@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
|
@@ -8,17 +8,19 @@ exports.subscribeSubstrateBalance = void 0;
|
|
|
8
8
|
var _types = require("@subwallet/chain-list/types");
|
|
9
9
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
10
|
var _constants = require("@subwallet/extension-base/constants");
|
|
11
|
+
var _assetsPallet = require("@subwallet/extension-base/core/substrate/assets-pallet");
|
|
11
12
|
var _foreignAssetPallet = require("@subwallet/extension-base/core/substrate/foreign-asset-pallet");
|
|
12
13
|
var _nominationpoolsPallet = require("@subwallet/extension-base/core/substrate/nominationpools-pallet");
|
|
14
|
+
var _ormlTokensPallet = require("@subwallet/extension-base/core/substrate/ormlTokens-pallet");
|
|
13
15
|
var _systemPallet = require("@subwallet/extension-base/core/substrate/system-pallet");
|
|
16
|
+
var _tokensPallet = require("@subwallet/extension-base/core/substrate/tokens-pallet");
|
|
17
|
+
var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
|
|
14
18
|
var _wasm = require("@subwallet/extension-base/koni/api/contract-handler/wasm");
|
|
15
19
|
var _utils = require("@subwallet/extension-base/koni/api/contract-handler/wasm/utils");
|
|
16
20
|
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
17
21
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
18
22
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
19
23
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
20
|
-
var _rxjs = require("rxjs");
|
|
21
|
-
var _util = require("@polkadot/util");
|
|
22
24
|
var _evm = require("../evm");
|
|
23
25
|
var _equilibrium = require("./equilibrium");
|
|
24
26
|
var _gear = require("./gear");
|
|
@@ -43,7 +45,7 @@ const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap, substra
|
|
|
43
45
|
};
|
|
44
46
|
const substrateParams = {
|
|
45
47
|
...baseParams,
|
|
46
|
-
substrateApi
|
|
48
|
+
substrateApi
|
|
47
49
|
};
|
|
48
50
|
if (!_constants2._BALANCE_CHAIN_GROUP.kintsugi.includes(chain) && !_constants2._BALANCE_CHAIN_GROUP.genshiro.includes(chain) && !_constants2._BALANCE_CHAIN_GROUP.equilibrium_parachain.includes(chain)) {
|
|
49
51
|
unsubNativeToken = await subscribeWithSystemAccountPallet(substrateParams);
|
|
@@ -119,43 +121,34 @@ const subscribeWithSystemAccountPallet = async _ref => {
|
|
|
119
121
|
extrinsicType,
|
|
120
122
|
substrateApi
|
|
121
123
|
} = _ref;
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
const subscription = (0, _rxjs.combineLatest)({
|
|
140
|
-
balances: balanceSubscribe,
|
|
141
|
-
poolMemberInfos: poolSubscribe
|
|
142
|
-
}).subscribe(_ref2 => {
|
|
143
|
-
let {
|
|
144
|
-
balances,
|
|
145
|
-
poolMemberInfos
|
|
146
|
-
} = _ref2;
|
|
124
|
+
const systemAccountKey = 'query_system_account';
|
|
125
|
+
const poolMembersKey = 'query_nominationPools_poolMembers';
|
|
126
|
+
const params = [{
|
|
127
|
+
section: 'query',
|
|
128
|
+
module: systemAccountKey.split('_')[1],
|
|
129
|
+
method: systemAccountKey.split('_')[2],
|
|
130
|
+
args: addresses
|
|
131
|
+
}, {
|
|
132
|
+
section: 'query',
|
|
133
|
+
module: poolMembersKey.split('_')[1],
|
|
134
|
+
method: poolMembersKey.split('_')[2],
|
|
135
|
+
args: addresses
|
|
136
|
+
}];
|
|
137
|
+
const subscription = substrateApi.subscribeDataWithMulti(params, rs => {
|
|
138
|
+
const balances = rs[systemAccountKey];
|
|
139
|
+
const poolMemberInfos = rs[poolMembersKey];
|
|
147
140
|
const items = balances.map((_balance, index) => {
|
|
148
|
-
const balanceInfo = _balance
|
|
149
|
-
const poolMemberInfo = poolMemberInfos[index]
|
|
150
|
-
const nominationPoolBalance = poolMemberInfo ? (0, _nominationpoolsPallet._getTotalStakeInNominationPool)(poolMemberInfo) :
|
|
141
|
+
const balanceInfo = _balance;
|
|
142
|
+
const poolMemberInfo = poolMemberInfos[index];
|
|
143
|
+
const nominationPoolBalance = poolMemberInfo ? (0, _nominationpoolsPallet._getTotalStakeInNominationPool)(poolMemberInfo) : BigInt(0);
|
|
151
144
|
const transferableBalance = (0, _systemPallet._getSystemPalletTransferable)(balanceInfo, (0, _utils2._getChainExistentialDeposit)(chainInfo), extrinsicType);
|
|
152
145
|
const totalBalance = (0, _systemPallet._getSystemPalletTotalBalance)(balanceInfo);
|
|
153
|
-
const totalLockedFromTransfer =
|
|
146
|
+
const totalLockedFromTransfer = totalBalance - transferableBalance + nominationPoolBalance;
|
|
154
147
|
return {
|
|
155
148
|
address: addresses[index],
|
|
156
|
-
tokenSlug:
|
|
157
|
-
free: transferableBalance,
|
|
158
|
-
locked: totalLockedFromTransfer.
|
|
149
|
+
tokenSlug: (0, _utils2._getChainNativeTokenSlug)(chainInfo),
|
|
150
|
+
free: transferableBalance.toString(),
|
|
151
|
+
locked: totalLockedFromTransfer.toString(),
|
|
159
152
|
state: _KoniTypes.APIItemState.READY,
|
|
160
153
|
metadata: balanceInfo
|
|
161
154
|
};
|
|
@@ -166,31 +159,37 @@ const subscribeWithSystemAccountPallet = async _ref => {
|
|
|
166
159
|
subscription.unsubscribe();
|
|
167
160
|
};
|
|
168
161
|
};
|
|
169
|
-
const subscribeForeignAssetBalance = async
|
|
162
|
+
const subscribeForeignAssetBalance = async _ref2 => {
|
|
170
163
|
let {
|
|
171
164
|
addresses,
|
|
172
165
|
assetMap,
|
|
173
166
|
callback,
|
|
174
167
|
chainInfo,
|
|
168
|
+
extrinsicType,
|
|
175
169
|
substrateApi
|
|
176
|
-
} =
|
|
177
|
-
const
|
|
178
|
-
const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap,
|
|
179
|
-
|
|
180
|
-
// @ts-ignore
|
|
181
|
-
const unsubList = await Promise.all(Object.values(tokenMap).map(async tokenInfo => {
|
|
170
|
+
} = _ref2;
|
|
171
|
+
const foreignAssetsAccountKey = 'query_foreignAssets_account';
|
|
172
|
+
const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chainInfo.slug, [_types._AssetType.LOCAL]);
|
|
173
|
+
const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
|
|
182
174
|
try {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
175
|
+
if ((0, _utils2._isBridgedToken)(tokenInfo)) {
|
|
176
|
+
const params = [{
|
|
177
|
+
section: 'query',
|
|
178
|
+
module: foreignAssetsAccountKey.split('_')[1],
|
|
179
|
+
method: foreignAssetsAccountKey.split('_')[2],
|
|
180
|
+
args: addresses.map(address => [(0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _xcmParser._adaptX1Interior)((0, _utils2._getXcmAssetMultilocation)(tokenInfo), 3), address])
|
|
181
|
+
}];
|
|
182
|
+
return substrateApi.subscribeDataWithMulti(params, rs => {
|
|
183
|
+
const balances = rs[foreignAssetsAccountKey];
|
|
184
|
+
const items = balances.map((_balance, index) => {
|
|
185
|
+
const balanceInfo = _balance;
|
|
186
|
+
const transferableBalance = (0, _foreignAssetPallet._getForeignAssetPalletTransferable)(balanceInfo, (0, _utils2._getAssetExistentialDeposit)(tokenInfo), extrinsicType);
|
|
187
|
+
const totalLockedFromTransfer = (0, _foreignAssetPallet._getForeignAssetPalletLockedBalance)(balanceInfo);
|
|
189
188
|
return {
|
|
190
189
|
address: addresses[index],
|
|
191
190
|
tokenSlug: tokenInfo.slug,
|
|
192
|
-
free:
|
|
193
|
-
locked:
|
|
191
|
+
free: transferableBalance.toString(),
|
|
192
|
+
locked: totalLockedFromTransfer.toString(),
|
|
194
193
|
state: _KoniTypes.APIItemState.READY
|
|
195
194
|
};
|
|
196
195
|
});
|
|
@@ -204,7 +203,7 @@ const subscribeForeignAssetBalance = async _ref3 => {
|
|
|
204
203
|
}));
|
|
205
204
|
return () => {
|
|
206
205
|
unsubList.forEach(unsub => {
|
|
207
|
-
unsub && unsub();
|
|
206
|
+
unsub && unsub.unsubscribe();
|
|
208
207
|
});
|
|
209
208
|
};
|
|
210
209
|
};
|
|
@@ -217,20 +216,20 @@ function extractOkResponse(response) {
|
|
|
217
216
|
}
|
|
218
217
|
return undefined;
|
|
219
218
|
}
|
|
220
|
-
const subscribePSP22Balance =
|
|
219
|
+
const subscribePSP22Balance = _ref3 => {
|
|
221
220
|
let {
|
|
222
221
|
addresses,
|
|
223
222
|
assetMap,
|
|
224
223
|
callback,
|
|
225
224
|
chainInfo,
|
|
226
225
|
substrateApi
|
|
227
|
-
} =
|
|
226
|
+
} = _ref3;
|
|
228
227
|
const chain = chainInfo.slug;
|
|
229
228
|
const psp22ContractMap = {};
|
|
230
229
|
const tokenList = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.PSP22]);
|
|
231
|
-
Object.entries(tokenList).forEach(
|
|
232
|
-
let [slug, tokenInfo] =
|
|
233
|
-
psp22ContractMap[slug] = (0, _wasm.getPSP22ContractPromise)(substrateApi, (0, _utils2._getContractAddressOfToken)(tokenInfo));
|
|
230
|
+
Object.entries(tokenList).forEach(_ref4 => {
|
|
231
|
+
let [slug, tokenInfo] = _ref4;
|
|
232
|
+
psp22ContractMap[slug] = (0, _wasm.getPSP22ContractPromise)(substrateApi.api, (0, _utils2._getContractAddressOfToken)(tokenInfo));
|
|
234
233
|
});
|
|
235
234
|
const getTokenBalances = () => {
|
|
236
235
|
Object.values(tokenList).map(async tokenInfo => {
|
|
@@ -240,7 +239,7 @@ const subscribePSP22Balance = _ref4 => {
|
|
|
240
239
|
try {
|
|
241
240
|
var _balanceOf$output;
|
|
242
241
|
const _balanceOf = await contract.query['psp22::balanceOf'](address, {
|
|
243
|
-
gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi)
|
|
242
|
+
gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi.api)
|
|
244
243
|
}, address);
|
|
245
244
|
const balanceObj = _balanceOf === null || _balanceOf === void 0 ? void 0 : (_balanceOf$output = _balanceOf.output) === null || _balanceOf$output === void 0 ? void 0 : _balanceOf$output.toPrimitive();
|
|
246
245
|
const freeResponse = extractOkResponse(balanceObj);
|
|
@@ -276,41 +275,39 @@ const subscribePSP22Balance = _ref4 => {
|
|
|
276
275
|
clearInterval(interval);
|
|
277
276
|
};
|
|
278
277
|
};
|
|
279
|
-
const subscribeTokensAccountsPallet = async
|
|
278
|
+
const subscribeTokensAccountsPallet = async _ref5 => {
|
|
280
279
|
let {
|
|
281
280
|
addresses,
|
|
282
281
|
assetMap,
|
|
283
282
|
callback,
|
|
284
283
|
chainInfo,
|
|
284
|
+
extrinsicType,
|
|
285
285
|
includeNativeToken,
|
|
286
286
|
substrateApi
|
|
287
|
-
} =
|
|
288
|
-
const
|
|
287
|
+
} = _ref5;
|
|
288
|
+
const tokensAccountsKey = 'query_tokens_accounts';
|
|
289
289
|
const tokenTypes = includeNativeToken ? [_types._AssetType.NATIVE, _types._AssetType.LOCAL] : [_types._AssetType.LOCAL];
|
|
290
|
-
const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap,
|
|
291
|
-
const unsubList = await Promise.all(Object.values(tokenMap).map(
|
|
290
|
+
const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chainInfo.slug, tokenTypes);
|
|
291
|
+
const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
|
|
292
292
|
try {
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
const freeBalance = tokenBalance.free.sub(tokenBalance.frozen);
|
|
307
|
-
const lockedBalance = tokenBalance.frozen.add(tokenBalance.reserved);
|
|
293
|
+
const params = [{
|
|
294
|
+
section: 'query',
|
|
295
|
+
module: tokensAccountsKey.split('_')[1],
|
|
296
|
+
method: tokensAccountsKey.split('_')[2],
|
|
297
|
+
args: addresses.map(address => [address, (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo)])
|
|
298
|
+
}];
|
|
299
|
+
return substrateApi.subscribeDataWithMulti(params, rs => {
|
|
300
|
+
const balances = rs[tokensAccountsKey];
|
|
301
|
+
const items = balances.map((_balance, index) => {
|
|
302
|
+
const balanceInfo = _balance;
|
|
303
|
+
const transferableBalance = (0, _tokensPallet._getTokensPalletTransferable)(balanceInfo, (0, _utils2._getAssetExistentialDeposit)(tokenInfo), extrinsicType);
|
|
304
|
+
const totalLockedFromTransfer = (0, _tokensPallet._getTokensPalletLocked)(balanceInfo);
|
|
308
305
|
return {
|
|
309
306
|
address: addresses[index],
|
|
310
307
|
tokenSlug: tokenInfo.slug,
|
|
311
308
|
state: _KoniTypes.APIItemState.READY,
|
|
312
|
-
free:
|
|
313
|
-
locked:
|
|
309
|
+
free: transferableBalance.toString(),
|
|
310
|
+
locked: totalLockedFromTransfer.toString()
|
|
314
311
|
};
|
|
315
312
|
});
|
|
316
313
|
callback(items);
|
|
@@ -322,56 +319,51 @@ const subscribeTokensAccountsPallet = async _ref6 => {
|
|
|
322
319
|
}));
|
|
323
320
|
return () => {
|
|
324
321
|
unsubList.forEach(unsub => {
|
|
325
|
-
unsub && unsub();
|
|
322
|
+
unsub && unsub.unsubscribe();
|
|
326
323
|
});
|
|
327
324
|
};
|
|
328
325
|
};
|
|
329
|
-
const subscribeAssetsAccountPallet = async
|
|
326
|
+
const subscribeAssetsAccountPallet = async _ref6 => {
|
|
330
327
|
let {
|
|
331
328
|
addresses,
|
|
332
329
|
assetMap,
|
|
333
330
|
callback,
|
|
334
331
|
chainInfo,
|
|
335
|
-
|
|
332
|
+
extrinsicType,
|
|
336
333
|
substrateApi
|
|
337
|
-
} =
|
|
338
|
-
const
|
|
339
|
-
const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap,
|
|
334
|
+
} = _ref6;
|
|
335
|
+
const assetsAccountKey = 'query_assets_account';
|
|
336
|
+
const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chainInfo.slug, [_types._AssetType.LOCAL]);
|
|
340
337
|
Object.values(tokenMap).forEach(token => {
|
|
341
338
|
if (_constants2._MANTA_ZK_CHAIN_GROUP.includes(token.originChain) && token.symbol.startsWith(_constants2._ZK_ASSET_PREFIX)) {
|
|
342
339
|
delete tokenMap[token.slug];
|
|
343
340
|
}
|
|
344
341
|
});
|
|
345
|
-
const unsubList = await Promise.all(Object.values(tokenMap).map(
|
|
342
|
+
const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
|
|
346
343
|
try {
|
|
347
344
|
const assetIndex = (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
|
|
348
345
|
if (assetIndex === '-1') {
|
|
349
346
|
return undefined;
|
|
350
347
|
}
|
|
348
|
+
const params = [{
|
|
349
|
+
section: 'query',
|
|
350
|
+
module: assetsAccountKey.split('_')[1],
|
|
351
|
+
method: assetsAccountKey.split('_')[2],
|
|
352
|
+
args: addresses.map(address => [assetIndex, address])
|
|
353
|
+
}];
|
|
351
354
|
|
|
352
355
|
// Get Token Balance
|
|
353
|
-
return
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
// @ts-ignore
|
|
360
|
-
const addressBalance = new _util.BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance).replaceAll(',', '') || '0');
|
|
361
|
-
|
|
362
|
-
// @ts-ignore
|
|
363
|
-
if (bdata !== null && bdata !== void 0 && bdata.isFrozen || ['Blocked', 'Frozen'].includes(bdata === null || bdata === void 0 ? void 0 : bdata.status)) {
|
|
364
|
-
// Status 'Frozen' and 'Blocked' are for frozen balance
|
|
365
|
-
frozen = addressBalance;
|
|
366
|
-
}
|
|
367
|
-
total = addressBalance;
|
|
368
|
-
}
|
|
369
|
-
const free = total.sub(frozen);
|
|
356
|
+
return substrateApi.subscribeDataWithMulti(params, rs => {
|
|
357
|
+
const balances = rs[assetsAccountKey];
|
|
358
|
+
const items = balances.map((_balance, index) => {
|
|
359
|
+
const balanceInfo = _balance;
|
|
360
|
+
const transferableBalance = (0, _assetsPallet._getAssetsPalletTransferable)(balanceInfo, (0, _utils2._getAssetExistentialDeposit)(tokenInfo), extrinsicType);
|
|
361
|
+
const totalLockedFromTransfer = (0, _assetsPallet._getAssetsPalletLockedBalance)(balanceInfo);
|
|
370
362
|
return {
|
|
371
363
|
address: addresses[index],
|
|
372
364
|
tokenSlug: tokenInfo.slug,
|
|
373
|
-
free:
|
|
374
|
-
locked:
|
|
365
|
+
free: transferableBalance.toString(),
|
|
366
|
+
locked: totalLockedFromTransfer.toString(),
|
|
375
367
|
state: _KoniTypes.APIItemState.READY
|
|
376
368
|
};
|
|
377
369
|
});
|
|
@@ -384,62 +376,57 @@ const subscribeAssetsAccountPallet = async _ref7 => {
|
|
|
384
376
|
}));
|
|
385
377
|
return () => {
|
|
386
378
|
unsubList.forEach(unsub => {
|
|
387
|
-
unsub && unsub();
|
|
379
|
+
unsub && unsub.unsubscribe();
|
|
388
380
|
});
|
|
389
381
|
};
|
|
390
382
|
};
|
|
391
383
|
|
|
392
384
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
393
|
-
const subscribeOrmlTokensPallet = async
|
|
385
|
+
const subscribeOrmlTokensPallet = async _ref7 => {
|
|
394
386
|
let {
|
|
395
387
|
addresses,
|
|
396
388
|
assetMap,
|
|
397
389
|
callback,
|
|
398
390
|
chainInfo,
|
|
391
|
+
extrinsicType,
|
|
399
392
|
substrateApi
|
|
400
|
-
} =
|
|
401
|
-
const
|
|
402
|
-
const
|
|
403
|
-
const
|
|
404
|
-
const unsubList = Object.values(tokenMap).map(async tokenInfo => {
|
|
393
|
+
} = _ref7;
|
|
394
|
+
const ormlTokensAccountsKey = 'query_ormlTokens_accounts';
|
|
395
|
+
const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chainInfo.slug, [_types._AssetType.LOCAL]);
|
|
396
|
+
const unsubList = Object.values(tokenMap).map(tokenInfo => {
|
|
405
397
|
try {
|
|
406
|
-
const
|
|
398
|
+
const params = [{
|
|
399
|
+
section: 'query',
|
|
400
|
+
module: ormlTokensAccountsKey.split('_')[1],
|
|
401
|
+
method: ormlTokensAccountsKey.split('_')[2],
|
|
402
|
+
args: addresses.map(address => [address, (0, _utils2._getTokenOnChainInfo)(tokenInfo)])
|
|
403
|
+
}];
|
|
407
404
|
|
|
408
|
-
// Get Token Balance
|
|
409
405
|
// @ts-ignore
|
|
410
|
-
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
// free balance = total balance - frozen misc
|
|
419
|
-
// locked balance = reserved + frozen misc
|
|
420
|
-
const freeBalance = tokenBalance.free.sub(tokenBalance.frozen);
|
|
421
|
-
const lockedBalance = tokenBalance.frozen.add(tokenBalance.reserved);
|
|
406
|
+
return substrateApi.subscribeDataWithMulti(params, rs => {
|
|
407
|
+
const balances = rs[ormlTokensAccountsKey];
|
|
408
|
+
const items = balances.map((_balance, index) => {
|
|
409
|
+
const balanceInfo = _balance;
|
|
410
|
+
const transferableBalance = (0, _ormlTokensPallet._getOrmlTokensPalletTransferable)(balanceInfo, (0, _utils2._getAssetExistentialDeposit)(tokenInfo), extrinsicType);
|
|
411
|
+
const totalLockedFromTransfer = (0, _ormlTokensPallet._getOrmlTokensPalletLockedBalance)(balanceInfo);
|
|
422
412
|
return {
|
|
423
413
|
address: addresses[index],
|
|
424
414
|
tokenSlug: tokenInfo.slug,
|
|
425
415
|
state: _KoniTypes.APIItemState.READY,
|
|
426
|
-
free:
|
|
427
|
-
locked:
|
|
416
|
+
free: transferableBalance.toString(),
|
|
417
|
+
locked: totalLockedFromTransfer.toString()
|
|
428
418
|
};
|
|
429
419
|
});
|
|
430
420
|
callback(items);
|
|
431
421
|
});
|
|
432
|
-
return unsub;
|
|
433
422
|
} catch (err) {
|
|
434
423
|
console.warn(err);
|
|
435
424
|
return undefined;
|
|
436
425
|
}
|
|
437
426
|
});
|
|
438
427
|
return () => {
|
|
439
|
-
unsubList.forEach(
|
|
440
|
-
|
|
441
|
-
unsub && unsub();
|
|
442
|
-
}).catch(console.error);
|
|
428
|
+
unsubList.forEach(unsub => {
|
|
429
|
+
unsub && unsub.unsubscribe();
|
|
443
430
|
});
|
|
444
431
|
};
|
|
445
432
|
};
|
|
@@ -64,11 +64,12 @@ const createXcmExtrinsic = async _ref2 => {
|
|
|
64
64
|
return extrinsic;
|
|
65
65
|
};
|
|
66
66
|
exports.createXcmExtrinsic = createXcmExtrinsic;
|
|
67
|
-
const getXcmMockTxFee = async (substrateApi, chainInfoMap,
|
|
67
|
+
const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo) => {
|
|
68
68
|
try {
|
|
69
69
|
var _paymentInfo$partialF;
|
|
70
70
|
const destChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
71
71
|
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
72
|
+
const address = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap';
|
|
72
73
|
|
|
73
74
|
// mock receiving account from sender
|
|
74
75
|
const recipient = !(0, _utilCrypto.isEthereumAddress)(address) && (0, _utils._isChainEvmCompatible)(destChainInfo) && !(0, _utils._isChainEvmCompatible)(originChainInfo) ? (0, _util.u8aToHex)((0, _utilCrypto.addressToEvm)(address)) : address;
|
|
@@ -17,7 +17,7 @@ function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destination
|
|
|
17
17
|
version = 4;
|
|
18
18
|
method = 'transferAssets';
|
|
19
19
|
}
|
|
20
|
-
if ((0, _utils.isUseTeleportProtocol)(originChainInfo, destinationChainInfo)) {
|
|
20
|
+
if ((0, _utils.isUseTeleportProtocol)(originChainInfo, destinationChainInfo, tokenInfo.slug)) {
|
|
21
21
|
method = 'limitedTeleportAssets';
|
|
22
22
|
}
|
|
23
23
|
const weightParam = (0, _xcmParser._getXcmDestWeight)(originChainInfo);
|
|
@@ -10,8 +10,9 @@ exports.isUseTeleportProtocol = isUseTeleportProtocol;
|
|
|
10
10
|
|
|
11
11
|
const STABLE_XCM_VERSION = 3;
|
|
12
12
|
exports.STABLE_XCM_VERSION = STABLE_XCM_VERSION;
|
|
13
|
-
function isUseTeleportProtocol(originChainInfo, destChainInfo) {
|
|
13
|
+
function isUseTeleportProtocol(originChainInfo, destChainInfo, tokenSlug) {
|
|
14
14
|
const relayChainToSystemChain = ['polkadot'].includes(originChainInfo.slug) && ['statemint'].includes(destChainInfo.slug) || ['kusama'].includes(originChainInfo.slug) && ['statemine'].includes(destChainInfo.slug) || ['rococo'].includes(originChainInfo.slug) && ['rococo_assethub'].includes(destChainInfo.slug);
|
|
15
15
|
const systemChainToRelayChain = ['polkadot'].includes(destChainInfo.slug) && ['statemint'].includes(originChainInfo.slug) || ['kusama'].includes(destChainInfo.slug) && ['statemine'].includes(originChainInfo.slug) || ['rococo'].includes(destChainInfo.slug) && ['rococo_assethub'].includes(originChainInfo.slug);
|
|
16
|
-
|
|
16
|
+
const isXcmMythos = originChainInfo.slug === 'mythos' && destChainInfo.slug === 'statemint' && tokenSlug === 'mythos-NATIVE-MYTH' || originChainInfo.slug === 'statemint' && destChainInfo.slug === 'mythos' && tokenSlug === 'statemint-LOCAL-MYTH';
|
|
17
|
+
return relayChainToSystemChain || systemChainToRelayChain || isXcmMythos;
|
|
17
18
|
}
|
|
@@ -278,7 +278,7 @@ const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
|
|
|
278
278
|
// XCM------------------------------------------------------------------------------------------------------------------
|
|
279
279
|
exports._DEFAULT_MANTA_ZK_CHAIN = _DEFAULT_MANTA_ZK_CHAIN;
|
|
280
280
|
const _XCM_CHAIN_GROUP = {
|
|
281
|
-
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub'],
|
|
281
|
+
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub', 'mythos'],
|
|
282
282
|
xcmPallet: ['polkadot', 'kusama', 'rococo']
|
|
283
283
|
// default is xTokens pallet
|
|
284
284
|
};
|