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

Top balances endpoint does not consider locked amounts #2019

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading