From f41c9daee68bef9901a16df2b6a0d454c1bb1506 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Tue, 27 Aug 2024 01:42:03 +0200 Subject: [PATCH] Add reserved balance to transferrable balance --- .../builder/src/balance/BalanceBuilder.ts | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/builder/src/balance/BalanceBuilder.ts b/packages/builder/src/balance/BalanceBuilder.ts index 6fd70681..165261e7 100644 --- a/packages/builder/src/balance/BalanceBuilder.ts +++ b/packages/builder/src/balance/BalanceBuilder.ts @@ -82,13 +82,7 @@ function system() { args: [address], transform: async ( response: FrameSystemAccountInfo, - ): Promise => { - const balance = response.data as PalletBalancesAccountData & - PalletBalancesAccountDataOld; - const frozen = balance.miscFrozen ?? balance.frozen; - - return BigInt(balance.free.sub(frozen).toString()); - }, + ): Promise => calculateSystemAccountBalance(response), }), }), accountEquilibrium: (): BalanceConfigBuilder => ({ @@ -139,13 +133,7 @@ function system() { args: [substrateAddress], transform: async ( response: FrameSystemAccountInfo, - ): Promise => { - const balance = response.data as PalletBalancesAccountData & - PalletBalancesAccountDataOld; - const frozen = balance.miscFrozen ?? balance.frozen; - - return BigInt(balance.free.sub(frozen).toString()); - }, + ): Promise => calculateSystemAccountBalance(response), }); }, }), @@ -169,3 +157,14 @@ function tokens() { }), }; } + +export async function calculateSystemAccountBalance( + response: FrameSystemAccountInfo, +): Promise { + const balance = response.data as PalletBalancesAccountData & + PalletBalancesAccountDataOld; + + const frozen = balance.miscFrozen ?? balance.frozen; + + return BigInt(balance.free.sub(frozen).add(balance.reserved).toString()); +}