Skip to content

Commit

Permalink
Add reserved balance to transferrable balance
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Aug 26, 2024
1 parent d225201 commit f41c9da
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions packages/builder/src/balance/BalanceBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,7 @@ function system() {
args: [address],
transform: async (
response: FrameSystemAccountInfo,
): Promise<bigint> => {
const balance = response.data as PalletBalancesAccountData &
PalletBalancesAccountDataOld;
const frozen = balance.miscFrozen ?? balance.frozen;

return BigInt(balance.free.sub(frozen).toString());
},
): Promise<bigint> => calculateSystemAccountBalance(response),
}),
}),
accountEquilibrium: (): BalanceConfigBuilder => ({
Expand Down Expand Up @@ -139,13 +133,7 @@ function system() {
args: [substrateAddress],
transform: async (
response: FrameSystemAccountInfo,
): Promise<bigint> => {
const balance = response.data as PalletBalancesAccountData &
PalletBalancesAccountDataOld;
const frozen = balance.miscFrozen ?? balance.frozen;

return BigInt(balance.free.sub(frozen).toString());
},
): Promise<bigint> => calculateSystemAccountBalance(response),
});
},
}),
Expand All @@ -169,3 +157,14 @@ function tokens() {
}),
};
}

export async function calculateSystemAccountBalance(
response: FrameSystemAccountInfo,
): Promise<bigint> {
const balance = response.data as PalletBalancesAccountData &
PalletBalancesAccountDataOld;

const frozen = balance.miscFrozen ?? balance.frozen;

return BigInt(balance.free.sub(frozen).add(balance.reserved).toString());
}

0 comments on commit f41c9da

Please sign in to comment.