Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transferable formula #5956

Merged
merged 2 commits into from
Aug 19, 2024
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
11 changes: 8 additions & 3 deletions packages/api-derive/src/balances/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ function calcShared (api: DeriveApi, bestNumber: BlockNumber, data: DeriveBalanc
let transferable = null;

if (data.frameSystemAccountInfo?.frozen) {
const frozenReserveDiff = data.frameSystemAccountInfo.frozen.sub(data.reservedBalance);

transferable = api.registry.createType('Balance', allLocked ? 0 : data?.freeBalance.sub(bnMax(frozenReserveDiff, api.consts.balances.existentialDeposit)));
const { frameSystemAccountInfo, freeBalance, reservedBalance } = data;

transferable = api.registry.createType(
'Balance',
allLocked
? 0
: freeBalance.sub(bnMax(new BN(0), frameSystemAccountInfo.frozen.sub(reservedBalance)))
);
}

return objectSpread({}, data, {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-derive/src/balances/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface DeriveBalancesAllAccountData extends DeriveBalancesAccountData
*/
lockedBreakdown: (PalletBalancesBalanceLock | BalanceLockTo212)[];
/**
* Calculated transferable balance. This uses the formula: free - max(frozen - reserve, ed)
* Calculated transferable balance. This uses the formula: free - max(0, frozen - reserve)
* 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.
*
Expand Down
Loading