@talismn/balances 0.3.0 → 0.3.2
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 +15 -0
- package/dist/{BalanceModule.d.ts → declarations/src/BalanceModule.d.ts} +5 -5
- package/dist/{TalismanBalancesDatabase.d.ts → declarations/src/TalismanBalancesDatabase.d.ts} +0 -0
- package/dist/{helpers.d.ts → declarations/src/helpers.d.ts} +0 -0
- package/dist/{index.d.ts → declarations/src/index.d.ts} +0 -0
- package/dist/{log.d.ts → declarations/src/log.d.ts} +0 -0
- package/dist/{plugins.d.ts → declarations/src/plugins.d.ts} +0 -0
- package/dist/declarations/src/types/addresses.d.ts +4 -0
- package/dist/{types → declarations/src/types}/balances.d.ts +4 -4
- package/dist/{types → declarations/src/types}/balancetypes.d.ts +12 -12
- package/dist/{types → declarations/src/types}/index.d.ts +0 -0
- package/dist/{types → declarations/src/types}/subscriptions.d.ts +1 -1
- package/dist/talismn-balances.cjs.d.ts +1 -0
- package/dist/talismn-balances.cjs.dev.js +705 -0
- package/dist/talismn-balances.cjs.js +7 -0
- package/dist/talismn-balances.cjs.prod.js +705 -0
- package/dist/talismn-balances.esm.js +683 -0
- package/package.json +20 -15
- package/plugins/dist/talismn-balances-plugins.cjs.d.ts +1 -0
- package/plugins/dist/talismn-balances-plugins.cjs.dev.js +2 -0
- package/plugins/dist/talismn-balances-plugins.cjs.js +7 -0
- package/plugins/dist/talismn-balances-plugins.cjs.prod.js +2 -0
- package/plugins/dist/talismn-balances-plugins.esm.js +1 -0
- package/plugins/package.json +2 -3
- package/dist/BalanceModule.js +0 -29
- package/dist/TalismanBalancesDatabase.js +0 -23
- package/dist/helpers.js +0 -99
- package/dist/index.js +0 -31
- package/dist/log.js +0 -10
- package/dist/plugins.js +0 -2
- package/dist/types/addresses.d.ts +0 -4
- package/dist/types/addresses.js +0 -2
- package/dist/types/balances.js +0 -471
- package/dist/types/balancetypes.js +0 -34
- package/dist/types/index.js +0 -20
- package/dist/types/subscriptions.js +0 -2
package/dist/types/balances.js
DELETED
@@ -1,471 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
-
};
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
10
|
-
};
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.SumBalancesFormatter = exports.FiatSumBalancesFormatter = exports.BalanceFormatter = exports.Balance = exports.Balances = void 0;
|
13
|
-
const util_1 = require("@talismn/util");
|
14
|
-
const memoize_1 = __importDefault(require("lodash/memoize"));
|
15
|
-
const typescript_memoize_1 = require("typescript-memoize");
|
16
|
-
const helpers_1 = require("../helpers");
|
17
|
-
const log_1 = __importDefault(require("../log"));
|
18
|
-
const balancetypes_1 = require("./balancetypes");
|
19
|
-
/**
|
20
|
-
* A collection of balances.
|
21
|
-
*/
|
22
|
-
class Balances {
|
23
|
-
//
|
24
|
-
// Properties
|
25
|
-
//
|
26
|
-
#balances = {};
|
27
|
-
//
|
28
|
-
// Methods
|
29
|
-
//
|
30
|
-
constructor(balances, hydrate) {
|
31
|
-
// handle Balances (convert to Balance[])
|
32
|
-
if (balances instanceof Balances)
|
33
|
-
return new Balances([...balances], hydrate);
|
34
|
-
// handle Balance (convert to Balance[])
|
35
|
-
if (balances instanceof Balance)
|
36
|
-
return new Balances([balances], hydrate);
|
37
|
-
// handle BalanceJsonList (the only remaining non-array type of balances) (convert to BalanceJson[])
|
38
|
-
if (!Array.isArray(balances))
|
39
|
-
return new Balances(Object.values(balances), hydrate);
|
40
|
-
// handle no balances
|
41
|
-
if (balances.length === 0)
|
42
|
-
return this;
|
43
|
-
// handle BalanceJson[]
|
44
|
-
if (!(0, util_1.isArrayOf)(balances, Balance))
|
45
|
-
return new Balances(balances.map((storage) => new Balance(storage)), hydrate);
|
46
|
-
// handle Balance[]
|
47
|
-
this.#balances = Object.fromEntries(balances.map((balance) => [balance.id, balance]));
|
48
|
-
if (hydrate !== undefined)
|
49
|
-
this.hydrate(hydrate);
|
50
|
-
}
|
51
|
-
/**
|
52
|
-
* Calling toJSON on a collection of balances will return the underlying BalanceJsonList.
|
53
|
-
*/
|
54
|
-
toJSON = () => Object.fromEntries(Object.entries(this.#balances)
|
55
|
-
.map(([id, balance]) => {
|
56
|
-
try {
|
57
|
-
return [id, balance.toJSON()];
|
58
|
-
}
|
59
|
-
catch (error) {
|
60
|
-
log_1.default.error("Failed to convert balance to JSON", error, { id, balance });
|
61
|
-
return null;
|
62
|
-
}
|
63
|
-
})
|
64
|
-
.filter(Array.isArray));
|
65
|
-
/**
|
66
|
-
* Allows the collection to be iterated over.
|
67
|
-
*
|
68
|
-
* @example
|
69
|
-
* [...balances].forEach(balance => { // do something // })
|
70
|
-
*
|
71
|
-
* @example
|
72
|
-
* for (const balance of balances) {
|
73
|
-
* // do something
|
74
|
-
* }
|
75
|
-
*/
|
76
|
-
[Symbol.iterator] = () =>
|
77
|
-
// Create an array of the balances in this collection and return the result of its iterator.
|
78
|
-
Object.values(this.#balances)[Symbol.iterator]();
|
79
|
-
/**
|
80
|
-
* Hydrates all balances in this collection.
|
81
|
-
*
|
82
|
-
* @param sources - The sources to hydrate from.
|
83
|
-
*/
|
84
|
-
hydrate = (sources) => {
|
85
|
-
Object.values(this.#balances).map((balance) => balance.hydrate(sources));
|
86
|
-
};
|
87
|
-
/**
|
88
|
-
* Retrieve a balance from this collection by id.
|
89
|
-
*
|
90
|
-
* @param id - The id of the balance to fetch.
|
91
|
-
* @returns The balance if one exists, or none.
|
92
|
-
*/
|
93
|
-
get = (id) => this.#balances[id] || null;
|
94
|
-
/**
|
95
|
-
* Retrieve balances from this collection by search query.
|
96
|
-
*
|
97
|
-
* @param query - The search query.
|
98
|
-
* @returns All balances which match the query.
|
99
|
-
*/
|
100
|
-
find = (query) => {
|
101
|
-
// construct filter
|
102
|
-
const orQueries = (Array.isArray(query) ? query : [query]).map((query) => typeof query === "function" ? query : Object.entries(query));
|
103
|
-
// filter balances
|
104
|
-
const filter = (balance) => orQueries.some((query) => typeof query === "function"
|
105
|
-
? query(balance)
|
106
|
-
: query.every(([key, value]) => balance[key] === value));
|
107
|
-
// return filter matches
|
108
|
-
return new Balances([...this].filter(filter));
|
109
|
-
};
|
110
|
-
/**
|
111
|
-
* Add some balances to this collection.
|
112
|
-
* Added balances take priority over existing balances.
|
113
|
-
* The aggregation of the two collections is returned.
|
114
|
-
* The original collection is not mutated.
|
115
|
-
*
|
116
|
-
* @param balances - Either a balance or collection of balances to add.
|
117
|
-
* @returns The new collection of balances.
|
118
|
-
*/
|
119
|
-
add = (balances) => {
|
120
|
-
// handle single balance
|
121
|
-
if (balances instanceof Balance)
|
122
|
-
return this.add(new Balances(balances));
|
123
|
-
// merge balances
|
124
|
-
const mergedBalances = { ...this.#balances };
|
125
|
-
[...balances].forEach((balance) => (mergedBalances[balance.id] = balance));
|
126
|
-
// return new balances
|
127
|
-
return new Balances(Object.values(mergedBalances));
|
128
|
-
};
|
129
|
-
/**
|
130
|
-
* Remove balances from this collection by id.
|
131
|
-
* A new collection without these balances is returned.
|
132
|
-
* The original collection is not mutated.
|
133
|
-
*
|
134
|
-
* @param ids - The id(s) of the balances to remove.
|
135
|
-
* @returns The new collection of balances.
|
136
|
-
*/
|
137
|
-
remove = (ids) => {
|
138
|
-
// handle single id
|
139
|
-
if (!Array.isArray(ids))
|
140
|
-
return this.remove([ids]);
|
141
|
-
// merge balances
|
142
|
-
const removedBalances = { ...this.#balances };
|
143
|
-
ids.forEach((id) => delete removedBalances[id]);
|
144
|
-
// return new balances
|
145
|
-
return new Balances(Object.values(removedBalances));
|
146
|
-
};
|
147
|
-
// TODO: Add some more useful aggregator methods
|
148
|
-
/**
|
149
|
-
* Get an array of balances in this collection, sorted by chain sortIndex.
|
150
|
-
*
|
151
|
-
* @returns A sorted array of the balances in this collection.
|
152
|
-
*/
|
153
|
-
get sorted() {
|
154
|
-
return [...this].sort((a, b) => ((a.chain || a.evmNetwork)?.sortIndex || Number.MAX_SAFE_INTEGER) -
|
155
|
-
((b.chain || b.evmNetwork)?.sortIndex || Number.MAX_SAFE_INTEGER));
|
156
|
-
}
|
157
|
-
/**
|
158
|
-
* Get the number of balances in this collection.
|
159
|
-
*
|
160
|
-
* @returns The number of balances in this collection.
|
161
|
-
*/
|
162
|
-
get count() {
|
163
|
-
return [...this].length;
|
164
|
-
}
|
165
|
-
/**
|
166
|
-
* Get the summed value of balances in this collection.
|
167
|
-
* TODO: Sum up token amounts AND fiat amounts
|
168
|
-
*
|
169
|
-
* @example
|
170
|
-
* // Get the sum of all transferable balances in usd.
|
171
|
-
* balances.sum.fiat('usd').transferable
|
172
|
-
*/
|
173
|
-
get sum() {
|
174
|
-
return new SumBalancesFormatter(this);
|
175
|
-
}
|
176
|
-
}
|
177
|
-
__decorate([
|
178
|
-
(0, typescript_memoize_1.Memoize)()
|
179
|
-
], Balances.prototype, "sorted", null);
|
180
|
-
__decorate([
|
181
|
-
(0, typescript_memoize_1.Memoize)()
|
182
|
-
], Balances.prototype, "count", null);
|
183
|
-
__decorate([
|
184
|
-
(0, typescript_memoize_1.Memoize)()
|
185
|
-
], Balances.prototype, "sum", null);
|
186
|
-
exports.Balances = Balances;
|
187
|
-
/**
|
188
|
-
* An individual balance.
|
189
|
-
*/
|
190
|
-
class Balance {
|
191
|
-
//
|
192
|
-
// Properties
|
193
|
-
//
|
194
|
-
/** The underlying data for this balance */
|
195
|
-
#storage;
|
196
|
-
#db = null;
|
197
|
-
//
|
198
|
-
// Methods
|
199
|
-
//
|
200
|
-
constructor(storage, hydrate) {
|
201
|
-
this.#format = (0, memoize_1.default)(this.#format);
|
202
|
-
this.#storage = storage;
|
203
|
-
if (hydrate !== undefined)
|
204
|
-
this.hydrate(hydrate);
|
205
|
-
}
|
206
|
-
toJSON = () => this.#storage;
|
207
|
-
isSource = (source) => this.#storage.source === source;
|
208
|
-
// // TODO: Fix this method, the types don't work with our plugin architecture.
|
209
|
-
// // Specifically, the `BalanceJson` type is compiled down to `IBalance` in the following way:
|
210
|
-
// //
|
211
|
-
// // toJSON: () => BalanceJson // works
|
212
|
-
// // isSource: (source: BalanceSource) => boolean // works
|
213
|
-
// // asSource: <P extends string>(source: P) => NarrowBalanceType<IBalance, P> | null // Doesn't work! IBalance should just be BalanceJson!
|
214
|
-
// //
|
215
|
-
// // `IBalance` won't match the type of `BalanceSource` after `PluginBalanceTypes` has been extended by balance plugins.
|
216
|
-
// // As a result, typescript will think that the returned #storage is not a BalanceJson.
|
217
|
-
// asSource = <P extends BalanceSource>(source: P): NarrowBalanceType<BalanceJson, P> | null => {
|
218
|
-
// if (this.#storage.source === source) return this.#storage as NarrowBalanceType<BalanceJson, P>
|
219
|
-
// return null
|
220
|
-
// }
|
221
|
-
hydrate = (hydrate) => {
|
222
|
-
if (hydrate !== undefined)
|
223
|
-
this.#db = hydrate;
|
224
|
-
};
|
225
|
-
#format = (balance) => new BalanceFormatter(typeof balance === "bigint" ? balance.toString() : balance, this.decimals || undefined, this.#db?.tokenRates && this.#db.tokenRates[this.tokenId]);
|
226
|
-
//
|
227
|
-
// Accessors
|
228
|
-
//
|
229
|
-
get id() {
|
230
|
-
const { source, address, chainId, evmNetworkId, tokenId } = this.#storage;
|
231
|
-
const locationId = chainId !== undefined ? chainId : evmNetworkId;
|
232
|
-
return `${source}-${address}-${locationId}-${tokenId}`;
|
233
|
-
}
|
234
|
-
get source() {
|
235
|
-
return this.#storage.source;
|
236
|
-
}
|
237
|
-
get status() {
|
238
|
-
return this.#storage.status;
|
239
|
-
}
|
240
|
-
get address() {
|
241
|
-
return this.#storage.address;
|
242
|
-
}
|
243
|
-
get chainId() {
|
244
|
-
return this.#storage.chainId;
|
245
|
-
}
|
246
|
-
get chain() {
|
247
|
-
return (this.#db?.chains && this.chainId && this.#db?.chains[this.chainId]) || null;
|
248
|
-
}
|
249
|
-
get evmNetworkId() {
|
250
|
-
return this.#storage.evmNetworkId;
|
251
|
-
}
|
252
|
-
get evmNetwork() {
|
253
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
254
|
-
return (this.#db?.evmNetworks && this.#db?.evmNetworks[this.evmNetworkId]) || null;
|
255
|
-
}
|
256
|
-
get tokenId() {
|
257
|
-
return this.#storage.tokenId;
|
258
|
-
}
|
259
|
-
get token() {
|
260
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
261
|
-
return (this.#db?.tokens && this.#db?.tokens[this.tokenId]) || null;
|
262
|
-
}
|
263
|
-
get decimals() {
|
264
|
-
return this.token?.decimals || null;
|
265
|
-
}
|
266
|
-
get rates() {
|
267
|
-
return (this.#db?.tokenRates && this.#db.tokenRates[this.tokenId]) || null;
|
268
|
-
}
|
269
|
-
/**
|
270
|
-
* The total balance of this token.
|
271
|
-
* Includes the free and the reserved amount.
|
272
|
-
* The balance will be reaped if this goes below the existential deposit.
|
273
|
-
*/
|
274
|
-
get total() {
|
275
|
-
const extra = (0, balancetypes_1.includeInTotalExtraAmount)(this.#storage.extra);
|
276
|
-
return this.#format(this.free.planck + this.reserved.planck + extra);
|
277
|
-
}
|
278
|
-
/** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
|
279
|
-
get free() {
|
280
|
-
return this.#format(typeof this.#storage.free === "string"
|
281
|
-
? BigInt(this.#storage.free)
|
282
|
-
: Array.isArray(this.#storage.free)
|
283
|
-
? this.#storage.free
|
284
|
-
.map((reserve) => BigInt(reserve.amount))
|
285
|
-
.reduce((a, b) => a + b, BigInt("0"))
|
286
|
-
: BigInt(this.#storage.free?.amount || "0"));
|
287
|
-
}
|
288
|
-
/** The reserved balance of this token. Is included in the total. */
|
289
|
-
get reserved() {
|
290
|
-
return this.#format(typeof this.#storage.reserves === "string"
|
291
|
-
? BigInt(this.#storage.reserves)
|
292
|
-
: Array.isArray(this.#storage.reserves)
|
293
|
-
? this.#storage.reserves
|
294
|
-
.map((reserve) => BigInt(reserve.amount))
|
295
|
-
.reduce((a, b) => a + b, BigInt("0"))
|
296
|
-
: BigInt(this.#storage.reserves?.amount || "0"));
|
297
|
-
}
|
298
|
-
/** The frozen balance of this token. Is included in the free amount. */
|
299
|
-
get locked() {
|
300
|
-
return this.#format(typeof this.#storage.locks === "string"
|
301
|
-
? BigInt(this.#storage.locks)
|
302
|
-
: Array.isArray(this.#storage.locks)
|
303
|
-
? this.#storage.locks
|
304
|
-
.map((lock) => BigInt(lock.amount))
|
305
|
-
.reduce((a, b) => util_1.BigMath.max(a, b), BigInt("0"))
|
306
|
-
: BigInt(this.#storage.locks?.amount || "0"));
|
307
|
-
}
|
308
|
-
/** @depreacted - use balance.locked */
|
309
|
-
get frozen() {
|
310
|
-
return this.locked;
|
311
|
-
}
|
312
|
-
/** The transferable balance of this token. Is generally the free amount - the miscFrozen amount. */
|
313
|
-
get transferable() {
|
314
|
-
// if no locks exist, transferable is equal to the free amount
|
315
|
-
if (!this.#storage.locks)
|
316
|
-
return this.free;
|
317
|
-
// find the largest lock (but ignore any locks which are marked as `includeInTransferable`)
|
318
|
-
const excludeAmount = (0, balancetypes_1.excludeFromTransferableAmount)(this.#storage.locks);
|
319
|
-
// subtract the lock from the free amount (but don't go below 0)
|
320
|
-
return this.#format(util_1.BigMath.max(this.free.planck - excludeAmount, BigInt("0")));
|
321
|
-
}
|
322
|
-
/** The feePayable balance of this token. Is generally the free amount - the feeFrozen amount. */
|
323
|
-
get feePayable() {
|
324
|
-
// if no locks exist, feePayable is equal to the free amount
|
325
|
-
if (!this.#storage.locks)
|
326
|
-
return this.free;
|
327
|
-
// find the largest lock which can't be used to pay tx fees
|
328
|
-
const excludeAmount = (0, balancetypes_1.excludeFromFeePayableLocks)(this.#storage.locks)
|
329
|
-
.map((lock) => BigInt(lock.amount))
|
330
|
-
.reduce((max, lock) => util_1.BigMath.max(max, lock), BigInt("0"));
|
331
|
-
// subtract the lock from the free amount (but don't go below 0)
|
332
|
-
return this.#format(util_1.BigMath.max(this.free.planck - excludeAmount, BigInt("0")));
|
333
|
-
}
|
334
|
-
}
|
335
|
-
__decorate([
|
336
|
-
(0, typescript_memoize_1.Memoize)()
|
337
|
-
], Balance.prototype, "total", null);
|
338
|
-
__decorate([
|
339
|
-
(0, typescript_memoize_1.Memoize)()
|
340
|
-
], Balance.prototype, "free", null);
|
341
|
-
__decorate([
|
342
|
-
(0, typescript_memoize_1.Memoize)()
|
343
|
-
], Balance.prototype, "reserved", null);
|
344
|
-
__decorate([
|
345
|
-
(0, typescript_memoize_1.Memoize)()
|
346
|
-
], Balance.prototype, "locked", null);
|
347
|
-
__decorate([
|
348
|
-
(0, typescript_memoize_1.Memoize)()
|
349
|
-
], Balance.prototype, "frozen", null);
|
350
|
-
__decorate([
|
351
|
-
(0, typescript_memoize_1.Memoize)()
|
352
|
-
], Balance.prototype, "transferable", null);
|
353
|
-
__decorate([
|
354
|
-
(0, typescript_memoize_1.Memoize)()
|
355
|
-
], Balance.prototype, "feePayable", null);
|
356
|
-
exports.Balance = Balance;
|
357
|
-
class BalanceFormatter {
|
358
|
-
#planck;
|
359
|
-
#decimals;
|
360
|
-
#fiatRatios;
|
361
|
-
constructor(planck, decimals, fiatRatios) {
|
362
|
-
this.#planck = typeof planck === "bigint" ? planck.toString() : planck ?? "0";
|
363
|
-
this.#decimals = decimals || 0;
|
364
|
-
this.#fiatRatios = fiatRatios || null;
|
365
|
-
this.fiat = (0, memoize_1.default)(this.fiat);
|
366
|
-
}
|
367
|
-
toJSON = () => this.#planck;
|
368
|
-
get planck() {
|
369
|
-
return BigInt(this.#planck);
|
370
|
-
}
|
371
|
-
get tokens() {
|
372
|
-
return (0, util_1.planckToTokens)(this.#planck, this.#decimals);
|
373
|
-
}
|
374
|
-
fiat(currency) {
|
375
|
-
if (!this.#fiatRatios)
|
376
|
-
return null;
|
377
|
-
const ratio = this.#fiatRatios[currency];
|
378
|
-
if (!ratio)
|
379
|
-
return null;
|
380
|
-
return parseFloat(this.tokens) * ratio;
|
381
|
-
}
|
382
|
-
}
|
383
|
-
__decorate([
|
384
|
-
(0, typescript_memoize_1.Memoize)()
|
385
|
-
], BalanceFormatter.prototype, "tokens", null);
|
386
|
-
exports.BalanceFormatter = BalanceFormatter;
|
387
|
-
class FiatSumBalancesFormatter {
|
388
|
-
#balances;
|
389
|
-
#currency;
|
390
|
-
constructor(balances, currency) {
|
391
|
-
this.#balances = balances;
|
392
|
-
this.#currency = currency;
|
393
|
-
this.#sum = (0, memoize_1.default)(this.#sum);
|
394
|
-
}
|
395
|
-
#sum = (balanceField) => {
|
396
|
-
// a function to get a fiat amount from a balance
|
397
|
-
const fiat = (balance) => balance[balanceField].fiat(this.#currency) || 0;
|
398
|
-
// a function to add two amounts
|
399
|
-
const sum = (a, b) => a + b;
|
400
|
-
return [...this.#balances].filter(helpers_1.filterMirrorTokens).reduce((total, balance) => sum(
|
401
|
-
// add the total amount...
|
402
|
-
total,
|
403
|
-
// ...to the fiat amount of each balance
|
404
|
-
fiat(balance)),
|
405
|
-
// start with a total of 0
|
406
|
-
0);
|
407
|
-
};
|
408
|
-
/**
|
409
|
-
* The total balance of these tokens. Includes the free and the reserved amount.
|
410
|
-
*/
|
411
|
-
get total() {
|
412
|
-
return this.#sum("total");
|
413
|
-
}
|
414
|
-
/** The non-reserved balance of these tokens. Includes the frozen amount. Is included in the total. */
|
415
|
-
get free() {
|
416
|
-
return this.#sum("free");
|
417
|
-
}
|
418
|
-
/** The reserved balance of these tokens. Is included in the total. */
|
419
|
-
get reserved() {
|
420
|
-
return this.#sum("reserved");
|
421
|
-
}
|
422
|
-
/** The frozen balance of these tokens. Is included in the free amount. */
|
423
|
-
get locked() {
|
424
|
-
return this.#sum("locked");
|
425
|
-
}
|
426
|
-
/** @deprecated - use balances.locked */
|
427
|
-
get frozen() {
|
428
|
-
return this.locked;
|
429
|
-
}
|
430
|
-
/** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
|
431
|
-
get transferable() {
|
432
|
-
return this.#sum("transferable");
|
433
|
-
}
|
434
|
-
/** The feePayable balance of these tokens. Is generally the free amount - the feeFrozen amount. */
|
435
|
-
get feePayable() {
|
436
|
-
return this.#sum("feePayable");
|
437
|
-
}
|
438
|
-
}
|
439
|
-
__decorate([
|
440
|
-
(0, typescript_memoize_1.Memoize)()
|
441
|
-
], FiatSumBalancesFormatter.prototype, "total", null);
|
442
|
-
__decorate([
|
443
|
-
(0, typescript_memoize_1.Memoize)()
|
444
|
-
], FiatSumBalancesFormatter.prototype, "free", null);
|
445
|
-
__decorate([
|
446
|
-
(0, typescript_memoize_1.Memoize)()
|
447
|
-
], FiatSumBalancesFormatter.prototype, "reserved", null);
|
448
|
-
__decorate([
|
449
|
-
(0, typescript_memoize_1.Memoize)()
|
450
|
-
], FiatSumBalancesFormatter.prototype, "locked", null);
|
451
|
-
__decorate([
|
452
|
-
(0, typescript_memoize_1.Memoize)()
|
453
|
-
], FiatSumBalancesFormatter.prototype, "frozen", null);
|
454
|
-
__decorate([
|
455
|
-
(0, typescript_memoize_1.Memoize)()
|
456
|
-
], FiatSumBalancesFormatter.prototype, "transferable", null);
|
457
|
-
__decorate([
|
458
|
-
(0, typescript_memoize_1.Memoize)()
|
459
|
-
], FiatSumBalancesFormatter.prototype, "feePayable", null);
|
460
|
-
exports.FiatSumBalancesFormatter = FiatSumBalancesFormatter;
|
461
|
-
class SumBalancesFormatter {
|
462
|
-
#balances;
|
463
|
-
constructor(balances) {
|
464
|
-
this.#balances = balances;
|
465
|
-
this.fiat = (0, memoize_1.default)(this.fiat);
|
466
|
-
}
|
467
|
-
fiat(currency) {
|
468
|
-
return new FiatSumBalancesFormatter(this.#balances, currency);
|
469
|
-
}
|
470
|
-
}
|
471
|
-
exports.SumBalancesFormatter = SumBalancesFormatter;
|
@@ -1,34 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.includeInTotalExtraAmount = exports.excludeFromFeePayableLocks = exports.excludeFromTransferableAmount = void 0;
|
4
|
-
const util_1 = require("@talismn/util");
|
5
|
-
function excludeFromTransferableAmount(locks) {
|
6
|
-
if (typeof locks === "string")
|
7
|
-
return BigInt(locks);
|
8
|
-
if (!Array.isArray(locks))
|
9
|
-
locks = [locks];
|
10
|
-
return locks
|
11
|
-
.filter((lock) => lock.includeInTransferable !== true)
|
12
|
-
.map((lock) => BigInt(lock.amount))
|
13
|
-
.reduce((max, lock) => util_1.BigMath.max(max, lock), BigInt("0"));
|
14
|
-
}
|
15
|
-
exports.excludeFromTransferableAmount = excludeFromTransferableAmount;
|
16
|
-
function excludeFromFeePayableLocks(locks) {
|
17
|
-
if (typeof locks === "string")
|
18
|
-
return [];
|
19
|
-
if (!Array.isArray(locks))
|
20
|
-
locks = [locks];
|
21
|
-
return locks.filter((lock) => lock.excludeFromFeePayable);
|
22
|
-
}
|
23
|
-
exports.excludeFromFeePayableLocks = excludeFromFeePayableLocks;
|
24
|
-
function includeInTotalExtraAmount(extra) {
|
25
|
-
if (!extra)
|
26
|
-
return BigInt("0");
|
27
|
-
if (!Array.isArray(extra))
|
28
|
-
extra = [extra];
|
29
|
-
return extra
|
30
|
-
.filter((extra) => extra.includeInTotal)
|
31
|
-
.map((extra) => BigInt(extra.amount))
|
32
|
-
.reduce((a, b) => a + b, BigInt("0"));
|
33
|
-
}
|
34
|
-
exports.includeInTotalExtraAmount = includeInTotalExtraAmount;
|
package/dist/types/index.js
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./addresses"), exports);
|
18
|
-
__exportStar(require("./balances"), exports);
|
19
|
-
__exportStar(require("./balancetypes"), exports);
|
20
|
-
__exportStar(require("./subscriptions"), exports);
|