Revise api.derive.balances.all to include ED when necessary (#5957)

This commit is contained in:
Tarik Gul
2024-08-19 13:46:21 -04:00
committed by GitHub
parent f82c572704
commit 92dfe00851
2 changed files with 7 additions and 2 deletions
+5 -1
View File
@@ -58,12 +58,16 @@ function calcShared (api: DeriveApi, bestNumber: BlockNumber, data: DeriveBalanc
if (data.frameSystemAccountInfo?.frozen) {
const { frameSystemAccountInfo, freeBalance, reservedBalance } = data;
const noFrozenReserved = frameSystemAccountInfo.frozen.isZero() && reservedBalance.isZero();
const ED = api.consts.balances.existentialDeposit;
const maybeED = noFrozenReserved ? new BN(0) : ED;
const frozenReserveDif = frameSystemAccountInfo.frozen.sub(reservedBalance);
transferable = api.registry.createType(
'Balance',
allLocked
? 0
: freeBalance.sub(bnMax(new BN(0), frameSystemAccountInfo.frozen.sub(reservedBalance)))
: freeBalance.sub(bnMax(maybeED, frozenReserveDif))
);
}
+2 -1
View File
@@ -41,7 +41,8 @@ export interface DeriveBalancesAllAccountData extends DeriveBalancesAccountData
*/
lockedBreakdown: (PalletBalancesBalanceLock | BalanceLockTo212)[];
/**
* Calculated transferable balance. This uses the formula: free - max(0, frozen - reserve)
* Calculated transferable balance. This uses the formula: free - max(maybeEd, frozen - reserve)
* Where `maybeEd` means if there is no frozen and reserves it will be zero, else it will be the existential deposit.
* This is only correct when the return type of `api.query.system.account` is `FrameSystemAccountInfo`.
* Which is the most up to date calulcation for transferrable balances.
*