@subwallet/extension-base 1.2.24-0 → 1.2.24-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/cjs/core/substrate/assets-pallet.js +35 -0
- package/cjs/core/substrate/foreign-asset-pallet.js +13 -3
- package/cjs/core/substrate/nominationpools-pallet.js +4 -6
- package/cjs/core/substrate/ormlTokens-pallet.js +24 -0
- package/cjs/core/substrate/system-pallet.js +18 -18
- package/cjs/core/substrate/tokens-pallet.js +24 -0
- package/cjs/core/substrate/types.js +19 -0
- package/cjs/core/substrate/xcm-parser.js +16 -2
- package/cjs/core/utils.js +25 -0
- package/cjs/koni/background/handlers/Extension.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +2 -2
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +120 -133
- package/cjs/services/balance-service/transfer/xcm/index.js +2 -1
- package/cjs/services/balance-service/transfer/xcm/polkadotXcm.js +1 -1
- package/cjs/services/balance-service/transfer/xcm/utils.js +3 -2
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/chain-service/handler/SubstrateApi.js +128 -34
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +26 -9
- package/cjs/services/chain-service/utils/index.js +5 -0
- package/core/substrate/assets-pallet.d.ts +4 -0
- package/core/substrate/assets-pallet.js +28 -0
- package/core/substrate/foreign-asset-pallet.d.ts +4 -8
- package/core/substrate/foreign-asset-pallet.js +13 -3
- package/core/substrate/nominationpools-pallet.d.ts +4 -10
- package/core/substrate/nominationpools-pallet.js +4 -5
- package/core/substrate/ormlTokens-pallet.d.ts +4 -0
- package/core/substrate/ormlTokens-pallet.js +17 -0
- package/core/substrate/system-pallet.d.ts +4 -24
- package/core/substrate/system-pallet.js +18 -21
- package/core/substrate/tokens-pallet.d.ts +5 -0
- package/core/substrate/tokens-pallet.js +16 -0
- package/core/substrate/types.d.ts +43 -0
- package/core/substrate/types.js +12 -0
- package/core/substrate/xcm-parser.d.ts +1 -0
- package/core/substrate/xcm-parser.js +15 -2
- package/core/utils.d.ts +4 -0
- package/core/utils.js +17 -0
- package/koni/api/staking/bonding/relayChain.d.ts +1 -1
- package/koni/background/handlers/Extension.js +1 -1
- package/koni/background/handlers/State.d.ts +2 -2
- package/package.json +31 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +2 -2
- package/services/balance-service/helpers/subscribe/substrate/index.js +109 -121
- package/services/balance-service/transfer/xcm/index.d.ts +1 -1
- package/services/balance-service/transfer/xcm/index.js +2 -1
- package/services/balance-service/transfer/xcm/polkadotXcm.js +1 -1
- package/services/balance-service/transfer/xcm/utils.d.ts +1 -1
- package/services/balance-service/transfer/xcm/utils.js +3 -2
- package/services/chain-service/constants.js +1 -1
- package/services/chain-service/handler/SubstrateApi.d.ts +5 -7
- package/services/chain-service/handler/SubstrateApi.js +128 -35
- package/services/chain-service/handler/SubstrateChainHandler.d.ts +5 -6
- package/services/chain-service/handler/SubstrateChainHandler.js +26 -9
- package/services/chain-service/index.d.ts +3 -3
- package/services/chain-service/types.d.ts +22 -5
- package/services/chain-service/utils/index.d.ts +1 -0
- package/services/chain-service/utils/index.js +3 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -1
- package/types/balance/index.d.ts +2 -3
|
@@ -10,7 +10,6 @@ var _api2 = require("@gear-js/api");
|
|
|
10
10
|
var _types = require("@oak-foundation/types");
|
|
11
11
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
12
12
|
var _lightClient = require("@subwallet/extension-base/services/chain-service/handler/light-client");
|
|
13
|
-
var _SubstrateChainHandler = require("@subwallet/extension-base/services/chain-service/handler/SubstrateChainHandler");
|
|
14
13
|
var _types2 = require("@subwallet/extension-base/services/chain-service/types");
|
|
15
14
|
var _promise = require("@subwallet/extension-base/utils/promise");
|
|
16
15
|
var _availJsSdk = require("avail-js-sdk");
|
|
@@ -18,8 +17,6 @@ var _rxjs = require("rxjs");
|
|
|
18
17
|
var _api3 = require("@polkadot/api");
|
|
19
18
|
var _api4 = require("@polkadot/apps-config/api");
|
|
20
19
|
var _create = require("@polkadot/types/create");
|
|
21
|
-
var _util = require("@polkadot/util");
|
|
22
|
-
var _defaults = require("@polkadot/util-crypto/address/defaults");
|
|
23
20
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
24
21
|
// SPDX-License-Identifier: Apache-2.0
|
|
25
22
|
|
|
@@ -62,6 +59,11 @@ class SubstrateApi {
|
|
|
62
59
|
this.connectionStatusSubject.next(status);
|
|
63
60
|
}
|
|
64
61
|
}
|
|
62
|
+
|
|
63
|
+
// apiDefaultTx?: SubmittableExtrinsicFunction;
|
|
64
|
+
// apiDefaultTxSudo?: SubmittableExtrinsicFunction;
|
|
65
|
+
// defaultFormatBalance?: _SubstrateDefaultFormatBalance;
|
|
66
|
+
|
|
65
67
|
specName = '';
|
|
66
68
|
specVersion = '';
|
|
67
69
|
systemChain = '';
|
|
@@ -231,44 +233,136 @@ class SubstrateApi {
|
|
|
231
233
|
console.warn(`${this.chainSlug} connection got error`, e);
|
|
232
234
|
}
|
|
233
235
|
async fillApiInfo() {
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
} = this;
|
|
239
|
-
const DEFAULT_DECIMALS = registry.createType('u32', 12);
|
|
240
|
-
const DEFAULT_SS58 = registry.createType('u32', _defaults.defaults.prefix);
|
|
236
|
+
// const { registry } = this;
|
|
237
|
+
// const DEFAULT_DECIMALS = registry.createType('u32', 12);
|
|
238
|
+
// const DEFAULT_SS58 = registry.createType('u32', addressDefaults.prefix);
|
|
239
|
+
|
|
241
240
|
this.specName = this.api.runtimeVersion.specName.toString();
|
|
242
241
|
this.specVersion = this.api.runtimeVersion.specVersion.toString();
|
|
243
|
-
const [systemChain, systemName, systemVersion] = await Promise.all([
|
|
242
|
+
const [systemChain, systemName, systemVersion] = await Promise.all([this.makeRpcQuery({
|
|
243
|
+
section: 'rpc',
|
|
244
|
+
module: 'system',
|
|
245
|
+
method: 'chain'
|
|
246
|
+
}), this.makeRpcQuery({
|
|
247
|
+
section: 'rpc',
|
|
248
|
+
module: 'system',
|
|
249
|
+
method: 'name'
|
|
250
|
+
}), this.makeRpcQuery({
|
|
251
|
+
section: 'rpc',
|
|
252
|
+
module: 'system',
|
|
253
|
+
method: 'version'
|
|
254
|
+
})]);
|
|
244
255
|
this.systemChain = systemChain.toString();
|
|
245
256
|
this.systemName = systemName.toString();
|
|
246
257
|
this.systemVersion = systemVersion.toString();
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
|
|
259
|
+
// const [ss58Format, tokenDecimals, tokenSymbol] = await Promise.all([
|
|
260
|
+
// this.makeRpcQuery<number | undefined>({ section: 'registry', module: 'chainSS58' }),
|
|
261
|
+
// this.makeRpcQuery<number[]>({ section: 'registry', module: 'chainDecimals' }),
|
|
262
|
+
// this.makeRpcQuery<string[]>({ section: 'registry', module: 'chainTokens' })
|
|
263
|
+
// ]);
|
|
264
|
+
//
|
|
265
|
+
// const properties = registry.createType('ChainProperties', {
|
|
266
|
+
// ss58Format,
|
|
267
|
+
// tokenDecimals,
|
|
268
|
+
// tokenSymbol
|
|
269
|
+
// });
|
|
270
|
+
// const ss58Format = properties.ss58Format.unwrapOr(DEFAULT_SS58).toNumber();
|
|
271
|
+
// const tokenSymbol = properties.tokenSymbol.unwrapOr([formatBalance.getDefaults().unit, ...DEFAULT_AUX]);
|
|
272
|
+
// const tokenDecimals = properties.tokenDecimals.unwrapOr([DEFAULT_DECIMALS]);
|
|
273
|
+
//
|
|
274
|
+
// registry.setChainProperties(registry.createType('ChainProperties', { ss58Format, tokenDecimals, tokenSymbol }));
|
|
260
275
|
|
|
261
276
|
// first set up the UI helpers
|
|
262
|
-
this.defaultFormatBalance = {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
277
|
+
// this.defaultFormatBalance = {
|
|
278
|
+
// decimals: tokenDecimals.map((b: BN) => {
|
|
279
|
+
// return b.toNumber();
|
|
280
|
+
// }),
|
|
281
|
+
// unit: tokenSymbol[0].toString()
|
|
282
|
+
// };
|
|
283
|
+
//
|
|
284
|
+
// const defaultSection = Object.keys(api.tx)[0];
|
|
285
|
+
// const defaultMethod = Object.keys(api.tx[defaultSection])[0];
|
|
286
|
+
|
|
287
|
+
// this.apiDefaultTx = api.tx[defaultSection][defaultMethod];
|
|
288
|
+
// this.apiDefaultTxSudo = (api.tx.system && api.tx.system.setCode) || this.apiDefaultTx;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
async makeRpcQuery(_ref) {
|
|
292
|
+
let {
|
|
293
|
+
args,
|
|
294
|
+
method,
|
|
295
|
+
module,
|
|
296
|
+
section
|
|
297
|
+
} = _ref;
|
|
298
|
+
const isGetterCall = section === 'genesisHash' || section === 'extrinsicVersion' || section === 'runtimeVersion' || section === 'runtimeMetadata' || section === 'registry';
|
|
299
|
+
const isRuntimeConstQuery = section === 'consts' && !!method && !!module && !args;
|
|
300
|
+
const isRpcQuery = section === 'rpc' && !!method && !!module && !args;
|
|
301
|
+
const isStateQuery = section === 'query' && method && module;
|
|
302
|
+
if (isGetterCall) {
|
|
303
|
+
if (section === 'genesisHash') {
|
|
304
|
+
return this.api[section].toHex();
|
|
305
|
+
} else if (section === 'extrinsicVersion') {
|
|
306
|
+
return this.api[section];
|
|
307
|
+
} else if (section === 'runtimeVersion') {
|
|
308
|
+
return this.api[section].toPrimitive();
|
|
309
|
+
} else if (section === 'runtimeMetadata') {
|
|
310
|
+
return this.api[section].toHex();
|
|
311
|
+
} else if (section === 'registry') {
|
|
312
|
+
return this.api[section];
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (isRuntimeConstQuery) {
|
|
316
|
+
if (!this.api[section][module]) {
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
return this.api[section][module][method].toPrimitive();
|
|
320
|
+
}
|
|
321
|
+
if (isRpcQuery) {
|
|
322
|
+
// @ts-ignore
|
|
323
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
324
|
+
if (!this.api[section][module]) {
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// @ts-ignore
|
|
329
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
330
|
+
return (await this.api[section][module][method]()).toPrimitive(); // todo: improve this
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (isStateQuery) {
|
|
334
|
+
if (!this.api[section][module]) {
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
if (args) {
|
|
338
|
+
return (await this.api[section][module][method](...args)).toPrimitive();
|
|
339
|
+
} else {
|
|
340
|
+
return (await this.api[section][module][method]()).toPrimitive();
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return Promise.reject(new Error('Cannot handle query'));
|
|
344
|
+
}
|
|
345
|
+
subscribeDataWithMulti(params, callback) {
|
|
346
|
+
const apiRx = this.api.rx;
|
|
347
|
+
const observables = {};
|
|
348
|
+
params.forEach(queryParams => {
|
|
349
|
+
const {
|
|
350
|
+
args,
|
|
351
|
+
method,
|
|
352
|
+
module,
|
|
353
|
+
section
|
|
354
|
+
} = queryParams;
|
|
355
|
+
const key = `${section}_${module}_${method}`;
|
|
356
|
+
if (!this.api[section][module] || !this.api[section][module][method]) {
|
|
357
|
+
// if method not found, returns an empty observable
|
|
358
|
+
observables[key] = new _rxjs.Observable(subscriber => {
|
|
359
|
+
subscriber.next([]);
|
|
360
|
+
});
|
|
361
|
+
} else {
|
|
362
|
+
observables[key] = apiRx[section][module][method].multi(args).pipe((0, _rxjs.map)(codecs => codecs.map(codec => codec.toPrimitive())));
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
return (0, _rxjs.combineLatest)(observables).subscribe(callback);
|
|
272
366
|
}
|
|
273
367
|
}
|
|
274
368
|
exports.SubstrateApi = SubstrateApi;
|
|
@@ -69,12 +69,13 @@ class SubstrateChainHandler extends _AbstractChainHandler.AbstractChainHandler {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
async getChainSpec(substrateApi) {
|
|
72
|
-
var _substrateApi$api$gen, _substrateApi$api, _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$con3;
|
|
73
72
|
const result = {
|
|
74
73
|
addressPrefix: -1,
|
|
75
74
|
decimals: 0,
|
|
76
75
|
existentialDeposit: '',
|
|
77
|
-
genesisHash:
|
|
76
|
+
genesisHash: await substrateApi.makeRpcQuery({
|
|
77
|
+
section: 'genesisHash'
|
|
78
|
+
}),
|
|
78
79
|
name: '',
|
|
79
80
|
symbol: '',
|
|
80
81
|
paraId: null
|
|
@@ -82,17 +83,33 @@ class SubstrateChainHandler extends _AbstractChainHandler.AbstractChainHandler {
|
|
|
82
83
|
const {
|
|
83
84
|
chainDecimals,
|
|
84
85
|
chainTokens
|
|
85
|
-
} = substrateApi.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
} = await substrateApi.makeRpcQuery({
|
|
87
|
+
section: 'registry'
|
|
88
|
+
});
|
|
89
|
+
result.paraId = await substrateApi.makeRpcQuery({
|
|
90
|
+
section: 'query',
|
|
91
|
+
module: 'parachainInfo',
|
|
92
|
+
method: 'parachainId'
|
|
93
|
+
});
|
|
89
94
|
|
|
90
95
|
// get first token by default, might change
|
|
91
|
-
result.name =
|
|
96
|
+
result.name = await substrateApi.makeRpcQuery({
|
|
97
|
+
section: 'rpc',
|
|
98
|
+
module: 'system',
|
|
99
|
+
method: 'chain'
|
|
100
|
+
});
|
|
92
101
|
result.symbol = chainTokens[0];
|
|
93
102
|
result.decimals = chainDecimals[0];
|
|
94
|
-
result.addressPrefix =
|
|
95
|
-
|
|
103
|
+
result.addressPrefix = await substrateApi.makeRpcQuery({
|
|
104
|
+
section: 'consts',
|
|
105
|
+
module: 'system',
|
|
106
|
+
method: 'ss58Prefix'
|
|
107
|
+
});
|
|
108
|
+
result.existentialDeposit = await substrateApi.makeRpcQuery({
|
|
109
|
+
section: 'consts',
|
|
110
|
+
module: 'balances',
|
|
111
|
+
method: 'existentialDeposit'
|
|
112
|
+
});
|
|
96
113
|
return result;
|
|
97
114
|
}
|
|
98
115
|
async getPsp22TokenInfo(apiPromise, contractAddress, contractCaller) {
|
|
@@ -81,6 +81,7 @@ var _exportNames = {
|
|
|
81
81
|
findChainInfoByChainId: true,
|
|
82
82
|
_isMantaZkAsset: true,
|
|
83
83
|
_getChainExistentialDeposit: true,
|
|
84
|
+
_getAssetExistentialDeposit: true,
|
|
84
85
|
randomizeProvider: true,
|
|
85
86
|
_isAssetCanPayTxFee: true,
|
|
86
87
|
updateLatestChainInfo: true
|
|
@@ -88,6 +89,7 @@ var _exportNames = {
|
|
|
88
89
|
exports._checkSmartContractSupportByChain = _checkSmartContractSupportByChain;
|
|
89
90
|
exports._generateCustomProviderKey = _generateCustomProviderKey;
|
|
90
91
|
exports._getAssetDecimals = _getAssetDecimals;
|
|
92
|
+
exports._getAssetExistentialDeposit = _getAssetExistentialDeposit;
|
|
91
93
|
exports._getAssetName = _getAssetName;
|
|
92
94
|
exports._getAssetOriginChain = _getAssetOriginChain;
|
|
93
95
|
exports._getAssetPriceId = _getAssetPriceId;
|
|
@@ -599,6 +601,9 @@ function _getChainExistentialDeposit(chainInfo) {
|
|
|
599
601
|
var _chainInfo$substrateI20;
|
|
600
602
|
return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI20 = chainInfo.substrateInfo) === null || _chainInfo$substrateI20 === void 0 ? void 0 : _chainInfo$substrateI20.existentialDeposit) || '0';
|
|
601
603
|
}
|
|
604
|
+
function _getAssetExistentialDeposit(chainAsset) {
|
|
605
|
+
return (chainAsset === null || chainAsset === void 0 ? void 0 : chainAsset.minAmount) || '0';
|
|
606
|
+
}
|
|
602
607
|
function randomizeProvider(providers, excludedKeys) {
|
|
603
608
|
if (Object.keys(providers).length === 0) {
|
|
604
609
|
return {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { PalletAssetsAssetAccount } from '@subwallet/extension-base/core/substrate/types';
|
|
3
|
+
export declare function _getAssetsPalletTransferable(accountInfo: PalletAssetsAssetAccount | undefined, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
|
|
4
|
+
export declare function _getAssetsPalletLockedBalance(accountInfo: PalletAssetsAssetAccount | undefined): bigint;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
|
|
5
|
+
import { _getAppliedExistentialDeposit, getStrictMode } from '@subwallet/extension-base/core/utils';
|
|
6
|
+
export function _getAssetsPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
|
|
7
|
+
const strictMode = getStrictMode(BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
|
|
8
|
+
const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
|
|
9
|
+
let bnTransferable = BigInt(0);
|
|
10
|
+
if (!accountInfo) {
|
|
11
|
+
return BigInt(0);
|
|
12
|
+
}
|
|
13
|
+
if (['Liquid'].includes(accountInfo.status)) {
|
|
14
|
+
bnTransferable = BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
|
|
15
|
+
}
|
|
16
|
+
return bnTransferable;
|
|
17
|
+
}
|
|
18
|
+
export function _getAssetsPalletLockedBalance(accountInfo) {
|
|
19
|
+
let bnLocked = BigInt(0);
|
|
20
|
+
if (!accountInfo) {
|
|
21
|
+
return bnLocked;
|
|
22
|
+
}
|
|
23
|
+
if (!['Liquid'].includes(accountInfo.status)) {
|
|
24
|
+
// todo: check case accountInfo has isFrozen?
|
|
25
|
+
bnLocked = BigInt(accountInfo.balance);
|
|
26
|
+
}
|
|
27
|
+
return bnLocked;
|
|
28
|
+
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
extra: unknown;
|
|
6
|
-
};
|
|
7
|
-
export declare function _getForeignAssetPalletTransferable(accountInfo: PalletAssetsAssetAccount): bigint;
|
|
8
|
-
export declare function _getForeignAssetPalletLockedBalance(accountInfo: PalletAssetsAssetAccount): bigint;
|
|
1
|
+
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { PalletAssetsAssetAccount } from '@subwallet/extension-base/core/substrate/types';
|
|
3
|
+
export declare function _getForeignAssetPalletTransferable(accountInfo: PalletAssetsAssetAccount | undefined, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
|
|
4
|
+
export declare function _getForeignAssetPalletLockedBalance(accountInfo: PalletAssetsAssetAccount | undefined): bigint;
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
|
|
5
|
+
import { _getAppliedExistentialDeposit, getStrictMode } from '@subwallet/extension-base/core/utils';
|
|
6
|
+
export function _getForeignAssetPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
|
|
7
|
+
const strictMode = getStrictMode(BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
|
|
8
|
+
if (!accountInfo || accountInfo.status !== 'Liquid') {
|
|
9
|
+
return BigInt(0);
|
|
10
|
+
}
|
|
11
|
+
const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
|
|
12
|
+
return BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
|
|
6
13
|
}
|
|
7
14
|
export function _getForeignAssetPalletLockedBalance(accountInfo) {
|
|
8
|
-
|
|
15
|
+
if (!accountInfo || accountInfo.status === 'Liquid') {
|
|
16
|
+
return BigInt(0);
|
|
17
|
+
}
|
|
18
|
+
return BigInt(accountInfo.balance);
|
|
9
19
|
}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
lastRecordedRewardCounter: number;
|
|
6
|
-
unbondingEras: Record<string, number>;
|
|
7
|
-
};
|
|
8
|
-
export declare function _getActiveStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): BigN;
|
|
9
|
-
export declare function _getUnbondingStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): BigN;
|
|
10
|
-
export declare function _getTotalStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): BigN;
|
|
1
|
+
import { PalletNominationPoolsPoolMember } from '@subwallet/extension-base/core/substrate/types';
|
|
2
|
+
export declare function _getActiveStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): bigint;
|
|
3
|
+
export declare function _getUnbondingStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): bigint;
|
|
4
|
+
export declare function _getTotalStakeInNominationPool(memberInfo: PalletNominationPoolsPoolMember): bigint;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import BigN from 'bignumber.js';
|
|
5
4
|
export function _getActiveStakeInNominationPool(memberInfo) {
|
|
6
|
-
return
|
|
5
|
+
return BigInt(memberInfo.points);
|
|
7
6
|
}
|
|
8
7
|
export function _getUnbondingStakeInNominationPool(memberInfo) {
|
|
9
|
-
const unbondingValues = Object.values(memberInfo.unbondingEras).map(unbonding =>
|
|
10
|
-
return
|
|
8
|
+
const unbondingValues = Object.values(memberInfo.unbondingEras).map(unbonding => BigInt(unbonding));
|
|
9
|
+
return unbondingValues.reduce((a, b) => a + b, BigInt(0));
|
|
11
10
|
}
|
|
12
11
|
export function _getTotalStakeInNominationPool(memberInfo) {
|
|
13
|
-
return _getActiveStakeInNominationPool(memberInfo)
|
|
12
|
+
return _getActiveStakeInNominationPool(memberInfo) + _getUnbondingStakeInNominationPool(memberInfo);
|
|
14
13
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { OrmlTokensAccountData } from '@subwallet/extension-base/core/substrate/types';
|
|
3
|
+
export declare function _getOrmlTokensPalletTransferable(accountInfo: OrmlTokensAccountData, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
|
|
4
|
+
export declare function _getOrmlTokensPalletLockedBalance(accountInfo: OrmlTokensAccountData): bigint;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
|
|
5
|
+
import { _getAppliedExistentialDeposit, getMaxBigInt, getStrictMode } from '@subwallet/extension-base/core/utils';
|
|
6
|
+
export function _getOrmlTokensPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
|
|
7
|
+
const strictMode = getStrictMode(BalanceAccountType.OrmlTokensAccountData, extrinsicType);
|
|
8
|
+
const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
|
|
9
|
+
const bnFrozen = BigInt(accountInfo.frozen);
|
|
10
|
+
const bnFree = BigInt(accountInfo.free);
|
|
11
|
+
return bnFree - getMaxBigInt(bnFrozen, bnAppliedExistentialDeposit);
|
|
12
|
+
}
|
|
13
|
+
export function _getOrmlTokensPalletLockedBalance(accountInfo) {
|
|
14
|
+
const bnFrozen = BigInt(accountInfo.frozen);
|
|
15
|
+
const bnReserved = BigInt(accountInfo.reserved);
|
|
16
|
+
return bnReserved + bnFrozen;
|
|
17
|
+
}
|
|
@@ -1,27 +1,7 @@
|
|
|
1
1
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
free: number;
|
|
5
|
-
reserved: number;
|
|
6
|
-
frozen: number;
|
|
7
|
-
flags: number;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export declare type FrameSystemAccountInfoV1 = {
|
|
11
|
-
nonce: number;
|
|
12
|
-
consumers: number;
|
|
13
|
-
providers: number;
|
|
14
|
-
sufficients: number;
|
|
15
|
-
data: {
|
|
16
|
-
free: number | string;
|
|
17
|
-
reserved: number;
|
|
18
|
-
miscFrozen: number;
|
|
19
|
-
feeFrozen: number;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
export declare type FrameSystemAccountInfo = FrameSystemAccountInfoV1 | FrameSystemAccountInfoV2;
|
|
23
|
-
export declare function _getSystemPalletTransferable(accountInfo: FrameSystemAccountInfo, existentialDeposit: string, extrinsicType?: ExtrinsicType): string;
|
|
2
|
+
import { FrameSystemAccountInfo } from '@subwallet/extension-base/core/substrate/types';
|
|
3
|
+
export declare function _getSystemPalletTransferable(accountInfo: FrameSystemAccountInfo, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
|
|
24
4
|
export declare function _canAccountBeReaped(accountInfo: FrameSystemAccountInfo): boolean;
|
|
25
5
|
export declare function _isAccountActive(accountInfo: FrameSystemAccountInfo): boolean;
|
|
26
|
-
export declare function _getSystemPalletTotalBalance(accountInfo: FrameSystemAccountInfo):
|
|
27
|
-
export declare function _getAppliedExistentialDepositWithExtrinsicType(accountInfo: FrameSystemAccountInfo, existentialDeposit: string, extrinsicType?: ExtrinsicType):
|
|
6
|
+
export declare function _getSystemPalletTotalBalance(accountInfo: FrameSystemAccountInfo): bigint;
|
|
7
|
+
export declare function _getAppliedExistentialDepositWithExtrinsicType(accountInfo: FrameSystemAccountInfo, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
// https://crates.parity.io/frame_system/struct.AccountInfo.html
|
|
8
|
-
// https://wiki.polkadot.network/docs/learn-account-balances
|
|
9
|
-
|
|
4
|
+
import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
|
|
5
|
+
import { getMaxBigInt, getStrictMode } from '@subwallet/extension-base/core/utils';
|
|
10
6
|
function isV1(accountInfo) {
|
|
11
7
|
return accountInfo.data.miscFrozen !== undefined && accountInfo.data.feeFrozen !== undefined;
|
|
12
8
|
}
|
|
13
9
|
export function _getSystemPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
|
|
14
|
-
const strictMode =
|
|
10
|
+
const strictMode = getStrictMode(BalanceAccountType.FrameSystemAccountInfo, extrinsicType); // always apply strict mode to keep account alive unless explicitly specified otherwise
|
|
15
11
|
|
|
16
12
|
if (isV1(accountInfo)) {
|
|
17
13
|
return _getSystemPalletTransferableV1(accountInfo, existentialDeposit, strictMode);
|
|
@@ -34,7 +30,7 @@ export function _getSystemPalletTotalBalance(accountInfo) {
|
|
|
34
30
|
}
|
|
35
31
|
}
|
|
36
32
|
export function _getAppliedExistentialDepositWithExtrinsicType(accountInfo, existentialDeposit, extrinsicType) {
|
|
37
|
-
const strictMode =
|
|
33
|
+
const strictMode = getStrictMode(BalanceAccountType.FrameSystemAccountInfo, extrinsicType); // always apply strict mode to keep account alive unless explicitly specified otherwise
|
|
38
34
|
|
|
39
35
|
return _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode);
|
|
40
36
|
}
|
|
@@ -42,29 +38,30 @@ export function _getAppliedExistentialDepositWithExtrinsicType(accountInfo, exis
|
|
|
42
38
|
// ----------------------------------------------------------------------
|
|
43
39
|
|
|
44
40
|
function _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode) {
|
|
41
|
+
const bnExistentialDeposit = BigInt(existentialDeposit);
|
|
42
|
+
|
|
45
43
|
// strict mode will always apply existential deposit to keep account alive
|
|
46
44
|
if (strictMode) {
|
|
47
|
-
return
|
|
45
|
+
return bnExistentialDeposit;
|
|
48
46
|
}
|
|
49
|
-
return _canAccountBeReaped(accountInfo) ?
|
|
47
|
+
return _canAccountBeReaped(accountInfo) ? BigInt(0) : bnExistentialDeposit; // account for ED here will go better with max transfer logic
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
function _getSystemPalletTransferableV2(accountInfo, existentialDeposit, strictMode) {
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
return BigN.max(bnTransferableBalance, 0).toFixed();
|
|
51
|
+
const bnLocked = BigInt(accountInfo.data.frozen) - BigInt(accountInfo.data.reserved); // locked can go below 0 but this shouldn't matter
|
|
52
|
+
const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode);
|
|
53
|
+
const bnTransferable = BigInt(accountInfo.data.free) - getMaxBigInt(bnLocked, bnAppliedExistentialDeposit);
|
|
54
|
+
return getMaxBigInt(bnTransferable, BigInt(0));
|
|
58
55
|
}
|
|
59
56
|
function _getSystemPalletTotalBalanceV2(accountInfo) {
|
|
60
|
-
return
|
|
57
|
+
return BigInt(accountInfo.data.free) + BigInt(accountInfo.data.reserved);
|
|
61
58
|
}
|
|
62
59
|
function _getSystemPalletTransferableV1(accountInfo, existentialDeposit, strictMode) {
|
|
63
|
-
const bnAppliedExistentialDeposit =
|
|
64
|
-
const bnAppliedFrozen =
|
|
65
|
-
const
|
|
66
|
-
return
|
|
60
|
+
const bnAppliedExistentialDeposit = BigInt(_getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode));
|
|
61
|
+
const bnAppliedFrozen = getMaxBigInt(BigInt(accountInfo.data.feeFrozen), BigInt(accountInfo.data.miscFrozen));
|
|
62
|
+
const bnTransferable = BigInt(accountInfo.data.free) - getMaxBigInt(bnAppliedFrozen, bnAppliedExistentialDeposit);
|
|
63
|
+
return getMaxBigInt(bnTransferable, BigInt(0));
|
|
67
64
|
}
|
|
68
65
|
function _getSystemPalletTotalBalanceV1(accountInfo) {
|
|
69
|
-
return
|
|
66
|
+
return BigInt(accountInfo.data.free) + BigInt(accountInfo.data.reserved);
|
|
70
67
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { OrmlTokensAccountData } from '@subwallet/extension-base/core/substrate/types';
|
|
3
|
+
export declare function _getTokensPalletTransferable(accountInfo: OrmlTokensAccountData, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
|
|
4
|
+
export declare function _getTokensPalletLocked(accountInfo: OrmlTokensAccountData): bigint;
|
|
5
|
+
export declare function _getTokensPalletTotalBalance(accountInfo: OrmlTokensAccountData): bigint;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
|
|
5
|
+
import { _getAppliedExistentialDeposit, getMaxBigInt, getStrictMode } from '@subwallet/extension-base/core/utils';
|
|
6
|
+
export function _getTokensPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
|
|
7
|
+
const strictMode = getStrictMode(BalanceAccountType.OrmlTokensAccountData, extrinsicType);
|
|
8
|
+
const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
|
|
9
|
+
return BigInt(accountInfo.free) - getMaxBigInt(BigInt(accountInfo.frozen), bnAppliedExistentialDeposit);
|
|
10
|
+
}
|
|
11
|
+
export function _getTokensPalletLocked(accountInfo) {
|
|
12
|
+
return BigInt(accountInfo.reserved) + BigInt(accountInfo.frozen);
|
|
13
|
+
}
|
|
14
|
+
export function _getTokensPalletTotalBalance(accountInfo) {
|
|
15
|
+
return BigInt(accountInfo.free) + BigInt(accountInfo.reserved);
|
|
16
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare type FrameSystemAccountInfoV2 = Omit<FrameSystemAccountInfoV1, 'data'> & {
|
|
2
|
+
data: {
|
|
3
|
+
free: number;
|
|
4
|
+
reserved: number;
|
|
5
|
+
frozen: number;
|
|
6
|
+
flags: number;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare type FrameSystemAccountInfoV1 = {
|
|
10
|
+
nonce: number;
|
|
11
|
+
consumers: number;
|
|
12
|
+
providers: number;
|
|
13
|
+
sufficients: number;
|
|
14
|
+
data: {
|
|
15
|
+
free: number | string;
|
|
16
|
+
reserved: number;
|
|
17
|
+
miscFrozen: number;
|
|
18
|
+
feeFrozen: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare type FrameSystemAccountInfo = FrameSystemAccountInfoV1 | FrameSystemAccountInfoV2;
|
|
22
|
+
export declare type OrmlTokensAccountData = {
|
|
23
|
+
free: number;
|
|
24
|
+
reserved: number;
|
|
25
|
+
frozen: number;
|
|
26
|
+
};
|
|
27
|
+
export declare type PalletAssetsAssetAccount = {
|
|
28
|
+
balance: number | string;
|
|
29
|
+
status: 'Frozen' | 'Liquid' | 'Blocked';
|
|
30
|
+
reason: Record<string, unknown>;
|
|
31
|
+
extra: unknown;
|
|
32
|
+
};
|
|
33
|
+
export declare type PalletNominationPoolsPoolMember = {
|
|
34
|
+
poolId: number;
|
|
35
|
+
points: number;
|
|
36
|
+
lastRecordedRewardCounter: number;
|
|
37
|
+
unbondingEras: Record<string, number>;
|
|
38
|
+
};
|
|
39
|
+
export declare const BalanceAccountType: {
|
|
40
|
+
FrameSystemAccountInfo: string;
|
|
41
|
+
OrmlTokensAccountData: string;
|
|
42
|
+
PalletAssetsAssetAccount: string;
|
|
43
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// https://crates.parity.io/frame_system/struct.AccountInfo.html
|
|
5
|
+
// https://wiki.polkadot.network/docs/learn-account-balances
|
|
6
|
+
|
|
7
|
+
// export type BalanceAccountType = 'FrameSystemAccountInfo' | 'OrmlTokensAccountData' | 'PalletAssetsAssetAccount' | 'PalletNominationPoolsPoolMember';
|
|
8
|
+
export const BalanceAccountType = {
|
|
9
|
+
FrameSystemAccountInfo: 'FrameSystemAccountInfo',
|
|
10
|
+
OrmlTokensAccountData: 'OrmlTokensAccountData',
|
|
11
|
+
PalletAssetsAssetAccount: 'PalletAssetsAssetAccount'
|
|
12
|
+
};
|
|
@@ -51,3 +51,4 @@ export declare function _isXcmTransferUnstable(originChainInfo: _ChainInfo, dest
|
|
|
51
51
|
export declare function _getXcmUnstableWarning(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): string;
|
|
52
52
|
export declare function _isXcmWithinSameConsensus(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
53
53
|
export declare function _isSnowBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
54
|
+
export declare function _adaptX1Interior(assetIdentifier: Record<string, any>, version: number): Record<string, any>;
|
|
@@ -191,15 +191,28 @@ function _getRecipientLocation(destChainInfo, recipient, version) {
|
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
193
|
function _getAssetIdentifier(tokenInfo, version) {
|
|
194
|
-
const
|
|
195
|
-
if (!
|
|
194
|
+
const _assetIdentifier = _getXcmAssetMultilocation(tokenInfo);
|
|
195
|
+
if (!_assetIdentifier) {
|
|
196
196
|
throw new Error('Asset must have multilocation');
|
|
197
197
|
}
|
|
198
|
+
const assetIdentifier = _adaptX1Interior(structuredClone(_assetIdentifier), version);
|
|
198
199
|
return version >= 4 // from V4, Concrete is removed
|
|
199
200
|
? assetIdentifier : {
|
|
200
201
|
Concrete: assetIdentifier
|
|
201
202
|
};
|
|
202
203
|
}
|
|
204
|
+
export function _adaptX1Interior(assetIdentifier, version) {
|
|
205
|
+
const interior = assetIdentifier.interior;
|
|
206
|
+
const isInteriorObj = typeof interior === 'object' && interior !== null;
|
|
207
|
+
const isX1 = isInteriorObj && 'X1' in interior;
|
|
208
|
+
const needModifyX1 = version <= 4 && Array.isArray(interior.X1);
|
|
209
|
+
if (isInteriorObj && isX1 && needModifyX1) {
|
|
210
|
+
// X1 is an object for version < 4. From V4, it's an array
|
|
211
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
|
|
212
|
+
interior.X1 = interior.X1[0];
|
|
213
|
+
}
|
|
214
|
+
return assetIdentifier;
|
|
215
|
+
}
|
|
203
216
|
function _getNetworkByVersion(version) {
|
|
204
217
|
switch (version) {
|
|
205
218
|
case 1:
|