@talismn/balances 0.0.0-pr974-20230915020916 → 0.0.0-pr974-20231123032136
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 +16 -5
- package/dist/declarations/src/BalanceModule.d.ts +0 -4
- package/dist/declarations/src/helpers.d.ts +11 -0
- package/dist/declarations/src/types/balances.d.ts +6 -0
- package/dist/talismn-balances.cjs.dev.js +26 -5
- package/dist/talismn-balances.cjs.prod.js +26 -5
- package/dist/talismn-balances.esm.js +28 -8
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
@@ -1,20 +1,31 @@
|
|
1
1
|
# @talismn/balances
|
2
2
|
|
3
|
-
## 0.0.0-pr974-
|
3
|
+
## 0.0.0-pr974-20231123032136
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
7
7
|
- d2ccdafb: fix: balance subscriptions never update registry cache with new metadata
|
8
|
+
- c4d59671: bump typescript version
|
8
9
|
- a916db00: docs: added @talismn/balances readme
|
9
10
|
- a3a1bd7c: feat: psp22 balances module
|
11
|
+
- c681c8bb: Use Balances::transfer_allow_death as default method for substrate balance transfers
|
12
|
+
- Updated dependencies [123647e3]
|
10
13
|
- Updated dependencies [03939d5f]
|
14
|
+
- Updated dependencies [123647e3]
|
15
|
+
- Updated dependencies [e0eb84ad]
|
16
|
+
- Updated dependencies [372f9951]
|
17
|
+
- Updated dependencies [c4d59671]
|
18
|
+
- Updated dependencies [e0eb84ad]
|
11
19
|
- Updated dependencies [850381a5]
|
20
|
+
- Updated dependencies [5aadf998]
|
12
21
|
- Updated dependencies [4cace80d]
|
22
|
+
- Updated dependencies [372f9951]
|
13
23
|
- Updated dependencies [9ebcd938]
|
14
|
-
- @talismn/
|
15
|
-
- @talismn/
|
16
|
-
- @talismn/chain-connector@0.0.0-pr974-
|
17
|
-
- @talismn/
|
24
|
+
- @talismn/token-rates@0.0.0-pr974-20231123032136
|
25
|
+
- @talismn/chaindata-provider@0.0.0-pr974-20231123032136
|
26
|
+
- @talismn/chain-connector@0.0.0-pr974-20231123032136
|
27
|
+
- @talismn/chain-connector-evm@0.0.0-pr974-20231123032136
|
28
|
+
- @talismn/util@0.0.0-pr974-20231123032136
|
18
29
|
|
19
30
|
## 0.6.0
|
20
31
|
|
@@ -2,7 +2,6 @@ import { UnsignedTransaction } from "@substrate/txwrapper-core";
|
|
2
2
|
import { ChainConnector } from "@talismn/chain-connector";
|
3
3
|
import { ChainConnectorEvm } from "@talismn/chain-connector-evm";
|
4
4
|
import { ChainId, ChaindataProvider, IToken } from "@talismn/chaindata-provider";
|
5
|
-
import { ethers } from "ethers";
|
6
5
|
import { AddressesByToken, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
|
7
6
|
export type ExtendableTokenType = IToken;
|
8
7
|
export type ExtendableChainMeta = Record<string, unknown> | undefined;
|
@@ -21,9 +20,6 @@ export type NewTransferParamsType<T extends Record<string, unknown>> = BaseTrans
|
|
21
20
|
export type TransferTokenTx = {
|
22
21
|
type: "substrate";
|
23
22
|
tx: UnsignedTransaction;
|
24
|
-
} | {
|
25
|
-
type: "evm";
|
26
|
-
tx: ethers.providers.TransactionRequest;
|
27
23
|
};
|
28
24
|
export type ChainConnectors = {
|
29
25
|
substrate?: ChainConnector;
|
@@ -83,4 +83,15 @@ export declare class RpcStateQueryHelper<T> {
|
|
83
83
|
subscribe(callback: SubscriptionCallback<T[]>, timeout?: number | false, subscribeMethod?: string, responseMethod?: string, unsubscribeMethod?: string): Promise<UnsubscribeFn>;
|
84
84
|
fetch(method?: string): Promise<T[]>;
|
85
85
|
}
|
86
|
+
/**
|
87
|
+
*
|
88
|
+
* Detect Balances::transfer -> Balances::transfer_allow_death migration
|
89
|
+
* https://github.com/paritytech/substrate/pull/12951
|
90
|
+
*
|
91
|
+
* `transfer_allow_death` is the preferred method,
|
92
|
+
* so if something goes wrong during detection, we should assume the chain has migrated
|
93
|
+
* @param metadataRpc string containing the hashed RPC metadata for the chain
|
94
|
+
* @returns
|
95
|
+
*/
|
96
|
+
export declare const detectTransferMethod: (metadataRpc: `0x${string}`) => "transfer" | "transferAllowDeath";
|
86
97
|
export {};
|
@@ -149,6 +149,9 @@ export declare class Balance {
|
|
149
149
|
get reserved(): BalanceFormatter;
|
150
150
|
get reserves(): {
|
151
151
|
amount: BalanceFormatter;
|
152
|
+
/**
|
153
|
+
* Filters this collection to only include balances which are not zero.
|
154
|
+
*/
|
152
155
|
label: string;
|
153
156
|
meta?: unknown;
|
154
157
|
}[];
|
@@ -156,6 +159,9 @@ export declare class Balance {
|
|
156
159
|
get locked(): BalanceFormatter;
|
157
160
|
get locks(): {
|
158
161
|
amount: BalanceFormatter;
|
162
|
+
/**
|
163
|
+
* Filters this collection to only include balances which are not zero.
|
164
|
+
*/
|
159
165
|
label: string;
|
160
166
|
meta?: unknown;
|
161
167
|
includeInTransferable?: boolean | undefined;
|
@@ -69,7 +69,7 @@ const db = new TalismanBalancesDatabase();
|
|
69
69
|
|
70
70
|
var packageJson = {
|
71
71
|
name: "@talismn/balances",
|
72
|
-
version: "0.0.0-pr974-
|
72
|
+
version: "0.0.0-pr974-20231123032136",
|
73
73
|
author: "Talisman",
|
74
74
|
homepage: "https://talisman.xyz",
|
75
75
|
license: "GPL-3.0-or-later",
|
@@ -111,10 +111,10 @@ var packageJson = {
|
|
111
111
|
"@talismn/tsconfig": "workspace:*",
|
112
112
|
"@types/jest": "^27.5.1",
|
113
113
|
"@types/lodash": "^4.14.180",
|
114
|
-
eslint: "^8.
|
114
|
+
eslint: "^8.52.0",
|
115
115
|
jest: "^28.1.0",
|
116
116
|
"ts-jest": "^28.0.2",
|
117
|
-
typescript: "^
|
117
|
+
typescript: "^5.2.2"
|
118
118
|
},
|
119
119
|
peerDependencies: {
|
120
120
|
"@polkadot/types": "10.x"
|
@@ -399,6 +399,26 @@ class RpcStateQueryHelper {
|
|
399
399
|
}
|
400
400
|
}
|
401
401
|
|
402
|
+
/**
|
403
|
+
*
|
404
|
+
* Detect Balances::transfer -> Balances::transfer_allow_death migration
|
405
|
+
* https://github.com/paritytech/substrate/pull/12951
|
406
|
+
*
|
407
|
+
* `transfer_allow_death` is the preferred method,
|
408
|
+
* so if something goes wrong during detection, we should assume the chain has migrated
|
409
|
+
* @param metadataRpc string containing the hashed RPC metadata for the chain
|
410
|
+
* @returns
|
411
|
+
*/
|
412
|
+
const detectTransferMethod = metadataRpc => {
|
413
|
+
const pjsMetadata = new types.Metadata(new types.TypeRegistry(), metadataRpc);
|
414
|
+
pjsMetadata.registry.setMetadata(pjsMetadata);
|
415
|
+
const balancesPallet = pjsMetadata.asLatest.pallets.find(pallet => pallet.name.eq("Balances"));
|
416
|
+
const balancesCallsTypeIndex = balancesPallet?.calls.value.type.toNumber();
|
417
|
+
const balancesCallsType = balancesCallsTypeIndex !== undefined ? pjsMetadata.asLatest.lookup.types[balancesCallsTypeIndex] : undefined;
|
418
|
+
const hasDeprecatedTransferCall = balancesCallsType?.type.def.asVariant?.variants.find(variant => variant.name.eq("transfer")) !== undefined;
|
419
|
+
return hasDeprecatedTransferCall ? "transfer" : "transferAllowDeath";
|
420
|
+
};
|
421
|
+
|
402
422
|
/**
|
403
423
|
* `BalanceTypes` is an automatically determined sub-selection of `PluginBalanceTypes`.
|
404
424
|
*
|
@@ -690,7 +710,7 @@ class Balance {
|
|
690
710
|
hydrate = hydrate => {
|
691
711
|
if (hydrate !== undefined) this.#db = hydrate;
|
692
712
|
};
|
693
|
-
#format = balance => new BalanceFormatter(
|
713
|
+
#format = balance => new BalanceFormatter(util.isBigInt(balance) ? balance.toString() : balance, this.decimals || undefined, this.#db?.tokenRates && this.#db.tokenRates[this.tokenId]);
|
694
714
|
|
695
715
|
//
|
696
716
|
// Accessors
|
@@ -823,7 +843,7 @@ class BalanceFormatter {
|
|
823
843
|
#decimals;
|
824
844
|
#fiatRatios;
|
825
845
|
constructor(planck, decimals, fiatRatios) {
|
826
|
-
this.#planck =
|
846
|
+
this.#planck = util.isBigInt(planck) ? planck.toString() : planck ?? "0";
|
827
847
|
this.#decimals = decimals || 0;
|
828
848
|
this.#fiatRatios = fiatRatios || null;
|
829
849
|
}
|
@@ -965,6 +985,7 @@ exports.createTypeRegistryCache = createTypeRegistryCache;
|
|
965
985
|
exports.db = db;
|
966
986
|
exports.deleteSubscriptionId = deleteSubscriptionId;
|
967
987
|
exports.deriveStatuses = deriveStatuses;
|
988
|
+
exports.detectTransferMethod = detectTransferMethod;
|
968
989
|
exports.excludeFromFeePayableLocks = excludeFromFeePayableLocks;
|
969
990
|
exports.excludeFromTransferableAmount = excludeFromTransferableAmount;
|
970
991
|
exports.filterMirrorTokens = filterMirrorTokens;
|
@@ -69,7 +69,7 @@ const db = new TalismanBalancesDatabase();
|
|
69
69
|
|
70
70
|
var packageJson = {
|
71
71
|
name: "@talismn/balances",
|
72
|
-
version: "0.0.0-pr974-
|
72
|
+
version: "0.0.0-pr974-20231123032136",
|
73
73
|
author: "Talisman",
|
74
74
|
homepage: "https://talisman.xyz",
|
75
75
|
license: "GPL-3.0-or-later",
|
@@ -111,10 +111,10 @@ var packageJson = {
|
|
111
111
|
"@talismn/tsconfig": "workspace:*",
|
112
112
|
"@types/jest": "^27.5.1",
|
113
113
|
"@types/lodash": "^4.14.180",
|
114
|
-
eslint: "^8.
|
114
|
+
eslint: "^8.52.0",
|
115
115
|
jest: "^28.1.0",
|
116
116
|
"ts-jest": "^28.0.2",
|
117
|
-
typescript: "^
|
117
|
+
typescript: "^5.2.2"
|
118
118
|
},
|
119
119
|
peerDependencies: {
|
120
120
|
"@polkadot/types": "10.x"
|
@@ -399,6 +399,26 @@ class RpcStateQueryHelper {
|
|
399
399
|
}
|
400
400
|
}
|
401
401
|
|
402
|
+
/**
|
403
|
+
*
|
404
|
+
* Detect Balances::transfer -> Balances::transfer_allow_death migration
|
405
|
+
* https://github.com/paritytech/substrate/pull/12951
|
406
|
+
*
|
407
|
+
* `transfer_allow_death` is the preferred method,
|
408
|
+
* so if something goes wrong during detection, we should assume the chain has migrated
|
409
|
+
* @param metadataRpc string containing the hashed RPC metadata for the chain
|
410
|
+
* @returns
|
411
|
+
*/
|
412
|
+
const detectTransferMethod = metadataRpc => {
|
413
|
+
const pjsMetadata = new types.Metadata(new types.TypeRegistry(), metadataRpc);
|
414
|
+
pjsMetadata.registry.setMetadata(pjsMetadata);
|
415
|
+
const balancesPallet = pjsMetadata.asLatest.pallets.find(pallet => pallet.name.eq("Balances"));
|
416
|
+
const balancesCallsTypeIndex = balancesPallet?.calls.value.type.toNumber();
|
417
|
+
const balancesCallsType = balancesCallsTypeIndex !== undefined ? pjsMetadata.asLatest.lookup.types[balancesCallsTypeIndex] : undefined;
|
418
|
+
const hasDeprecatedTransferCall = balancesCallsType?.type.def.asVariant?.variants.find(variant => variant.name.eq("transfer")) !== undefined;
|
419
|
+
return hasDeprecatedTransferCall ? "transfer" : "transferAllowDeath";
|
420
|
+
};
|
421
|
+
|
402
422
|
/**
|
403
423
|
* `BalanceTypes` is an automatically determined sub-selection of `PluginBalanceTypes`.
|
404
424
|
*
|
@@ -690,7 +710,7 @@ class Balance {
|
|
690
710
|
hydrate = hydrate => {
|
691
711
|
if (hydrate !== undefined) this.#db = hydrate;
|
692
712
|
};
|
693
|
-
#format = balance => new BalanceFormatter(
|
713
|
+
#format = balance => new BalanceFormatter(util.isBigInt(balance) ? balance.toString() : balance, this.decimals || undefined, this.#db?.tokenRates && this.#db.tokenRates[this.tokenId]);
|
694
714
|
|
695
715
|
//
|
696
716
|
// Accessors
|
@@ -823,7 +843,7 @@ class BalanceFormatter {
|
|
823
843
|
#decimals;
|
824
844
|
#fiatRatios;
|
825
845
|
constructor(planck, decimals, fiatRatios) {
|
826
|
-
this.#planck =
|
846
|
+
this.#planck = util.isBigInt(planck) ? planck.toString() : planck ?? "0";
|
827
847
|
this.#decimals = decimals || 0;
|
828
848
|
this.#fiatRatios = fiatRatios || null;
|
829
849
|
}
|
@@ -965,6 +985,7 @@ exports.createTypeRegistryCache = createTypeRegistryCache;
|
|
965
985
|
exports.db = db;
|
966
986
|
exports.deleteSubscriptionId = deleteSubscriptionId;
|
967
987
|
exports.deriveStatuses = deriveStatuses;
|
988
|
+
exports.detectTransferMethod = detectTransferMethod;
|
968
989
|
exports.excludeFromFeePayableLocks = excludeFromFeePayableLocks;
|
969
990
|
exports.excludeFromTransferableAmount = excludeFromTransferableAmount;
|
970
991
|
exports.filterMirrorTokens = filterMirrorTokens;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Dexie } from 'dexie';
|
2
|
-
import { decorateStorage, StorageKey,
|
3
|
-
import { hasOwnProperty, BigMath, isArrayOf, planckToTokens } from '@talismn/util';
|
2
|
+
import { decorateStorage, StorageKey, Metadata, TypeRegistry } from '@polkadot/types';
|
3
|
+
import { hasOwnProperty, BigMath, isArrayOf, isBigInt, planckToTokens } from '@talismn/util';
|
4
4
|
import groupBy from 'lodash/groupBy';
|
5
5
|
import anylogger from 'anylogger';
|
6
6
|
|
@@ -60,7 +60,7 @@ const db = new TalismanBalancesDatabase();
|
|
60
60
|
|
61
61
|
var packageJson = {
|
62
62
|
name: "@talismn/balances",
|
63
|
-
version: "0.0.0-pr974-
|
63
|
+
version: "0.0.0-pr974-20231123032136",
|
64
64
|
author: "Talisman",
|
65
65
|
homepage: "https://talisman.xyz",
|
66
66
|
license: "GPL-3.0-or-later",
|
@@ -102,10 +102,10 @@ var packageJson = {
|
|
102
102
|
"@talismn/tsconfig": "workspace:*",
|
103
103
|
"@types/jest": "^27.5.1",
|
104
104
|
"@types/lodash": "^4.14.180",
|
105
|
-
eslint: "^8.
|
105
|
+
eslint: "^8.52.0",
|
106
106
|
jest: "^28.1.0",
|
107
107
|
"ts-jest": "^28.0.2",
|
108
|
-
typescript: "^
|
108
|
+
typescript: "^5.2.2"
|
109
109
|
},
|
110
110
|
peerDependencies: {
|
111
111
|
"@polkadot/types": "10.x"
|
@@ -390,6 +390,26 @@ class RpcStateQueryHelper {
|
|
390
390
|
}
|
391
391
|
}
|
392
392
|
|
393
|
+
/**
|
394
|
+
*
|
395
|
+
* Detect Balances::transfer -> Balances::transfer_allow_death migration
|
396
|
+
* https://github.com/paritytech/substrate/pull/12951
|
397
|
+
*
|
398
|
+
* `transfer_allow_death` is the preferred method,
|
399
|
+
* so if something goes wrong during detection, we should assume the chain has migrated
|
400
|
+
* @param metadataRpc string containing the hashed RPC metadata for the chain
|
401
|
+
* @returns
|
402
|
+
*/
|
403
|
+
const detectTransferMethod = metadataRpc => {
|
404
|
+
const pjsMetadata = new Metadata(new TypeRegistry(), metadataRpc);
|
405
|
+
pjsMetadata.registry.setMetadata(pjsMetadata);
|
406
|
+
const balancesPallet = pjsMetadata.asLatest.pallets.find(pallet => pallet.name.eq("Balances"));
|
407
|
+
const balancesCallsTypeIndex = balancesPallet?.calls.value.type.toNumber();
|
408
|
+
const balancesCallsType = balancesCallsTypeIndex !== undefined ? pjsMetadata.asLatest.lookup.types[balancesCallsTypeIndex] : undefined;
|
409
|
+
const hasDeprecatedTransferCall = balancesCallsType?.type.def.asVariant?.variants.find(variant => variant.name.eq("transfer")) !== undefined;
|
410
|
+
return hasDeprecatedTransferCall ? "transfer" : "transferAllowDeath";
|
411
|
+
};
|
412
|
+
|
393
413
|
/**
|
394
414
|
* `BalanceTypes` is an automatically determined sub-selection of `PluginBalanceTypes`.
|
395
415
|
*
|
@@ -681,7 +701,7 @@ class Balance {
|
|
681
701
|
hydrate = hydrate => {
|
682
702
|
if (hydrate !== undefined) this.#db = hydrate;
|
683
703
|
};
|
684
|
-
#format = balance => new BalanceFormatter(
|
704
|
+
#format = balance => new BalanceFormatter(isBigInt(balance) ? balance.toString() : balance, this.decimals || undefined, this.#db?.tokenRates && this.#db.tokenRates[this.tokenId]);
|
685
705
|
|
686
706
|
//
|
687
707
|
// Accessors
|
@@ -814,7 +834,7 @@ class BalanceFormatter {
|
|
814
834
|
#decimals;
|
815
835
|
#fiatRatios;
|
816
836
|
constructor(planck, decimals, fiatRatios) {
|
817
|
-
this.#planck =
|
837
|
+
this.#planck = isBigInt(planck) ? planck.toString() : planck ?? "0";
|
818
838
|
this.#decimals = decimals || 0;
|
819
839
|
this.#fiatRatios = fiatRatios || null;
|
820
840
|
}
|
@@ -939,4 +959,4 @@ class SumBalancesFormatter {
|
|
939
959
|
}
|
940
960
|
}
|
941
961
|
|
942
|
-
export { Balance, BalanceFormatter, BalanceStatusLive, Balances, DefaultBalanceModule, FiatSumBalancesFormatter, PlanckSumBalancesFormatter, RpcStateQueryHelper, StorageHelper, SumBalancesFormatter, TalismanBalancesDatabase, balances, createSubscriptionId, createTypeRegistryCache, db, deleteSubscriptionId, deriveStatuses, excludeFromFeePayableLocks, excludeFromTransferableAmount, filterMirrorTokens, findChainMeta, getValidSubscriptionIds, includeInTotalExtraAmount };
|
962
|
+
export { Balance, BalanceFormatter, BalanceStatusLive, Balances, DefaultBalanceModule, FiatSumBalancesFormatter, PlanckSumBalancesFormatter, RpcStateQueryHelper, StorageHelper, SumBalancesFormatter, TalismanBalancesDatabase, balances, createSubscriptionId, createTypeRegistryCache, db, deleteSubscriptionId, deriveStatuses, detectTransferMethod, excludeFromFeePayableLocks, excludeFromTransferableAmount, filterMirrorTokens, findChainMeta, getValidSubscriptionIds, includeInTotalExtraAmount };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@talismn/balances",
|
3
|
-
"version": "0.0.0-pr974-
|
3
|
+
"version": "0.0.0-pr974-20231123032136",
|
4
4
|
"author": "Talisman",
|
5
5
|
"homepage": "https://talisman.xyz",
|
6
6
|
"license": "GPL-3.0-or-later",
|
@@ -27,25 +27,25 @@
|
|
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-pr974-
|
31
|
-
"@talismn/chain-connector-evm": "0.0.0-pr974-
|
32
|
-
"@talismn/chaindata-provider": "0.0.0-pr974-
|
33
|
-
"@talismn/token-rates": "0.0.0-pr974-
|
34
|
-
"@talismn/util": "0.
|
30
|
+
"@talismn/chain-connector": "0.0.0-pr974-20231123032136",
|
31
|
+
"@talismn/chain-connector-evm": "0.0.0-pr974-20231123032136",
|
32
|
+
"@talismn/chaindata-provider": "0.0.0-pr974-20231123032136",
|
33
|
+
"@talismn/token-rates": "0.0.0-pr974-20231123032136",
|
34
|
+
"@talismn/util": "0.0.0-pr974-20231123032136",
|
35
35
|
"anylogger": "^1.0.11",
|
36
36
|
"dexie": "^3.2.4",
|
37
37
|
"lodash": "4.17.21"
|
38
38
|
},
|
39
39
|
"devDependencies": {
|
40
40
|
"@polkadot/types": "^10.1.4",
|
41
|
-
"@talismn/eslint-config": "0.0.
|
41
|
+
"@talismn/eslint-config": "0.0.0-pr974-20231123032136",
|
42
42
|
"@talismn/tsconfig": "0.0.2",
|
43
43
|
"@types/jest": "^27.5.1",
|
44
44
|
"@types/lodash": "^4.14.180",
|
45
|
-
"eslint": "^8.
|
45
|
+
"eslint": "^8.52.0",
|
46
46
|
"jest": "^28.1.0",
|
47
47
|
"ts-jest": "^28.0.2",
|
48
|
-
"typescript": "^
|
48
|
+
"typescript": "^5.2.2"
|
49
49
|
},
|
50
50
|
"peerDependencies": {
|
51
51
|
"@polkadot/types": "10.x"
|