@talismn/balances 0.0.0-pr563-20230222051735 → 0.0.0-pr573-20230227134247
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 +6 -2
- package/dist/declarations/src/BalanceModule.d.ts +6 -28
- package/dist/declarations/src/helpers.d.ts +3 -3
- package/dist/declarations/src/types/balances.d.ts +7 -7
- package/dist/talismn-balances.cjs.dev.js +31 -18
- package/dist/talismn-balances.cjs.prod.js +31 -18
- package/dist/talismn-balances.esm.js +31 -18
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# @talismn/balances
|
2
2
|
|
3
|
-
## 0.0.0-
|
3
|
+
## 0.0.0-pr573-20230227134247
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
7
|
-
-
|
7
|
+
- Updated dependencies [87a1348]
|
8
|
+
- @talismn/chaindata-provider@0.0.0-pr573-20230227134247
|
9
|
+
- @talismn/chain-connector@0.0.0-pr573-20230227134247
|
10
|
+
- @talismn/chain-connector-evm@0.0.0-pr573-20230227134247
|
11
|
+
- @talismn/token-rates@0.0.0-pr573-20230227134247
|
8
12
|
|
9
13
|
## 0.3.3
|
10
14
|
|
@@ -1,46 +1,28 @@
|
|
1
|
-
import { UnsignedTransaction } from "@substrate/txwrapper-core";
|
2
1
|
import { ChainConnector } from "@talismn/chain-connector";
|
3
2
|
import { ChainConnectorEvm } from "@talismn/chain-connector-evm";
|
4
3
|
import { ChainId, ChaindataProvider, IToken } from "@talismn/chaindata-provider";
|
5
|
-
import { ethers } from "ethers";
|
6
4
|
import { AddressesByToken, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
|
5
|
+
export interface BalanceModule<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig> extends BalanceModuleSubstrate<TModuleType, TTokenType, TChainMeta, TModuleConfig>, BalanceModuleEvm<TModuleType, TTokenType, TChainMeta, TModuleConfig> {
|
6
|
+
}
|
7
|
+
export declare const DefaultBalanceModule: <TModuleType extends string, TTokenType extends IToken, TChainMeta extends ExtendableChainMeta = undefined, TModuleConfig extends ExtendableModuleConfig = undefined>(type: TModuleType) => BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig>;
|
7
8
|
export type ExtendableTokenType = IToken;
|
8
9
|
export type ExtendableChainMeta = Record<string, unknown> | undefined;
|
9
10
|
export type DefaultChainMeta = undefined;
|
10
11
|
export type ExtendableModuleConfig = Record<string, unknown> | undefined;
|
11
12
|
export type DefaultModuleConfig = undefined;
|
12
|
-
|
13
|
-
tokenId: string;
|
14
|
-
from: string;
|
15
|
-
to: string;
|
16
|
-
amount: string;
|
17
|
-
};
|
18
|
-
export type ExtendableTransferParams = BaseTransferParams | undefined;
|
19
|
-
export type DefaultTransferParams = undefined;
|
20
|
-
export type NewTransferParamsType<T extends Record<string, unknown>> = BaseTransferParams & T;
|
21
|
-
export type TransferTokenTx = {
|
22
|
-
type: "substrate";
|
23
|
-
tx: UnsignedTransaction;
|
24
|
-
} | {
|
25
|
-
type: "evm";
|
26
|
-
tx: ethers.providers.TransactionRequest;
|
27
|
-
};
|
28
|
-
export interface BalanceModule<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig, TTransferParams extends ExtendableTransferParams = DefaultTransferParams> extends BalanceModuleSubstrate<TModuleType, TTokenType, TChainMeta, TModuleConfig, TTransferParams>, BalanceModuleEvm<TModuleType, TTokenType, TChainMeta, TModuleConfig, TTransferParams> {
|
29
|
-
}
|
30
|
-
export declare const DefaultBalanceModule: <TModuleType extends string, TTokenType extends IToken, TChainMeta extends ExtendableChainMeta = undefined, TModuleConfig extends ExtendableModuleConfig = undefined, TTransferParams extends ExtendableTransferParams = undefined>(type: TModuleType) => BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig, TTransferParams>;
|
31
|
-
interface BalanceModuleSubstrate<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig, TTransferParams extends ExtendableTransferParams = DefaultTransferParams> extends BalanceModuleCommon<TModuleType, TTokenType, TTransferParams> {
|
13
|
+
interface BalanceModuleSubstrate<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig> extends BalanceModuleCommon<TModuleType, TTokenType> {
|
32
14
|
/** Pre-processes any substrate chain metadata required by this module ahead of time */
|
33
15
|
fetchSubstrateChainMeta(chainConnector: ChainConnector, chaindataProvider: ChaindataProvider, chainId: ChainId, moduleConfig: TModuleConfig | undefined): Promise<TChainMeta | null>;
|
34
16
|
/** Detects which tokens are available on a given substrate chain */
|
35
17
|
fetchSubstrateChainTokens(chainConnector: ChainConnector, chaindataProvider: ChaindataProvider, chainId: ChainId, chainMeta: TChainMeta, moduleConfig: TModuleConfig | undefined): Promise<Record<TTokenType["id"], TTokenType>>;
|
36
18
|
}
|
37
|
-
interface BalanceModuleEvm<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig
|
19
|
+
interface BalanceModuleEvm<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig> extends BalanceModuleCommon<TModuleType, TTokenType> {
|
38
20
|
/** Pre-processes any evm chain metadata required by this module ahead of time */
|
39
21
|
fetchEvmChainMeta(chainConnector: ChainConnectorEvm, chaindataProvider: ChaindataProvider, chainId: ChainId, moduleConfig: TModuleConfig | undefined): Promise<TChainMeta | null>;
|
40
22
|
/** Detects which tokens are available on a given evm chain */
|
41
23
|
fetchEvmChainTokens(chainConnector: ChainConnectorEvm, chaindataProvider: ChaindataProvider, chainId: ChainId, chainMeta: TChainMeta, moduleConfig: TModuleConfig | undefined): Promise<Record<TTokenType["id"], TTokenType>>;
|
42
24
|
}
|
43
|
-
interface BalanceModuleCommon<TModuleType extends string, TTokenType extends ExtendableTokenType
|
25
|
+
interface BalanceModuleCommon<TModuleType extends string, TTokenType extends ExtendableTokenType> {
|
44
26
|
get type(): TModuleType;
|
45
27
|
/**
|
46
28
|
* Subscribe to balances for this module with optional filtering.
|
@@ -56,10 +38,6 @@ interface BalanceModuleCommon<TModuleType extends string, TTokenType extends Ext
|
|
56
38
|
substrate?: ChainConnector;
|
57
39
|
evm?: ChainConnectorEvm;
|
58
40
|
}, chaindataProvider: ChaindataProvider, addressesByToken: AddressesByToken<TTokenType>): Promise<Balances>;
|
59
|
-
transferToken(chainConnectors: {
|
60
|
-
substrate?: ChainConnector;
|
61
|
-
evm?: ChainConnectorEvm;
|
62
|
-
}, chaindataProvider: ChaindataProvider, transferParams: TTransferParams): Promise<TransferTokenTx | null>;
|
63
41
|
[x: string | number | symbol]: unknown;
|
64
42
|
}
|
65
43
|
export {};
|
@@ -2,17 +2,17 @@ import { TypeRegistry } from "@polkadot/types";
|
|
2
2
|
import { ChainConnector } from "@talismn/chain-connector";
|
3
3
|
import { ChainConnectorEvm } from "@talismn/chain-connector-evm";
|
4
4
|
import { ChaindataProvider } from "@talismn/chaindata-provider";
|
5
|
-
import { BalanceModule, DefaultChainMeta, DefaultModuleConfig,
|
5
|
+
import { BalanceModule, DefaultChainMeta, DefaultModuleConfig, ExtendableChainMeta, ExtendableModuleConfig, ExtendableTokenType } from "./BalanceModule";
|
6
6
|
import { AddressesByToken, Balance, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
|
7
7
|
/**
|
8
8
|
* Wraps a BalanceModule's fetch/subscribe methods with a single `balances` method.
|
9
9
|
* This `balances` method will subscribe if a callback parameter is provided, or otherwise fetch.
|
10
10
|
*/
|
11
|
-
export declare function balances<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig
|
11
|
+
export declare function balances<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig>(balanceModule: BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig>, chainConnectors: {
|
12
12
|
substrate?: ChainConnector;
|
13
13
|
evm?: ChainConnectorEvm;
|
14
14
|
}, chaindataProvider: ChaindataProvider, addressesByToken: AddressesByToken<TTokenType>): Promise<Balances>;
|
15
|
-
export declare function balances<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig
|
15
|
+
export declare function balances<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig>(balanceModule: BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig>, chainConnectors: {
|
16
16
|
substrate?: ChainConnector;
|
17
17
|
evm?: ChainConnectorEvm;
|
18
18
|
}, chaindataProvider: ChaindataProvider, addressesByToken: AddressesByToken<TTokenType>, callback: SubscriptionCallback<Balances>): Promise<UnsubscribeFn>;
|
@@ -115,13 +115,13 @@ export declare class Balance {
|
|
115
115
|
get source(): string;
|
116
116
|
get status(): import("./balancetypes").BalanceStatus;
|
117
117
|
get address(): string;
|
118
|
-
get chainId():
|
119
|
-
get chain():
|
120
|
-
get evmNetworkId():
|
121
|
-
get evmNetwork():
|
122
|
-
get tokenId():
|
123
|
-
get token():
|
124
|
-
get decimals():
|
118
|
+
get chainId(): string | undefined;
|
119
|
+
get chain(): import("@talismn/chaindata-provider").Chain | null;
|
120
|
+
get evmNetworkId(): string | undefined;
|
121
|
+
get evmNetwork(): import("@talismn/chaindata-provider").EvmNetwork | null;
|
122
|
+
get tokenId(): string;
|
123
|
+
get token(): import("@talismn/chaindata-provider").IToken | null;
|
124
|
+
get decimals(): number | null;
|
125
125
|
get rates(): TokenRates | null;
|
126
126
|
/**
|
127
127
|
* The total balance of this token.
|
@@ -41,9 +41,6 @@ const DefaultBalanceModule = type => ({
|
|
41
41
|
},
|
42
42
|
async fetchBalances() {
|
43
43
|
throw new Error("Balance fetching is not implemented in this module.");
|
44
|
-
},
|
45
|
-
async transferToken() {
|
46
|
-
throw new Error("Token transfers are not implemented in this module.");
|
47
44
|
}
|
48
45
|
});
|
49
46
|
|
@@ -74,7 +71,7 @@ const db = new TalismanBalancesDatabase();
|
|
74
71
|
|
75
72
|
var packageJson = {
|
76
73
|
name: "@talismn/balances",
|
77
|
-
version: "0.0.0-
|
74
|
+
version: "0.0.0-pr573-20230227134247",
|
78
75
|
author: "Talisman",
|
79
76
|
homepage: "https://talisman.xyz",
|
80
77
|
license: "UNLICENSED",
|
@@ -107,7 +104,7 @@ var packageJson = {
|
|
107
104
|
"@talismn/token-rates": "workspace:^",
|
108
105
|
"@talismn/util": "workspace:^",
|
109
106
|
anylogger: "^1.0.11",
|
110
|
-
dexie: "^3.2.
|
107
|
+
dexie: "^3.2.3",
|
111
108
|
lodash: "^4.17.21",
|
112
109
|
"typescript-memoize": "^1.1.0"
|
113
110
|
},
|
@@ -148,8 +145,9 @@ async function balances(balanceModule, chainConnectors, chaindataProvider, addre
|
|
148
145
|
return await balanceModule.fetchBalances(chainConnectors, chaindataProvider, addressesByToken);
|
149
146
|
}
|
150
147
|
const filterMirrorTokens = (balance, i, balances) => {
|
151
|
-
|
152
|
-
|
148
|
+
var _balance$token;
|
149
|
+
// TODO implement a mirrorOf property, which should be set from chaindata
|
150
|
+
const mirrorOf = (_balance$token = balance.token) === null || _balance$token === void 0 ? void 0 : _balance$token.mirrorOf;
|
153
151
|
return !mirrorOf || !balances.find(b => b.tokenId === mirrorOf);
|
154
152
|
};
|
155
153
|
|
@@ -185,7 +183,8 @@ class StorageHelper {
|
|
185
183
|
}
|
186
184
|
}
|
187
185
|
get stateKey() {
|
188
|
-
|
186
|
+
var _this$storageKey;
|
187
|
+
return (_this$storageKey = this.#storageKey) === null || _this$storageKey === void 0 ? void 0 : _this$storageKey.toHex();
|
189
188
|
}
|
190
189
|
get module() {
|
191
190
|
return this.#module;
|
@@ -440,7 +439,10 @@ let Balances = (_dec = typescriptMemoize.Memoize(), _dec2 = typescriptMemoize.Me
|
|
440
439
|
* @returns A sorted array of the balances in this collection.
|
441
440
|
*/
|
442
441
|
get sorted() {
|
443
|
-
return [...this].sort((a, b) =>
|
442
|
+
return [...this].sort((a, b) => {
|
443
|
+
var _ref, _ref2;
|
444
|
+
return (((_ref = a.chain || a.evmNetwork) === null || _ref === void 0 ? void 0 : _ref.sortIndex) || Number.MAX_SAFE_INTEGER) - (((_ref2 = b.chain || b.evmNetwork) === null || _ref2 === void 0 ? void 0 : _ref2.sortIndex) || Number.MAX_SAFE_INTEGER);
|
445
|
+
});
|
444
446
|
}
|
445
447
|
|
446
448
|
/**
|
@@ -505,7 +507,10 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
|
|
505
507
|
hydrate = hydrate => {
|
506
508
|
if (hydrate !== undefined) this.#db = hydrate;
|
507
509
|
};
|
508
|
-
#format = balance =>
|
510
|
+
#format = balance => {
|
511
|
+
var _this$db;
|
512
|
+
return new BalanceFormatter(typeof balance === "bigint" ? balance.toString() : balance, this.decimals || undefined, ((_this$db = this.#db) === null || _this$db === void 0 ? void 0 : _this$db.tokenRates) && this.#db.tokenRates[this.tokenId]);
|
513
|
+
};
|
509
514
|
|
510
515
|
//
|
511
516
|
// Accessors
|
@@ -535,27 +540,32 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
|
|
535
540
|
return this.#storage.chainId;
|
536
541
|
}
|
537
542
|
get chain() {
|
538
|
-
|
543
|
+
var _this$db2, _this$db3;
|
544
|
+
return ((_this$db2 = this.#db) === null || _this$db2 === void 0 ? void 0 : _this$db2.chains) && this.chainId && ((_this$db3 = this.#db) === null || _this$db3 === void 0 ? void 0 : _this$db3.chains[this.chainId]) || null;
|
539
545
|
}
|
540
546
|
get evmNetworkId() {
|
541
547
|
return this.#storage.evmNetworkId;
|
542
548
|
}
|
543
549
|
get evmNetwork() {
|
550
|
+
var _this$db4, _this$db5;
|
544
551
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
545
|
-
return this.#db
|
552
|
+
return ((_this$db4 = this.#db) === null || _this$db4 === void 0 ? void 0 : _this$db4.evmNetworks) && ((_this$db5 = this.#db) === null || _this$db5 === void 0 ? void 0 : _this$db5.evmNetworks[this.evmNetworkId]) || null;
|
546
553
|
}
|
547
554
|
get tokenId() {
|
548
555
|
return this.#storage.tokenId;
|
549
556
|
}
|
550
557
|
get token() {
|
558
|
+
var _this$db6, _this$db7;
|
551
559
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
552
|
-
return this.#db
|
560
|
+
return ((_this$db6 = this.#db) === null || _this$db6 === void 0 ? void 0 : _this$db6.tokens) && ((_this$db7 = this.#db) === null || _this$db7 === void 0 ? void 0 : _this$db7.tokens[this.tokenId]) || null;
|
553
561
|
}
|
554
562
|
get decimals() {
|
555
|
-
|
563
|
+
var _this$token;
|
564
|
+
return ((_this$token = this.token) === null || _this$token === void 0 ? void 0 : _this$token.decimals) || null;
|
556
565
|
}
|
557
566
|
get rates() {
|
558
|
-
|
567
|
+
var _this$db8;
|
568
|
+
return ((_this$db8 = this.#db) === null || _this$db8 === void 0 ? void 0 : _this$db8.tokenRates) && this.#db.tokenRates[this.tokenId] || null;
|
559
569
|
}
|
560
570
|
|
561
571
|
/**
|
@@ -569,15 +579,18 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
|
|
569
579
|
}
|
570
580
|
/** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
|
571
581
|
get free() {
|
572
|
-
|
582
|
+
var _this$storage$free;
|
583
|
+
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, BigInt("0")) : BigInt(((_this$storage$free = this.#storage.free) === null || _this$storage$free === void 0 ? void 0 : _this$storage$free.amount) || "0"));
|
573
584
|
}
|
574
585
|
/** The reserved balance of this token. Is included in the total. */
|
575
586
|
get reserved() {
|
576
|
-
|
587
|
+
var _this$storage$reserve;
|
588
|
+
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, BigInt("0")) : BigInt(((_this$storage$reserve = this.#storage.reserves) === null || _this$storage$reserve === void 0 ? void 0 : _this$storage$reserve.amount) || "0"));
|
577
589
|
}
|
578
590
|
/** The frozen balance of this token. Is included in the free amount. */
|
579
591
|
get locked() {
|
580
|
-
|
592
|
+
var _this$storage$locks;
|
593
|
+
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), BigInt("0")) : BigInt(((_this$storage$locks = this.#storage.locks) === null || _this$storage$locks === void 0 ? void 0 : _this$storage$locks.amount) || "0"));
|
581
594
|
}
|
582
595
|
/** @depreacted - use balance.locked */
|
583
596
|
get frozen() {
|
@@ -41,9 +41,6 @@ const DefaultBalanceModule = type => ({
|
|
41
41
|
},
|
42
42
|
async fetchBalances() {
|
43
43
|
throw new Error("Balance fetching is not implemented in this module.");
|
44
|
-
},
|
45
|
-
async transferToken() {
|
46
|
-
throw new Error("Token transfers are not implemented in this module.");
|
47
44
|
}
|
48
45
|
});
|
49
46
|
|
@@ -74,7 +71,7 @@ const db = new TalismanBalancesDatabase();
|
|
74
71
|
|
75
72
|
var packageJson = {
|
76
73
|
name: "@talismn/balances",
|
77
|
-
version: "0.0.0-
|
74
|
+
version: "0.0.0-pr573-20230227134247",
|
78
75
|
author: "Talisman",
|
79
76
|
homepage: "https://talisman.xyz",
|
80
77
|
license: "UNLICENSED",
|
@@ -107,7 +104,7 @@ var packageJson = {
|
|
107
104
|
"@talismn/token-rates": "workspace:^",
|
108
105
|
"@talismn/util": "workspace:^",
|
109
106
|
anylogger: "^1.0.11",
|
110
|
-
dexie: "^3.2.
|
107
|
+
dexie: "^3.2.3",
|
111
108
|
lodash: "^4.17.21",
|
112
109
|
"typescript-memoize": "^1.1.0"
|
113
110
|
},
|
@@ -148,8 +145,9 @@ async function balances(balanceModule, chainConnectors, chaindataProvider, addre
|
|
148
145
|
return await balanceModule.fetchBalances(chainConnectors, chaindataProvider, addressesByToken);
|
149
146
|
}
|
150
147
|
const filterMirrorTokens = (balance, i, balances) => {
|
151
|
-
|
152
|
-
|
148
|
+
var _balance$token;
|
149
|
+
// TODO implement a mirrorOf property, which should be set from chaindata
|
150
|
+
const mirrorOf = (_balance$token = balance.token) === null || _balance$token === void 0 ? void 0 : _balance$token.mirrorOf;
|
153
151
|
return !mirrorOf || !balances.find(b => b.tokenId === mirrorOf);
|
154
152
|
};
|
155
153
|
|
@@ -185,7 +183,8 @@ class StorageHelper {
|
|
185
183
|
}
|
186
184
|
}
|
187
185
|
get stateKey() {
|
188
|
-
|
186
|
+
var _this$storageKey;
|
187
|
+
return (_this$storageKey = this.#storageKey) === null || _this$storageKey === void 0 ? void 0 : _this$storageKey.toHex();
|
189
188
|
}
|
190
189
|
get module() {
|
191
190
|
return this.#module;
|
@@ -440,7 +439,10 @@ let Balances = (_dec = typescriptMemoize.Memoize(), _dec2 = typescriptMemoize.Me
|
|
440
439
|
* @returns A sorted array of the balances in this collection.
|
441
440
|
*/
|
442
441
|
get sorted() {
|
443
|
-
return [...this].sort((a, b) =>
|
442
|
+
return [...this].sort((a, b) => {
|
443
|
+
var _ref, _ref2;
|
444
|
+
return (((_ref = a.chain || a.evmNetwork) === null || _ref === void 0 ? void 0 : _ref.sortIndex) || Number.MAX_SAFE_INTEGER) - (((_ref2 = b.chain || b.evmNetwork) === null || _ref2 === void 0 ? void 0 : _ref2.sortIndex) || Number.MAX_SAFE_INTEGER);
|
445
|
+
});
|
444
446
|
}
|
445
447
|
|
446
448
|
/**
|
@@ -505,7 +507,10 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
|
|
505
507
|
hydrate = hydrate => {
|
506
508
|
if (hydrate !== undefined) this.#db = hydrate;
|
507
509
|
};
|
508
|
-
#format = balance =>
|
510
|
+
#format = balance => {
|
511
|
+
var _this$db;
|
512
|
+
return new BalanceFormatter(typeof balance === "bigint" ? balance.toString() : balance, this.decimals || undefined, ((_this$db = this.#db) === null || _this$db === void 0 ? void 0 : _this$db.tokenRates) && this.#db.tokenRates[this.tokenId]);
|
513
|
+
};
|
509
514
|
|
510
515
|
//
|
511
516
|
// Accessors
|
@@ -535,27 +540,32 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
|
|
535
540
|
return this.#storage.chainId;
|
536
541
|
}
|
537
542
|
get chain() {
|
538
|
-
|
543
|
+
var _this$db2, _this$db3;
|
544
|
+
return ((_this$db2 = this.#db) === null || _this$db2 === void 0 ? void 0 : _this$db2.chains) && this.chainId && ((_this$db3 = this.#db) === null || _this$db3 === void 0 ? void 0 : _this$db3.chains[this.chainId]) || null;
|
539
545
|
}
|
540
546
|
get evmNetworkId() {
|
541
547
|
return this.#storage.evmNetworkId;
|
542
548
|
}
|
543
549
|
get evmNetwork() {
|
550
|
+
var _this$db4, _this$db5;
|
544
551
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
545
|
-
return this.#db
|
552
|
+
return ((_this$db4 = this.#db) === null || _this$db4 === void 0 ? void 0 : _this$db4.evmNetworks) && ((_this$db5 = this.#db) === null || _this$db5 === void 0 ? void 0 : _this$db5.evmNetworks[this.evmNetworkId]) || null;
|
546
553
|
}
|
547
554
|
get tokenId() {
|
548
555
|
return this.#storage.tokenId;
|
549
556
|
}
|
550
557
|
get token() {
|
558
|
+
var _this$db6, _this$db7;
|
551
559
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
552
|
-
return this.#db
|
560
|
+
return ((_this$db6 = this.#db) === null || _this$db6 === void 0 ? void 0 : _this$db6.tokens) && ((_this$db7 = this.#db) === null || _this$db7 === void 0 ? void 0 : _this$db7.tokens[this.tokenId]) || null;
|
553
561
|
}
|
554
562
|
get decimals() {
|
555
|
-
|
563
|
+
var _this$token;
|
564
|
+
return ((_this$token = this.token) === null || _this$token === void 0 ? void 0 : _this$token.decimals) || null;
|
556
565
|
}
|
557
566
|
get rates() {
|
558
|
-
|
567
|
+
var _this$db8;
|
568
|
+
return ((_this$db8 = this.#db) === null || _this$db8 === void 0 ? void 0 : _this$db8.tokenRates) && this.#db.tokenRates[this.tokenId] || null;
|
559
569
|
}
|
560
570
|
|
561
571
|
/**
|
@@ -569,15 +579,18 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
|
|
569
579
|
}
|
570
580
|
/** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
|
571
581
|
get free() {
|
572
|
-
|
582
|
+
var _this$storage$free;
|
583
|
+
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, BigInt("0")) : BigInt(((_this$storage$free = this.#storage.free) === null || _this$storage$free === void 0 ? void 0 : _this$storage$free.amount) || "0"));
|
573
584
|
}
|
574
585
|
/** The reserved balance of this token. Is included in the total. */
|
575
586
|
get reserved() {
|
576
|
-
|
587
|
+
var _this$storage$reserve;
|
588
|
+
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, BigInt("0")) : BigInt(((_this$storage$reserve = this.#storage.reserves) === null || _this$storage$reserve === void 0 ? void 0 : _this$storage$reserve.amount) || "0"));
|
577
589
|
}
|
578
590
|
/** The frozen balance of this token. Is included in the free amount. */
|
579
591
|
get locked() {
|
580
|
-
|
592
|
+
var _this$storage$locks;
|
593
|
+
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), BigInt("0")) : BigInt(((_this$storage$locks = this.#storage.locks) === null || _this$storage$locks === void 0 ? void 0 : _this$storage$locks.amount) || "0"));
|
581
594
|
}
|
582
595
|
/** @depreacted - use balance.locked */
|
583
596
|
get frozen() {
|
@@ -32,9 +32,6 @@ const DefaultBalanceModule = type => ({
|
|
32
32
|
},
|
33
33
|
async fetchBalances() {
|
34
34
|
throw new Error("Balance fetching is not implemented in this module.");
|
35
|
-
},
|
36
|
-
async transferToken() {
|
37
|
-
throw new Error("Token transfers are not implemented in this module.");
|
38
35
|
}
|
39
36
|
});
|
40
37
|
|
@@ -65,7 +62,7 @@ const db = new TalismanBalancesDatabase();
|
|
65
62
|
|
66
63
|
var packageJson = {
|
67
64
|
name: "@talismn/balances",
|
68
|
-
version: "0.0.0-
|
65
|
+
version: "0.0.0-pr573-20230227134247",
|
69
66
|
author: "Talisman",
|
70
67
|
homepage: "https://talisman.xyz",
|
71
68
|
license: "UNLICENSED",
|
@@ -98,7 +95,7 @@ var packageJson = {
|
|
98
95
|
"@talismn/token-rates": "workspace:^",
|
99
96
|
"@talismn/util": "workspace:^",
|
100
97
|
anylogger: "^1.0.11",
|
101
|
-
dexie: "^3.2.
|
98
|
+
dexie: "^3.2.3",
|
102
99
|
lodash: "^4.17.21",
|
103
100
|
"typescript-memoize": "^1.1.0"
|
104
101
|
},
|
@@ -139,8 +136,9 @@ async function balances(balanceModule, chainConnectors, chaindataProvider, addre
|
|
139
136
|
return await balanceModule.fetchBalances(chainConnectors, chaindataProvider, addressesByToken);
|
140
137
|
}
|
141
138
|
const filterMirrorTokens = (balance, i, balances) => {
|
142
|
-
|
143
|
-
|
139
|
+
var _balance$token;
|
140
|
+
// TODO implement a mirrorOf property, which should be set from chaindata
|
141
|
+
const mirrorOf = (_balance$token = balance.token) === null || _balance$token === void 0 ? void 0 : _balance$token.mirrorOf;
|
144
142
|
return !mirrorOf || !balances.find(b => b.tokenId === mirrorOf);
|
145
143
|
};
|
146
144
|
|
@@ -176,7 +174,8 @@ class StorageHelper {
|
|
176
174
|
}
|
177
175
|
}
|
178
176
|
get stateKey() {
|
179
|
-
|
177
|
+
var _this$storageKey;
|
178
|
+
return (_this$storageKey = this.#storageKey) === null || _this$storageKey === void 0 ? void 0 : _this$storageKey.toHex();
|
180
179
|
}
|
181
180
|
get module() {
|
182
181
|
return this.#module;
|
@@ -431,7 +430,10 @@ let Balances = (_dec = Memoize(), _dec2 = Memoize(), _dec3 = Memoize(), (_class
|
|
431
430
|
* @returns A sorted array of the balances in this collection.
|
432
431
|
*/
|
433
432
|
get sorted() {
|
434
|
-
return [...this].sort((a, b) =>
|
433
|
+
return [...this].sort((a, b) => {
|
434
|
+
var _ref, _ref2;
|
435
|
+
return (((_ref = a.chain || a.evmNetwork) === null || _ref === void 0 ? void 0 : _ref.sortIndex) || Number.MAX_SAFE_INTEGER) - (((_ref2 = b.chain || b.evmNetwork) === null || _ref2 === void 0 ? void 0 : _ref2.sortIndex) || Number.MAX_SAFE_INTEGER);
|
436
|
+
});
|
435
437
|
}
|
436
438
|
|
437
439
|
/**
|
@@ -496,7 +498,10 @@ let Balance = (_dec4 = Memoize(), _dec5 = Memoize(), _dec6 = Memoize(), _dec7 =
|
|
496
498
|
hydrate = hydrate => {
|
497
499
|
if (hydrate !== undefined) this.#db = hydrate;
|
498
500
|
};
|
499
|
-
#format = balance =>
|
501
|
+
#format = balance => {
|
502
|
+
var _this$db;
|
503
|
+
return new BalanceFormatter(typeof balance === "bigint" ? balance.toString() : balance, this.decimals || undefined, ((_this$db = this.#db) === null || _this$db === void 0 ? void 0 : _this$db.tokenRates) && this.#db.tokenRates[this.tokenId]);
|
504
|
+
};
|
500
505
|
|
501
506
|
//
|
502
507
|
// Accessors
|
@@ -526,27 +531,32 @@ let Balance = (_dec4 = Memoize(), _dec5 = Memoize(), _dec6 = Memoize(), _dec7 =
|
|
526
531
|
return this.#storage.chainId;
|
527
532
|
}
|
528
533
|
get chain() {
|
529
|
-
|
534
|
+
var _this$db2, _this$db3;
|
535
|
+
return ((_this$db2 = this.#db) === null || _this$db2 === void 0 ? void 0 : _this$db2.chains) && this.chainId && ((_this$db3 = this.#db) === null || _this$db3 === void 0 ? void 0 : _this$db3.chains[this.chainId]) || null;
|
530
536
|
}
|
531
537
|
get evmNetworkId() {
|
532
538
|
return this.#storage.evmNetworkId;
|
533
539
|
}
|
534
540
|
get evmNetwork() {
|
541
|
+
var _this$db4, _this$db5;
|
535
542
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
536
|
-
return this.#db
|
543
|
+
return ((_this$db4 = this.#db) === null || _this$db4 === void 0 ? void 0 : _this$db4.evmNetworks) && ((_this$db5 = this.#db) === null || _this$db5 === void 0 ? void 0 : _this$db5.evmNetworks[this.evmNetworkId]) || null;
|
537
544
|
}
|
538
545
|
get tokenId() {
|
539
546
|
return this.#storage.tokenId;
|
540
547
|
}
|
541
548
|
get token() {
|
549
|
+
var _this$db6, _this$db7;
|
542
550
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
543
|
-
return this.#db
|
551
|
+
return ((_this$db6 = this.#db) === null || _this$db6 === void 0 ? void 0 : _this$db6.tokens) && ((_this$db7 = this.#db) === null || _this$db7 === void 0 ? void 0 : _this$db7.tokens[this.tokenId]) || null;
|
544
552
|
}
|
545
553
|
get decimals() {
|
546
|
-
|
554
|
+
var _this$token;
|
555
|
+
return ((_this$token = this.token) === null || _this$token === void 0 ? void 0 : _this$token.decimals) || null;
|
547
556
|
}
|
548
557
|
get rates() {
|
549
|
-
|
558
|
+
var _this$db8;
|
559
|
+
return ((_this$db8 = this.#db) === null || _this$db8 === void 0 ? void 0 : _this$db8.tokenRates) && this.#db.tokenRates[this.tokenId] || null;
|
550
560
|
}
|
551
561
|
|
552
562
|
/**
|
@@ -560,15 +570,18 @@ let Balance = (_dec4 = Memoize(), _dec5 = Memoize(), _dec6 = Memoize(), _dec7 =
|
|
560
570
|
}
|
561
571
|
/** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
|
562
572
|
get free() {
|
563
|
-
|
573
|
+
var _this$storage$free;
|
574
|
+
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, BigInt("0")) : BigInt(((_this$storage$free = this.#storage.free) === null || _this$storage$free === void 0 ? void 0 : _this$storage$free.amount) || "0"));
|
564
575
|
}
|
565
576
|
/** The reserved balance of this token. Is included in the total. */
|
566
577
|
get reserved() {
|
567
|
-
|
578
|
+
var _this$storage$reserve;
|
579
|
+
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, BigInt("0")) : BigInt(((_this$storage$reserve = this.#storage.reserves) === null || _this$storage$reserve === void 0 ? void 0 : _this$storage$reserve.amount) || "0"));
|
568
580
|
}
|
569
581
|
/** The frozen balance of this token. Is included in the free amount. */
|
570
582
|
get locked() {
|
571
|
-
|
583
|
+
var _this$storage$locks;
|
584
|
+
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), BigInt("0")) : BigInt(((_this$storage$locks = this.#storage.locks) === null || _this$storage$locks === void 0 ? void 0 : _this$storage$locks.amount) || "0"));
|
572
585
|
}
|
573
586
|
/** @depreacted - use balance.locked */
|
574
587
|
get frozen() {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/balances",
|
3
|
-
"version": "0.0.0-
|
3
|
+
"version": "0.0.0-pr573-20230227134247",
|
4
4
|
"author": "Talisman",
|
5
5
|
"homepage": "https://talisman.xyz",
|
6
6
|
"license": "UNLICENSED",
|
@@ -27,13 +27,13 @@
|
|
27
27
|
"clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
|
28
28
|
},
|
29
29
|
"dependencies": {
|
30
|
-
"@talismn/chain-connector": "^0.
|
31
|
-
"@talismn/chain-connector-evm": "^0.
|
32
|
-
"@talismn/chaindata-provider": "^0.
|
33
|
-
"@talismn/token-rates": "^0.
|
30
|
+
"@talismn/chain-connector": "^0.0.0-pr573-20230227134247",
|
31
|
+
"@talismn/chain-connector-evm": "^0.0.0-pr573-20230227134247",
|
32
|
+
"@talismn/chaindata-provider": "^0.0.0-pr573-20230227134247",
|
33
|
+
"@talismn/token-rates": "^0.0.0-pr573-20230227134247",
|
34
34
|
"@talismn/util": "^0.1.7",
|
35
35
|
"anylogger": "^1.0.11",
|
36
|
-
"dexie": "^3.2.
|
36
|
+
"dexie": "^3.2.3",
|
37
37
|
"lodash": "^4.17.21",
|
38
38
|
"typescript-memoize": "^1.1.0"
|
39
39
|
},
|