@talismn/balances 0.2.1 → 0.2.3

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,5 +1,17 @@
1
1
  # @talismn/balances
2
2
 
3
+ ## 0.2.3
4
+
5
+ ## 0.2.2
6
+
7
+ ### Patch Changes
8
+
9
+ - Updated dependencies [931b6ca]
10
+ - @talismn/chain-connector-evm@0.3.0
11
+ - @talismn/chain-connector@0.2.0
12
+ - @talismn/chaindata-provider@0.2.0
13
+ - @talismn/token-rates@0.1.11
14
+
3
15
  ## 0.2.1
4
16
 
5
17
  ## 0.2.0
@@ -1,5 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultBalanceModule = void 0;
1
4
  // TODO: Document default balances module purpose/usage
2
- export const DefaultBalanceModule = (type) => ({
5
+ const DefaultBalanceModule = (type) => ({
3
6
  get type() {
4
7
  return type;
5
8
  },
@@ -23,3 +26,4 @@ export const DefaultBalanceModule = (type) => ({
23
26
  throw new Error("Balance fetching is not implemented in this module.");
24
27
  },
25
28
  });
29
+ exports.DefaultBalanceModule = DefaultBalanceModule;
@@ -1,5 +1,8 @@
1
- import { Dexie } from "dexie";
2
- export class TalismanBalancesDatabase extends Dexie {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.db = exports.TalismanBalancesDatabase = void 0;
4
+ const dexie_1 = require("dexie");
5
+ class TalismanBalancesDatabase extends dexie_1.Dexie {
3
6
  balances;
4
7
  constructor() {
5
8
  super("TalismanBalances");
@@ -16,4 +19,5 @@ export class TalismanBalancesDatabase extends Dexie {
16
19
  // this.on("ready", async () => {})
17
20
  }
18
21
  }
19
- export const db = new TalismanBalancesDatabase();
22
+ exports.TalismanBalancesDatabase = TalismanBalancesDatabase;
23
+ exports.db = new TalismanBalancesDatabase();
package/dist/helpers.js CHANGED
@@ -1,7 +1,11 @@
1
- export async function balances(balanceModule, chainConnectors, chaindataProvider, addressesByToken, callback) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.balances = void 0;
4
+ async function balances(balanceModule, chainConnectors, chaindataProvider, addressesByToken, callback) {
2
5
  // subscription request
3
6
  if (callback !== undefined)
4
7
  return await balanceModule.subscribeBalances(chainConnectors, chaindataProvider, addressesByToken, callback);
5
8
  // one-off request
6
9
  return await balanceModule.fetchBalances(chainConnectors, chaindataProvider, addressesByToken);
7
10
  }
11
+ exports.balances = balances;
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  //
2
3
  // NOTE: Do not export `./plugins` from here!
3
4
  // Doing so will introduce a circular dependency!
@@ -9,7 +10,22 @@
9
10
  //
10
11
  // import { PluginBalanceTypes } from '@talismn/balances'
11
12
  //
12
- export * from "./BalanceModule";
13
- export * from "./TalismanBalancesDatabase";
14
- export * from "./helpers";
15
- export * from "./types";
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ __exportStar(require("./BalanceModule"), exports);
29
+ __exportStar(require("./TalismanBalancesDatabase"), exports);
30
+ __exportStar(require("./helpers"), exports);
31
+ __exportStar(require("./types"), exports);
package/dist/log.js CHANGED
@@ -1,5 +1,10 @@
1
- import anylogger from "anylogger";
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const anylogger_1 = __importDefault(require("anylogger"));
2
7
  // eslint-disable-next-line @typescript-eslint/no-var-requires
3
8
  const { name } = require("../package.json");
4
9
  // import { name } from "../package.json"
5
- export default anylogger(name);
10
+ exports.default = (0, anylogger_1.default)(name);
package/dist/plugins.js CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,18 +1,24 @@
1
+ "use strict";
1
2
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
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;
5
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
7
  };
7
- import { BigMath, isArrayOf, planckToTokens } from "@talismn/util";
8
- import memoize from "lodash/memoize";
9
- import { Memoize } from "typescript-memoize";
10
- import log from "../log";
11
- import { excludeFromFeePayableLocks, excludeFromTransferableAmount, includeInTotalExtraAmount, } from "./balancetypes";
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 log_1 = __importDefault(require("../log"));
17
+ const balancetypes_1 = require("./balancetypes");
12
18
  /**
13
19
  * A collection of balances.
14
20
  */
15
- export class Balances {
21
+ class Balances {
16
22
  //
17
23
  // Properties
18
24
  //
@@ -34,7 +40,7 @@ export class Balances {
34
40
  if (balances.length === 0)
35
41
  return this;
36
42
  // handle BalanceJson[]
37
- if (!isArrayOf(balances, Balance))
43
+ if (!(0, util_1.isArrayOf)(balances, Balance))
38
44
  return new Balances(balances.map((storage) => new Balance(storage)), hydrate);
39
45
  // handle Balance[]
40
46
  this.#balances = Object.fromEntries(balances.map((balance) => [balance.id, balance]));
@@ -50,7 +56,7 @@ export class Balances {
50
56
  return [id, balance.toJSON()];
51
57
  }
52
58
  catch (error) {
53
- log.error("Failed to convert balance to JSON", error, { id, balance });
59
+ log_1.default.error("Failed to convert balance to JSON", error, { id, balance });
54
60
  return null;
55
61
  }
56
62
  })
@@ -168,18 +174,19 @@ export class Balances {
168
174
  }
169
175
  }
170
176
  __decorate([
171
- Memoize()
177
+ (0, typescript_memoize_1.Memoize)()
172
178
  ], Balances.prototype, "sorted", null);
173
179
  __decorate([
174
- Memoize()
180
+ (0, typescript_memoize_1.Memoize)()
175
181
  ], Balances.prototype, "count", null);
176
182
  __decorate([
177
- Memoize()
183
+ (0, typescript_memoize_1.Memoize)()
178
184
  ], Balances.prototype, "sum", null);
185
+ exports.Balances = Balances;
179
186
  /**
180
187
  * An individual balance.
181
188
  */
182
- export class Balance {
189
+ class Balance {
183
190
  //
184
191
  // Properties
185
192
  //
@@ -190,7 +197,7 @@ export class Balance {
190
197
  // Methods
191
198
  //
192
199
  constructor(storage, hydrate) {
193
- this.#format = memoize(this.#format);
200
+ this.#format = (0, memoize_1.default)(this.#format);
194
201
  this.#storage = storage;
195
202
  if (hydrate !== undefined)
196
203
  this.hydrate(hydrate);
@@ -264,7 +271,7 @@ export class Balance {
264
271
  * The balance will be reaped if this goes below the existential deposit.
265
272
  */
266
273
  get total() {
267
- const extra = includeInTotalExtraAmount(this.#storage.extra);
274
+ const extra = (0, balancetypes_1.includeInTotalExtraAmount)(this.#storage.extra);
268
275
  return this.#format(this.free.planck + this.reserved.planck + extra);
269
276
  }
270
277
  /** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
@@ -294,7 +301,7 @@ export class Balance {
294
301
  : Array.isArray(this.#storage.locks)
295
302
  ? this.#storage.locks
296
303
  .map((lock) => BigInt(lock.amount))
297
- .reduce((a, b) => BigMath.max(a, b), BigInt("0"))
304
+ .reduce((a, b) => util_1.BigMath.max(a, b), BigInt("0"))
298
305
  : BigInt(this.#storage.locks?.amount || "0"));
299
306
  }
300
307
  /** @depreacted - use balance.locked */
@@ -307,9 +314,9 @@ export class Balance {
307
314
  if (!this.#storage.locks)
308
315
  return this.free;
309
316
  // find the largest lock (but ignore any locks which are marked as `includeInTransferable`)
310
- const excludeAmount = excludeFromTransferableAmount(this.#storage.locks);
317
+ const excludeAmount = (0, balancetypes_1.excludeFromTransferableAmount)(this.#storage.locks);
311
318
  // subtract the lock from the free amount (but don't go below 0)
312
- return this.#format(BigMath.max(this.free.planck - excludeAmount, BigInt("0")));
319
+ return this.#format(util_1.BigMath.max(this.free.planck - excludeAmount, BigInt("0")));
313
320
  }
314
321
  /** The feePayable balance of this token. Is generally the free amount - the feeFrozen amount. */
315
322
  get feePayable() {
@@ -317,35 +324,36 @@ export class Balance {
317
324
  if (!this.#storage.locks)
318
325
  return this.free;
319
326
  // find the largest lock which can't be used to pay tx fees
320
- const excludeAmount = excludeFromFeePayableLocks(this.#storage.locks)
327
+ const excludeAmount = (0, balancetypes_1.excludeFromFeePayableLocks)(this.#storage.locks)
321
328
  .map((lock) => BigInt(lock.amount))
322
- .reduce((max, lock) => BigMath.max(max, lock), BigInt("0"));
329
+ .reduce((max, lock) => util_1.BigMath.max(max, lock), BigInt("0"));
323
330
  // subtract the lock from the free amount (but don't go below 0)
324
- return this.#format(BigMath.max(this.free.planck - excludeAmount, BigInt("0")));
331
+ return this.#format(util_1.BigMath.max(this.free.planck - excludeAmount, BigInt("0")));
325
332
  }
326
333
  }
327
334
  __decorate([
328
- Memoize()
335
+ (0, typescript_memoize_1.Memoize)()
329
336
  ], Balance.prototype, "total", null);
330
337
  __decorate([
331
- Memoize()
338
+ (0, typescript_memoize_1.Memoize)()
332
339
  ], Balance.prototype, "free", null);
333
340
  __decorate([
334
- Memoize()
341
+ (0, typescript_memoize_1.Memoize)()
335
342
  ], Balance.prototype, "reserved", null);
336
343
  __decorate([
337
- Memoize()
344
+ (0, typescript_memoize_1.Memoize)()
338
345
  ], Balance.prototype, "locked", null);
339
346
  __decorate([
340
- Memoize()
347
+ (0, typescript_memoize_1.Memoize)()
341
348
  ], Balance.prototype, "frozen", null);
342
349
  __decorate([
343
- Memoize()
350
+ (0, typescript_memoize_1.Memoize)()
344
351
  ], Balance.prototype, "transferable", null);
345
352
  __decorate([
346
- Memoize()
353
+ (0, typescript_memoize_1.Memoize)()
347
354
  ], Balance.prototype, "feePayable", null);
348
- export class BalanceFormatter {
355
+ exports.Balance = Balance;
356
+ class BalanceFormatter {
349
357
  #planck;
350
358
  #decimals;
351
359
  #fiatRatios;
@@ -353,14 +361,14 @@ export class BalanceFormatter {
353
361
  this.#planck = typeof planck === "bigint" ? planck.toString() : planck ?? "0";
354
362
  this.#decimals = decimals || 0;
355
363
  this.#fiatRatios = fiatRatios || null;
356
- this.fiat = memoize(this.fiat);
364
+ this.fiat = (0, memoize_1.default)(this.fiat);
357
365
  }
358
366
  toJSON = () => this.#planck;
359
367
  get planck() {
360
368
  return BigInt(this.#planck);
361
369
  }
362
370
  get tokens() {
363
- return planckToTokens(this.#planck, this.#decimals);
371
+ return (0, util_1.planckToTokens)(this.#planck, this.#decimals);
364
372
  }
365
373
  fiat(currency) {
366
374
  if (!this.#fiatRatios)
@@ -372,15 +380,16 @@ export class BalanceFormatter {
372
380
  }
373
381
  }
374
382
  __decorate([
375
- Memoize()
383
+ (0, typescript_memoize_1.Memoize)()
376
384
  ], BalanceFormatter.prototype, "tokens", null);
377
- export class FiatSumBalancesFormatter {
385
+ exports.BalanceFormatter = BalanceFormatter;
386
+ class FiatSumBalancesFormatter {
378
387
  #balances;
379
388
  #currency;
380
389
  constructor(balances, currency) {
381
390
  this.#balances = balances;
382
391
  this.#currency = currency;
383
- this.#sum = memoize(this.#sum);
392
+ this.#sum = (0, memoize_1.default)(this.#sum);
384
393
  }
385
394
  #sum = (balanceField) => {
386
395
  // a function to get a fiat amount from a balance
@@ -427,33 +436,35 @@ export class FiatSumBalancesFormatter {
427
436
  }
428
437
  }
429
438
  __decorate([
430
- Memoize()
439
+ (0, typescript_memoize_1.Memoize)()
431
440
  ], FiatSumBalancesFormatter.prototype, "total", null);
432
441
  __decorate([
433
- Memoize()
442
+ (0, typescript_memoize_1.Memoize)()
434
443
  ], FiatSumBalancesFormatter.prototype, "free", null);
435
444
  __decorate([
436
- Memoize()
445
+ (0, typescript_memoize_1.Memoize)()
437
446
  ], FiatSumBalancesFormatter.prototype, "reserved", null);
438
447
  __decorate([
439
- Memoize()
448
+ (0, typescript_memoize_1.Memoize)()
440
449
  ], FiatSumBalancesFormatter.prototype, "locked", null);
441
450
  __decorate([
442
- Memoize()
451
+ (0, typescript_memoize_1.Memoize)()
443
452
  ], FiatSumBalancesFormatter.prototype, "frozen", null);
444
453
  __decorate([
445
- Memoize()
454
+ (0, typescript_memoize_1.Memoize)()
446
455
  ], FiatSumBalancesFormatter.prototype, "transferable", null);
447
456
  __decorate([
448
- Memoize()
457
+ (0, typescript_memoize_1.Memoize)()
449
458
  ], FiatSumBalancesFormatter.prototype, "feePayable", null);
450
- export class SumBalancesFormatter {
459
+ exports.FiatSumBalancesFormatter = FiatSumBalancesFormatter;
460
+ class SumBalancesFormatter {
451
461
  #balances;
452
462
  constructor(balances) {
453
463
  this.#balances = balances;
454
- this.fiat = memoize(this.fiat);
464
+ this.fiat = (0, memoize_1.default)(this.fiat);
455
465
  }
456
466
  fiat(currency) {
457
467
  return new FiatSumBalancesFormatter(this.#balances, currency);
458
468
  }
459
469
  }
470
+ exports.SumBalancesFormatter = SumBalancesFormatter;
@@ -1,5 +1,8 @@
1
- import { BigMath } from "@talismn/util";
2
- export function excludeFromTransferableAmount(locks) {
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) {
3
6
  if (typeof locks === "string")
4
7
  return BigInt(locks);
5
8
  if (!Array.isArray(locks))
@@ -7,16 +10,18 @@ export function excludeFromTransferableAmount(locks) {
7
10
  return locks
8
11
  .filter((lock) => lock.includeInTransferable !== true)
9
12
  .map((lock) => BigInt(lock.amount))
10
- .reduce((max, lock) => BigMath.max(max, lock), BigInt("0"));
13
+ .reduce((max, lock) => util_1.BigMath.max(max, lock), BigInt("0"));
11
14
  }
12
- export function excludeFromFeePayableLocks(locks) {
15
+ exports.excludeFromTransferableAmount = excludeFromTransferableAmount;
16
+ function excludeFromFeePayableLocks(locks) {
13
17
  if (typeof locks === "string")
14
18
  return [];
15
19
  if (!Array.isArray(locks))
16
20
  locks = [locks];
17
21
  return locks.filter((lock) => lock.excludeFromFeePayable);
18
22
  }
19
- export function includeInTotalExtraAmount(extra) {
23
+ exports.excludeFromFeePayableLocks = excludeFromFeePayableLocks;
24
+ function includeInTotalExtraAmount(extra) {
20
25
  if (!extra)
21
26
  return BigInt("0");
22
27
  if (!Array.isArray(extra))
@@ -26,3 +31,4 @@ export function includeInTotalExtraAmount(extra) {
26
31
  .map((extra) => BigInt(extra.amount))
27
32
  .reduce((a, b) => a + b, BigInt("0"));
28
33
  }
34
+ exports.includeInTotalExtraAmount = includeInTotalExtraAmount;
@@ -1,4 +1,20 @@
1
- export * from "./addresses";
2
- export * from "./balances";
3
- export * from "./balancetypes";
4
- export * from "./subscriptions";
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);
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/balances",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "UNLICENSED",
@@ -31,10 +31,10 @@
31
31
  "clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
32
32
  },
33
33
  "dependencies": {
34
- "@talismn/chain-connector": "^0.1.10",
35
- "@talismn/chain-connector-evm": "^0.2.0",
36
- "@talismn/chaindata-provider": "^0.1.10",
37
- "@talismn/token-rates": "^0.1.10",
34
+ "@talismn/chain-connector": "^0.2.0",
35
+ "@talismn/chain-connector-evm": "^0.3.0",
36
+ "@talismn/chaindata-provider": "^0.2.0",
37
+ "@talismn/token-rates": "^0.1.11",
38
38
  "@talismn/util": "^0.1.4",
39
39
  "lodash": "^4.17.21",
40
40
  "typescript-memoize": "^1.1.0"