@talismn/balances 0.0.0-pr677-20230413212044 → 0.0.0-pr677-20230414055701
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
# @talismn/balances
|
2
2
|
|
3
|
-
## 0.0.0-pr677-
|
3
|
+
## 0.0.0-pr677-20230414055701
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
7
7
|
- fb8ee962: feat: proxy dapp websocket requests to talisman wallet backend when available
|
8
|
-
-
|
8
|
+
- 7440f96a: feat: crowdloan and nom pool balances
|
9
9
|
- Updated dependencies [fb8ee962]
|
10
10
|
- Updated dependencies [c898da98]
|
11
|
-
- Updated dependencies [
|
12
|
-
- @talismn/chain-connector@0.0.0-pr677-
|
13
|
-
- @talismn/chain-connector-evm@0.0.0-pr677-
|
14
|
-
- @talismn/util@0.0.0-pr677-
|
15
|
-
- @talismn/chaindata-provider@0.0.0-pr677-
|
16
|
-
- @talismn/token-rates@0.0.0-pr677-
|
11
|
+
- Updated dependencies [7440f96a]
|
12
|
+
- @talismn/chain-connector@0.0.0-pr677-20230414055701
|
13
|
+
- @talismn/chain-connector-evm@0.0.0-pr677-20230414055701
|
14
|
+
- @talismn/util@0.0.0-pr677-20230414055701
|
15
|
+
- @talismn/chaindata-provider@0.0.0-pr677-20230414055701
|
16
|
+
- @talismn/token-rates@0.0.0-pr677-20230414055701
|
17
17
|
|
18
18
|
## 0.4.0
|
19
19
|
|
@@ -176,7 +176,7 @@ export declare class FiatSumBalancesFormatter {
|
|
176
176
|
get reserved(): number;
|
177
177
|
/** The frozen balance of these tokens. Is included in the free amount. */
|
178
178
|
get locked(): number;
|
179
|
-
/** @deprecated
|
179
|
+
/** @deprecated Use balances.locked */
|
180
180
|
get frozen(): number;
|
181
181
|
/** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
|
182
182
|
get transferable(): number;
|
@@ -69,7 +69,7 @@ const db = new TalismanBalancesDatabase();
|
|
69
69
|
|
70
70
|
var packageJson = {
|
71
71
|
name: "@talismn/balances",
|
72
|
-
version: "0.0.0-pr677-
|
72
|
+
version: "0.0.0-pr677-20230414055701",
|
73
73
|
author: "Talisman",
|
74
74
|
homepage: "https://talisman.xyz",
|
75
75
|
license: "UNLICENSED",
|
@@ -156,7 +156,7 @@ const createTypeRegistryCache = () => {
|
|
156
156
|
} catch (cause) {
|
157
157
|
log.warn(new Error(`Failed to set metadata for chain ${chainId}`, {
|
158
158
|
cause
|
159
|
-
}));
|
159
|
+
}), cause);
|
160
160
|
}
|
161
161
|
}
|
162
162
|
typeRegistryCache.set(chainId, typeRegistry);
|
@@ -316,15 +316,12 @@ class RpcStateQueryHelper {
|
|
316
316
|
const params = [queries.map(({
|
317
317
|
stateKey
|
318
318
|
}) => stateKey)];
|
319
|
-
const
|
319
|
+
const unsub = this.#chainConnector.subscribe(chainId, subscribeMethod, responseMethod, params, (error, result) => {
|
320
320
|
error ? callback(error) : callback(null, this.#distributeChangesToQueryDecoders.call(this, chainId, result));
|
321
321
|
}, timeout);
|
322
|
-
return () => unsubscribe(unsubscribeMethod);
|
323
|
-
})
|
324
|
-
|
325
|
-
return () => {};
|
326
|
-
}));
|
327
|
-
return () => subscriptions.forEach(subscription => subscription.then(unsubscribe => unsubscribe()));
|
322
|
+
return () => unsub.then(unsubscribe => unsubscribe(unsubscribeMethod));
|
323
|
+
});
|
324
|
+
return () => subscriptions.forEach(unsubscribe => unsubscribe());
|
328
325
|
}
|
329
326
|
async fetch(method = "state_queryStorageAt") {
|
330
327
|
const queriesByChain = groupBy__default["default"](this.#queries, "chainId");
|
@@ -360,7 +357,7 @@ class RpcStateQueryHelper {
|
|
360
357
|
}) => stateKey)}`);
|
361
358
|
return [];
|
362
359
|
}
|
363
|
-
return query.decodeResult(change);
|
360
|
+
return [query.decodeResult(change)];
|
364
361
|
});
|
365
362
|
}
|
366
363
|
}
|
@@ -369,7 +366,7 @@ const BalanceStatusLive = subscriptionId => `live-${subscriptionId}`;
|
|
369
366
|
function excludeFromTransferableAmount(locks) {
|
370
367
|
if (typeof locks === "string") return BigInt(locks);
|
371
368
|
if (!Array.isArray(locks)) locks = [locks];
|
372
|
-
return locks.filter(lock => lock.includeInTransferable !== true).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock),
|
369
|
+
return locks.filter(lock => lock.includeInTransferable !== true).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock), 0n);
|
373
370
|
}
|
374
371
|
function excludeFromFeePayableLocks(locks) {
|
375
372
|
if (typeof locks === "string") return [];
|
@@ -380,9 +377,9 @@ function excludeFromFeePayableLocks(locks) {
|
|
380
377
|
/** A labelled extra amount of a balance */
|
381
378
|
|
382
379
|
function includeInTotalExtraAmount(extra) {
|
383
|
-
if (!extra) return
|
380
|
+
if (!extra) return 0n;
|
384
381
|
if (!Array.isArray(extra)) extra = [extra];
|
385
|
-
return extra.filter(extra => extra.includeInTotal).map(extra => BigInt(extra.amount)).reduce((a, b) => a + b,
|
382
|
+
return extra.filter(extra => extra.includeInTotal).map(extra => BigInt(extra.amount)).reduce((a, b) => a + b, 0n);
|
386
383
|
}
|
387
384
|
|
388
385
|
/** Used by plugins to help define their custom `BalanceType` */
|
@@ -671,11 +668,11 @@ class Balance {
|
|
671
668
|
}
|
672
669
|
/** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
|
673
670
|
get free() {
|
674
|
-
return this.#format(typeof this.#storage.free === "string" ? BigInt(this.#storage.free) : Array.isArray(this.#storage.free) ? this.#storage.free.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b,
|
671
|
+
return this.#format(typeof this.#storage.free === "string" ? BigInt(this.#storage.free) : Array.isArray(this.#storage.free) ? this.#storage.free.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b, 0n) : BigInt(this.#storage.free?.amount || "0"));
|
675
672
|
}
|
676
673
|
/** The reserved balance of this token. Is included in the total. */
|
677
674
|
get reserved() {
|
678
|
-
return this.#format(typeof this.#storage.reserves === "string" ? BigInt(this.#storage.reserves) : Array.isArray(this.#storage.reserves) ? this.#storage.reserves.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b,
|
675
|
+
return this.#format(typeof this.#storage.reserves === "string" ? BigInt(this.#storage.reserves) : Array.isArray(this.#storage.reserves) ? this.#storage.reserves.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b, 0n) : BigInt(this.#storage.reserves?.amount || "0"));
|
679
676
|
}
|
680
677
|
get reserves() {
|
681
678
|
return (Array.isArray(this.#storage.reserves) ? this.#storage.reserves : [this.#storage.reserves]).flatMap(reserve => {
|
@@ -692,7 +689,7 @@ class Balance {
|
|
692
689
|
}
|
693
690
|
/** The frozen balance of this token. Is included in the free amount. */
|
694
691
|
get locked() {
|
695
|
-
return this.#format(typeof this.#storage.locks === "string" ? BigInt(this.#storage.locks) : Array.isArray(this.#storage.locks) ? this.#storage.locks.map(lock => BigInt(lock.amount)).reduce((a, b) => util.BigMath.max(a, b),
|
692
|
+
return this.#format(typeof this.#storage.locks === "string" ? BigInt(this.#storage.locks) : Array.isArray(this.#storage.locks) ? this.#storage.locks.map(lock => BigInt(lock.amount)).reduce((a, b) => util.BigMath.max(a, b), 0n) : BigInt(this.#storage.locks?.amount || "0"));
|
696
693
|
}
|
697
694
|
get locks() {
|
698
695
|
return (Array.isArray(this.#storage.locks) ? this.#storage.locks : [this.#storage.locks]).flatMap(lock => {
|
@@ -720,7 +717,7 @@ class Balance {
|
|
720
717
|
const excludeAmount = excludeFromTransferableAmount(this.#storage.locks);
|
721
718
|
|
722
719
|
// subtract the lock from the free amount (but don't go below 0)
|
723
|
-
return this.#format(util.BigMath.max(this.free.planck - excludeAmount,
|
720
|
+
return this.#format(util.BigMath.max(this.free.planck - excludeAmount, 0n));
|
724
721
|
}
|
725
722
|
/** The feePayable balance of this token. Is generally the free amount - the feeFrozen amount. */
|
726
723
|
get feePayable() {
|
@@ -728,10 +725,10 @@ class Balance {
|
|
728
725
|
if (!this.#storage.locks) return this.free;
|
729
726
|
|
730
727
|
// find the largest lock which can't be used to pay tx fees
|
731
|
-
const excludeAmount = excludeFromFeePayableLocks(this.#storage.locks).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock),
|
728
|
+
const excludeAmount = excludeFromFeePayableLocks(this.#storage.locks).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock), 0n);
|
732
729
|
|
733
730
|
// subtract the lock from the free amount (but don't go below 0)
|
734
|
-
return this.#format(util.BigMath.max(this.free.planck - excludeAmount,
|
731
|
+
return this.#format(util.BigMath.max(this.free.planck - excludeAmount, 0n));
|
735
732
|
}
|
736
733
|
}
|
737
734
|
class BalanceFormatter {
|
@@ -797,7 +794,7 @@ class FiatSumBalancesFormatter {
|
|
797
794
|
get locked() {
|
798
795
|
return this.#sum("locked");
|
799
796
|
}
|
800
|
-
/** @deprecated
|
797
|
+
/** @deprecated Use balances.locked */
|
801
798
|
get frozen() {
|
802
799
|
return this.locked;
|
803
800
|
}
|
@@ -69,7 +69,7 @@ const db = new TalismanBalancesDatabase();
|
|
69
69
|
|
70
70
|
var packageJson = {
|
71
71
|
name: "@talismn/balances",
|
72
|
-
version: "0.0.0-pr677-
|
72
|
+
version: "0.0.0-pr677-20230414055701",
|
73
73
|
author: "Talisman",
|
74
74
|
homepage: "https://talisman.xyz",
|
75
75
|
license: "UNLICENSED",
|
@@ -156,7 +156,7 @@ const createTypeRegistryCache = () => {
|
|
156
156
|
} catch (cause) {
|
157
157
|
log.warn(new Error(`Failed to set metadata for chain ${chainId}`, {
|
158
158
|
cause
|
159
|
-
}));
|
159
|
+
}), cause);
|
160
160
|
}
|
161
161
|
}
|
162
162
|
typeRegistryCache.set(chainId, typeRegistry);
|
@@ -316,15 +316,12 @@ class RpcStateQueryHelper {
|
|
316
316
|
const params = [queries.map(({
|
317
317
|
stateKey
|
318
318
|
}) => stateKey)];
|
319
|
-
const
|
319
|
+
const unsub = this.#chainConnector.subscribe(chainId, subscribeMethod, responseMethod, params, (error, result) => {
|
320
320
|
error ? callback(error) : callback(null, this.#distributeChangesToQueryDecoders.call(this, chainId, result));
|
321
321
|
}, timeout);
|
322
|
-
return () => unsubscribe(unsubscribeMethod);
|
323
|
-
})
|
324
|
-
|
325
|
-
return () => {};
|
326
|
-
}));
|
327
|
-
return () => subscriptions.forEach(subscription => subscription.then(unsubscribe => unsubscribe()));
|
322
|
+
return () => unsub.then(unsubscribe => unsubscribe(unsubscribeMethod));
|
323
|
+
});
|
324
|
+
return () => subscriptions.forEach(unsubscribe => unsubscribe());
|
328
325
|
}
|
329
326
|
async fetch(method = "state_queryStorageAt") {
|
330
327
|
const queriesByChain = groupBy__default["default"](this.#queries, "chainId");
|
@@ -360,7 +357,7 @@ class RpcStateQueryHelper {
|
|
360
357
|
}) => stateKey)}`);
|
361
358
|
return [];
|
362
359
|
}
|
363
|
-
return query.decodeResult(change);
|
360
|
+
return [query.decodeResult(change)];
|
364
361
|
});
|
365
362
|
}
|
366
363
|
}
|
@@ -369,7 +366,7 @@ const BalanceStatusLive = subscriptionId => `live-${subscriptionId}`;
|
|
369
366
|
function excludeFromTransferableAmount(locks) {
|
370
367
|
if (typeof locks === "string") return BigInt(locks);
|
371
368
|
if (!Array.isArray(locks)) locks = [locks];
|
372
|
-
return locks.filter(lock => lock.includeInTransferable !== true).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock),
|
369
|
+
return locks.filter(lock => lock.includeInTransferable !== true).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock), 0n);
|
373
370
|
}
|
374
371
|
function excludeFromFeePayableLocks(locks) {
|
375
372
|
if (typeof locks === "string") return [];
|
@@ -380,9 +377,9 @@ function excludeFromFeePayableLocks(locks) {
|
|
380
377
|
/** A labelled extra amount of a balance */
|
381
378
|
|
382
379
|
function includeInTotalExtraAmount(extra) {
|
383
|
-
if (!extra) return
|
380
|
+
if (!extra) return 0n;
|
384
381
|
if (!Array.isArray(extra)) extra = [extra];
|
385
|
-
return extra.filter(extra => extra.includeInTotal).map(extra => BigInt(extra.amount)).reduce((a, b) => a + b,
|
382
|
+
return extra.filter(extra => extra.includeInTotal).map(extra => BigInt(extra.amount)).reduce((a, b) => a + b, 0n);
|
386
383
|
}
|
387
384
|
|
388
385
|
/** Used by plugins to help define their custom `BalanceType` */
|
@@ -671,11 +668,11 @@ class Balance {
|
|
671
668
|
}
|
672
669
|
/** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
|
673
670
|
get free() {
|
674
|
-
return this.#format(typeof this.#storage.free === "string" ? BigInt(this.#storage.free) : Array.isArray(this.#storage.free) ? this.#storage.free.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b,
|
671
|
+
return this.#format(typeof this.#storage.free === "string" ? BigInt(this.#storage.free) : Array.isArray(this.#storage.free) ? this.#storage.free.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b, 0n) : BigInt(this.#storage.free?.amount || "0"));
|
675
672
|
}
|
676
673
|
/** The reserved balance of this token. Is included in the total. */
|
677
674
|
get reserved() {
|
678
|
-
return this.#format(typeof this.#storage.reserves === "string" ? BigInt(this.#storage.reserves) : Array.isArray(this.#storage.reserves) ? this.#storage.reserves.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b,
|
675
|
+
return this.#format(typeof this.#storage.reserves === "string" ? BigInt(this.#storage.reserves) : Array.isArray(this.#storage.reserves) ? this.#storage.reserves.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b, 0n) : BigInt(this.#storage.reserves?.amount || "0"));
|
679
676
|
}
|
680
677
|
get reserves() {
|
681
678
|
return (Array.isArray(this.#storage.reserves) ? this.#storage.reserves : [this.#storage.reserves]).flatMap(reserve => {
|
@@ -692,7 +689,7 @@ class Balance {
|
|
692
689
|
}
|
693
690
|
/** The frozen balance of this token. Is included in the free amount. */
|
694
691
|
get locked() {
|
695
|
-
return this.#format(typeof this.#storage.locks === "string" ? BigInt(this.#storage.locks) : Array.isArray(this.#storage.locks) ? this.#storage.locks.map(lock => BigInt(lock.amount)).reduce((a, b) => util.BigMath.max(a, b),
|
692
|
+
return this.#format(typeof this.#storage.locks === "string" ? BigInt(this.#storage.locks) : Array.isArray(this.#storage.locks) ? this.#storage.locks.map(lock => BigInt(lock.amount)).reduce((a, b) => util.BigMath.max(a, b), 0n) : BigInt(this.#storage.locks?.amount || "0"));
|
696
693
|
}
|
697
694
|
get locks() {
|
698
695
|
return (Array.isArray(this.#storage.locks) ? this.#storage.locks : [this.#storage.locks]).flatMap(lock => {
|
@@ -720,7 +717,7 @@ class Balance {
|
|
720
717
|
const excludeAmount = excludeFromTransferableAmount(this.#storage.locks);
|
721
718
|
|
722
719
|
// subtract the lock from the free amount (but don't go below 0)
|
723
|
-
return this.#format(util.BigMath.max(this.free.planck - excludeAmount,
|
720
|
+
return this.#format(util.BigMath.max(this.free.planck - excludeAmount, 0n));
|
724
721
|
}
|
725
722
|
/** The feePayable balance of this token. Is generally the free amount - the feeFrozen amount. */
|
726
723
|
get feePayable() {
|
@@ -728,10 +725,10 @@ class Balance {
|
|
728
725
|
if (!this.#storage.locks) return this.free;
|
729
726
|
|
730
727
|
// find the largest lock which can't be used to pay tx fees
|
731
|
-
const excludeAmount = excludeFromFeePayableLocks(this.#storage.locks).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock),
|
728
|
+
const excludeAmount = excludeFromFeePayableLocks(this.#storage.locks).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock), 0n);
|
732
729
|
|
733
730
|
// subtract the lock from the free amount (but don't go below 0)
|
734
|
-
return this.#format(util.BigMath.max(this.free.planck - excludeAmount,
|
731
|
+
return this.#format(util.BigMath.max(this.free.planck - excludeAmount, 0n));
|
735
732
|
}
|
736
733
|
}
|
737
734
|
class BalanceFormatter {
|
@@ -797,7 +794,7 @@ class FiatSumBalancesFormatter {
|
|
797
794
|
get locked() {
|
798
795
|
return this.#sum("locked");
|
799
796
|
}
|
800
|
-
/** @deprecated
|
797
|
+
/** @deprecated Use balances.locked */
|
801
798
|
get frozen() {
|
802
799
|
return this.locked;
|
803
800
|
}
|
@@ -60,7 +60,7 @@ const db = new TalismanBalancesDatabase();
|
|
60
60
|
|
61
61
|
var packageJson = {
|
62
62
|
name: "@talismn/balances",
|
63
|
-
version: "0.0.0-pr677-
|
63
|
+
version: "0.0.0-pr677-20230414055701",
|
64
64
|
author: "Talisman",
|
65
65
|
homepage: "https://talisman.xyz",
|
66
66
|
license: "UNLICENSED",
|
@@ -147,7 +147,7 @@ const createTypeRegistryCache = () => {
|
|
147
147
|
} catch (cause) {
|
148
148
|
log.warn(new Error(`Failed to set metadata for chain ${chainId}`, {
|
149
149
|
cause
|
150
|
-
}));
|
150
|
+
}), cause);
|
151
151
|
}
|
152
152
|
}
|
153
153
|
typeRegistryCache.set(chainId, typeRegistry);
|
@@ -307,15 +307,12 @@ class RpcStateQueryHelper {
|
|
307
307
|
const params = [queries.map(({
|
308
308
|
stateKey
|
309
309
|
}) => stateKey)];
|
310
|
-
const
|
310
|
+
const unsub = this.#chainConnector.subscribe(chainId, subscribeMethod, responseMethod, params, (error, result) => {
|
311
311
|
error ? callback(error) : callback(null, this.#distributeChangesToQueryDecoders.call(this, chainId, result));
|
312
312
|
}, timeout);
|
313
|
-
return () => unsubscribe(unsubscribeMethod);
|
314
|
-
})
|
315
|
-
|
316
|
-
return () => {};
|
317
|
-
}));
|
318
|
-
return () => subscriptions.forEach(subscription => subscription.then(unsubscribe => unsubscribe()));
|
313
|
+
return () => unsub.then(unsubscribe => unsubscribe(unsubscribeMethod));
|
314
|
+
});
|
315
|
+
return () => subscriptions.forEach(unsubscribe => unsubscribe());
|
319
316
|
}
|
320
317
|
async fetch(method = "state_queryStorageAt") {
|
321
318
|
const queriesByChain = groupBy(this.#queries, "chainId");
|
@@ -351,7 +348,7 @@ class RpcStateQueryHelper {
|
|
351
348
|
}) => stateKey)}`);
|
352
349
|
return [];
|
353
350
|
}
|
354
|
-
return query.decodeResult(change);
|
351
|
+
return [query.decodeResult(change)];
|
355
352
|
});
|
356
353
|
}
|
357
354
|
}
|
@@ -360,7 +357,7 @@ const BalanceStatusLive = subscriptionId => `live-${subscriptionId}`;
|
|
360
357
|
function excludeFromTransferableAmount(locks) {
|
361
358
|
if (typeof locks === "string") return BigInt(locks);
|
362
359
|
if (!Array.isArray(locks)) locks = [locks];
|
363
|
-
return locks.filter(lock => lock.includeInTransferable !== true).map(lock => BigInt(lock.amount)).reduce((max, lock) => BigMath.max(max, lock),
|
360
|
+
return locks.filter(lock => lock.includeInTransferable !== true).map(lock => BigInt(lock.amount)).reduce((max, lock) => BigMath.max(max, lock), 0n);
|
364
361
|
}
|
365
362
|
function excludeFromFeePayableLocks(locks) {
|
366
363
|
if (typeof locks === "string") return [];
|
@@ -371,9 +368,9 @@ function excludeFromFeePayableLocks(locks) {
|
|
371
368
|
/** A labelled extra amount of a balance */
|
372
369
|
|
373
370
|
function includeInTotalExtraAmount(extra) {
|
374
|
-
if (!extra) return
|
371
|
+
if (!extra) return 0n;
|
375
372
|
if (!Array.isArray(extra)) extra = [extra];
|
376
|
-
return extra.filter(extra => extra.includeInTotal).map(extra => BigInt(extra.amount)).reduce((a, b) => a + b,
|
373
|
+
return extra.filter(extra => extra.includeInTotal).map(extra => BigInt(extra.amount)).reduce((a, b) => a + b, 0n);
|
377
374
|
}
|
378
375
|
|
379
376
|
/** Used by plugins to help define their custom `BalanceType` */
|
@@ -662,11 +659,11 @@ class Balance {
|
|
662
659
|
}
|
663
660
|
/** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
|
664
661
|
get free() {
|
665
|
-
return this.#format(typeof this.#storage.free === "string" ? BigInt(this.#storage.free) : Array.isArray(this.#storage.free) ? this.#storage.free.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b,
|
662
|
+
return this.#format(typeof this.#storage.free === "string" ? BigInt(this.#storage.free) : Array.isArray(this.#storage.free) ? this.#storage.free.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b, 0n) : BigInt(this.#storage.free?.amount || "0"));
|
666
663
|
}
|
667
664
|
/** The reserved balance of this token. Is included in the total. */
|
668
665
|
get reserved() {
|
669
|
-
return this.#format(typeof this.#storage.reserves === "string" ? BigInt(this.#storage.reserves) : Array.isArray(this.#storage.reserves) ? this.#storage.reserves.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b,
|
666
|
+
return this.#format(typeof this.#storage.reserves === "string" ? BigInt(this.#storage.reserves) : Array.isArray(this.#storage.reserves) ? this.#storage.reserves.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b, 0n) : BigInt(this.#storage.reserves?.amount || "0"));
|
670
667
|
}
|
671
668
|
get reserves() {
|
672
669
|
return (Array.isArray(this.#storage.reserves) ? this.#storage.reserves : [this.#storage.reserves]).flatMap(reserve => {
|
@@ -683,7 +680,7 @@ class Balance {
|
|
683
680
|
}
|
684
681
|
/** The frozen balance of this token. Is included in the free amount. */
|
685
682
|
get locked() {
|
686
|
-
return this.#format(typeof this.#storage.locks === "string" ? BigInt(this.#storage.locks) : Array.isArray(this.#storage.locks) ? this.#storage.locks.map(lock => BigInt(lock.amount)).reduce((a, b) => BigMath.max(a, b),
|
683
|
+
return this.#format(typeof this.#storage.locks === "string" ? BigInt(this.#storage.locks) : Array.isArray(this.#storage.locks) ? this.#storage.locks.map(lock => BigInt(lock.amount)).reduce((a, b) => BigMath.max(a, b), 0n) : BigInt(this.#storage.locks?.amount || "0"));
|
687
684
|
}
|
688
685
|
get locks() {
|
689
686
|
return (Array.isArray(this.#storage.locks) ? this.#storage.locks : [this.#storage.locks]).flatMap(lock => {
|
@@ -711,7 +708,7 @@ class Balance {
|
|
711
708
|
const excludeAmount = excludeFromTransferableAmount(this.#storage.locks);
|
712
709
|
|
713
710
|
// subtract the lock from the free amount (but don't go below 0)
|
714
|
-
return this.#format(BigMath.max(this.free.planck - excludeAmount,
|
711
|
+
return this.#format(BigMath.max(this.free.planck - excludeAmount, 0n));
|
715
712
|
}
|
716
713
|
/** The feePayable balance of this token. Is generally the free amount - the feeFrozen amount. */
|
717
714
|
get feePayable() {
|
@@ -719,10 +716,10 @@ class Balance {
|
|
719
716
|
if (!this.#storage.locks) return this.free;
|
720
717
|
|
721
718
|
// find the largest lock which can't be used to pay tx fees
|
722
|
-
const excludeAmount = excludeFromFeePayableLocks(this.#storage.locks).map(lock => BigInt(lock.amount)).reduce((max, lock) => BigMath.max(max, lock),
|
719
|
+
const excludeAmount = excludeFromFeePayableLocks(this.#storage.locks).map(lock => BigInt(lock.amount)).reduce((max, lock) => BigMath.max(max, lock), 0n);
|
723
720
|
|
724
721
|
// subtract the lock from the free amount (but don't go below 0)
|
725
|
-
return this.#format(BigMath.max(this.free.planck - excludeAmount,
|
722
|
+
return this.#format(BigMath.max(this.free.planck - excludeAmount, 0n));
|
726
723
|
}
|
727
724
|
}
|
728
725
|
class BalanceFormatter {
|
@@ -788,7 +785,7 @@ class FiatSumBalancesFormatter {
|
|
788
785
|
get locked() {
|
789
786
|
return this.#sum("locked");
|
790
787
|
}
|
791
|
-
/** @deprecated
|
788
|
+
/** @deprecated Use balances.locked */
|
792
789
|
get frozen() {
|
793
790
|
return this.locked;
|
794
791
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/balances",
|
3
|
-
"version": "0.0.0-pr677-
|
3
|
+
"version": "0.0.0-pr677-20230414055701",
|
4
4
|
"author": "Talisman",
|
5
5
|
"homepage": "https://talisman.xyz",
|
6
6
|
"license": "UNLICENSED",
|
@@ -27,11 +27,11 @@
|
|
27
27
|
"clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
|
28
28
|
},
|
29
29
|
"dependencies": {
|
30
|
-
"@talismn/chain-connector": "^0.0.0-pr677-
|
31
|
-
"@talismn/chain-connector-evm": "^0.0.0-pr677-
|
32
|
-
"@talismn/chaindata-provider": "^0.0.0-pr677-
|
33
|
-
"@talismn/token-rates": "^0.0.0-pr677-
|
34
|
-
"@talismn/util": "^0.0.0-pr677-
|
30
|
+
"@talismn/chain-connector": "^0.0.0-pr677-20230414055701",
|
31
|
+
"@talismn/chain-connector-evm": "^0.0.0-pr677-20230414055701",
|
32
|
+
"@talismn/chaindata-provider": "^0.0.0-pr677-20230414055701",
|
33
|
+
"@talismn/token-rates": "^0.0.0-pr677-20230414055701",
|
34
|
+
"@talismn/util": "^0.0.0-pr677-20230414055701",
|
35
35
|
"anylogger": "^1.0.11",
|
36
36
|
"dexie": "^3.2.3",
|
37
37
|
"lodash": "4.17.21"
|