Skip to content

Commit 3fb4422

Browse files
committed
fix(staking): Existential deposit not represented in "balance.total"
1 parent 18ec58e commit 3fb4422

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

packages/sdk-staking/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
## 0.3.3 2025-11-02
6+
7+
### Fixed
8+
9+
- Existential deposit not represented in "balance.total"
10+
511
## 0.3.2 2025-11-02
612

713
### Fixed

packages/sdk-staking/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polkadot-api/sdk-staking",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"sideEffects": false,
55
"author": "Carlo Sala (https://github.com/carlosala)",
66
"repository": {

packages/sdk-staking/src/accountStatus.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ const getBalance$ = (
3636
api.query.System.Account.watchValue(addr),
3737
api.constants.Balances.ExistentialDeposit(),
3838
]).pipe(
39-
map(([{ data }, existentialDeposit]) => {
39+
map(([{ data, providers, consumers }, existentialDeposit]) => {
40+
const accountExists = providers + consumers > 0
41+
const accountEd = accountExists ? existentialDeposit : 0n
4042
// https://wiki.polkadot.network/learn/learn-account-balances/
4143
// Total tokens in the account
42-
const total = data.reserved + data.free
44+
const total = data.reserved + data.free + accountEd
4345
// Portion of "free" balance that can't be transferred.
44-
const untouchable =
45-
total == 0n
46-
? 0n
47-
: maxBigInt(data.frozen - data.reserved, existentialDeposit)
46+
const untouchable = maxBigInt(data.frozen - data.reserved, accountEd)
4847
// Portion of "free" balance that can be transferred
4948
const spendable = data.free - untouchable
5049
// Portion of "total" balance that is somehow locked
@@ -53,7 +52,7 @@ const getBalance$ = (
5352
return {
5453
raw: {
5554
...data,
56-
existentialDeposit: total > 0n ? existentialDeposit : 0n,
55+
existentialDeposit: accountEd,
5756
},
5857
total,
5958
locked,

0 commit comments

Comments
 (0)