Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
🐛 Consider locked balances for top accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
sameersubudhi committed Jan 29, 2024
1 parent c17581b commit 82343ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
18 changes: 13 additions & 5 deletions services/blockchain-indexer/shared/indexer/accountBalanceIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@ const updateAccountBalances = async address => {
const accountBalancesTable = await getAccountBalancesTable();
const { data: balanceInfos } = await getTokenBalances({ address });

const updatedTokenBalances = balanceInfos.map(balanceInfo => ({
address,
tokenID: balanceInfo.tokenID,
balance: balanceInfo.availableBalance,
}));
const updatedTokenBalances = balanceInfos.map(balanceInfo => {
const { tokenID, availableBalance, lockedBalances } = balanceInfo;
const totalLockedBalance = lockedBalances.reduce(
(acc, entry) => BigInt(acc) + BigInt(entry.amount),
BigInt('0'),
);

return {
address,
tokenID,
balance: BigInt(availableBalance) + BigInt(totalLockedBalance),
};
});

// Update all token balances of the address
await accountBalancesTable.upsert(updatedTokenBalances);
Expand Down
12 changes: 10 additions & 2 deletions services/blockchain-indexer/shared/indexer/genesisBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ const indexTokenModuleAssets = async dbTrx => {

// eslint-disable-next-line no-restricted-syntax
for (const userInfo of userSubStoreInfos) {
const { address, availableBalance: balance, tokenID } = userInfo;
const { address, tokenID, availableBalance, lockedBalances } = userInfo;
const totalLockedBalance = lockedBalances.reduce(
(acc, entry) => BigInt(acc) + BigInt(entry.amount),
BigInt('0'),
);

// Add entry to index the genesis account balances
const accountBalanceEntry = { address, tokenID, balance };
const accountBalanceEntry = {
address,
tokenID,
balance: BigInt(availableBalance) + BigInt(totalLockedBalance),
};
genesisAccountBalances.push(accountBalanceEntry);

// eslint-disable-next-line no-restricted-syntax
Expand Down

0 comments on commit 82343ea

Please sign in to comment.