@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.
Files changed (61) hide show
  1. package/cjs/core/substrate/assets-pallet.js +35 -0
  2. package/cjs/core/substrate/foreign-asset-pallet.js +13 -3
  3. package/cjs/core/substrate/nominationpools-pallet.js +4 -6
  4. package/cjs/core/substrate/ormlTokens-pallet.js +24 -0
  5. package/cjs/core/substrate/system-pallet.js +18 -18
  6. package/cjs/core/substrate/tokens-pallet.js +24 -0
  7. package/cjs/core/substrate/types.js +19 -0
  8. package/cjs/core/substrate/xcm-parser.js +16 -2
  9. package/cjs/core/utils.js +25 -0
  10. package/cjs/koni/background/handlers/Extension.js +1 -1
  11. package/cjs/packageInfo.js +1 -1
  12. package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +2 -2
  13. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +120 -133
  14. package/cjs/services/balance-service/transfer/xcm/index.js +2 -1
  15. package/cjs/services/balance-service/transfer/xcm/polkadotXcm.js +1 -1
  16. package/cjs/services/balance-service/transfer/xcm/utils.js +3 -2
  17. package/cjs/services/chain-service/constants.js +1 -1
  18. package/cjs/services/chain-service/handler/SubstrateApi.js +128 -34
  19. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +26 -9
  20. package/cjs/services/chain-service/utils/index.js +5 -0
  21. package/core/substrate/assets-pallet.d.ts +4 -0
  22. package/core/substrate/assets-pallet.js +28 -0
  23. package/core/substrate/foreign-asset-pallet.d.ts +4 -8
  24. package/core/substrate/foreign-asset-pallet.js +13 -3
  25. package/core/substrate/nominationpools-pallet.d.ts +4 -10
  26. package/core/substrate/nominationpools-pallet.js +4 -5
  27. package/core/substrate/ormlTokens-pallet.d.ts +4 -0
  28. package/core/substrate/ormlTokens-pallet.js +17 -0
  29. package/core/substrate/system-pallet.d.ts +4 -24
  30. package/core/substrate/system-pallet.js +18 -21
  31. package/core/substrate/tokens-pallet.d.ts +5 -0
  32. package/core/substrate/tokens-pallet.js +16 -0
  33. package/core/substrate/types.d.ts +43 -0
  34. package/core/substrate/types.js +12 -0
  35. package/core/substrate/xcm-parser.d.ts +1 -0
  36. package/core/substrate/xcm-parser.js +15 -2
  37. package/core/utils.d.ts +4 -0
  38. package/core/utils.js +17 -0
  39. package/koni/api/staking/bonding/relayChain.d.ts +1 -1
  40. package/koni/background/handlers/Extension.js +1 -1
  41. package/koni/background/handlers/State.d.ts +2 -2
  42. package/package.json +31 -6
  43. package/packageInfo.js +1 -1
  44. package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +2 -2
  45. package/services/balance-service/helpers/subscribe/substrate/index.js +109 -121
  46. package/services/balance-service/transfer/xcm/index.d.ts +1 -1
  47. package/services/balance-service/transfer/xcm/index.js +2 -1
  48. package/services/balance-service/transfer/xcm/polkadotXcm.js +1 -1
  49. package/services/balance-service/transfer/xcm/utils.d.ts +1 -1
  50. package/services/balance-service/transfer/xcm/utils.js +3 -2
  51. package/services/chain-service/constants.js +1 -1
  52. package/services/chain-service/handler/SubstrateApi.d.ts +5 -7
  53. package/services/chain-service/handler/SubstrateApi.js +128 -35
  54. package/services/chain-service/handler/SubstrateChainHandler.d.ts +5 -6
  55. package/services/chain-service/handler/SubstrateChainHandler.js +26 -9
  56. package/services/chain-service/index.d.ts +3 -3
  57. package/services/chain-service/types.d.ts +22 -5
  58. package/services/chain-service/utils/index.d.ts +1 -0
  59. package/services/chain-service/utils/index.js +3 -0
  60. package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -1
  61. 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: substrateApi.api
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 chainNativeTokenSlug = (0, _utils2._getChainNativeTokenSlug)(chainInfo);
123
- const balanceSubscribe = substrateApi.rx.query.system.account.multi(addresses);
124
- let poolSubscribe; // add points in nomination pool back to user's balance
125
-
126
- if ((0, _utils2._isSubstrateRelayChain)(chainInfo) && substrateApi.query.nominationPools) {
127
- var _substrateApi$rx$quer;
128
- poolSubscribe = (_substrateApi$rx$quer = substrateApi.rx.query.nominationPools.poolMembers) === null || _substrateApi$rx$quer === void 0 ? void 0 : _substrateApi$rx$quer.multi(addresses);
129
- }
130
- if (!poolSubscribe) {
131
- poolSubscribe = new _rxjs.Observable(subscriber => {
132
- subscriber.next(addresses.map(() => ({
133
- toPrimitive() {
134
- return null;
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.toPrimitive();
149
- const poolMemberInfo = poolMemberInfos[index].toPrimitive();
150
- const nominationPoolBalance = poolMemberInfo ? (0, _nominationpoolsPallet._getTotalStakeInNominationPool)(poolMemberInfo) : new _bignumber.default(0);
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 = new _bignumber.default(totalBalance).minus(transferableBalance).plus(nominationPoolBalance);
146
+ const totalLockedFromTransfer = totalBalance - transferableBalance + nominationPoolBalance;
154
147
  return {
155
148
  address: addresses[index],
156
- tokenSlug: chainNativeTokenSlug,
157
- free: transferableBalance,
158
- locked: totalLockedFromTransfer.toFixed(),
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 _ref3 => {
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
- } = _ref3;
177
- const chain = chainInfo.slug;
178
- const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.LOCAL]);
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
- const isBridgedToken = (0, _utils2._isBridgedToken)(tokenInfo);
184
- if (isBridgedToken) {
185
- const assetLocation = (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getXcmAssetMultilocation)(tokenInfo);
186
- return await substrateApi.query.foreignAssets.account.multi(addresses.map(address => [assetLocation, address]), balances => {
187
- const items = balances.map((balance, index) => {
188
- const accountInfo = balance === null || balance === void 0 ? void 0 : balance.toPrimitive();
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: accountInfo ? (0, _foreignAssetPallet._getForeignAssetPalletTransferable)(accountInfo).toString() : '0',
193
- locked: accountInfo ? (0, _foreignAssetPallet._getForeignAssetPalletLockedBalance)(accountInfo).toString() : '0',
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 = _ref4 => {
219
+ const subscribePSP22Balance = _ref3 => {
221
220
  let {
222
221
  addresses,
223
222
  assetMap,
224
223
  callback,
225
224
  chainInfo,
226
225
  substrateApi
227
- } = _ref4;
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(_ref5 => {
232
- let [slug, tokenInfo] = _ref5;
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 _ref6 => {
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
- } = _ref6;
288
- const chain = chainInfo.slug;
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, chain, tokenTypes);
291
- const unsubList = await Promise.all(Object.values(tokenMap).map(async tokenInfo => {
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 onChainInfo = (0, _utils2._getTokenOnChainInfo)(tokenInfo);
294
- const assetId = (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
295
-
296
- // Get Token Balance
297
- // @ts-ignore
298
- return await substrateApi.query.tokens.accounts.multi(addresses.map(address => [address, onChainInfo || assetId]), balances => {
299
- const items = balances.map((balance, index) => {
300
- const tokenBalance = {
301
- reserved: balance.reserved || new _util.BN(0),
302
- frozen: balance.frozen || new _util.BN(0),
303
- free: balance.free || new _util.BN(0) // free is actually total balance
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: freeBalance.toString(),
313
- locked: lockedBalance.toString()
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 _ref7 => {
326
+ const subscribeAssetsAccountPallet = async _ref6 => {
330
327
  let {
331
328
  addresses,
332
329
  assetMap,
333
330
  callback,
334
331
  chainInfo,
335
- includeNativeToken,
332
+ extrinsicType,
336
333
  substrateApi
337
- } = _ref7;
338
- const chain = chainInfo.slug;
339
- const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.LOCAL]);
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(async tokenInfo => {
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 await substrateApi.query.assets.account.multi(addresses.map(address => [assetIndex, address]), balances => {
354
- const items = balances.map((balance, index) => {
355
- const bdata = balance === null || balance === void 0 ? void 0 : balance.toPrimitive();
356
- let frozen = _util.BN_ZERO;
357
- let total = _util.BN_ZERO;
358
- if (bdata) {
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: free.toString(),
374
- locked: frozen.toString(),
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 _ref8 => {
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
- } = _ref8;
401
- const chain = chainInfo.slug;
402
- const tokenTypes = [_types._AssetType.LOCAL];
403
- const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, tokenTypes);
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 onChainInfo = (0, _utils2._getTokenOnChainInfo)(tokenInfo);
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
- const unsub = await substrateApi.query.ormlTokens.accounts.multi(addresses.map(address => [address, onChainInfo]), balances => {
411
- const items = balances.map((balance, index) => {
412
- const tokenBalance = {
413
- reserved: balance.reserved || new _util.BN(0),
414
- frozen: balance.frozen || new _util.BN(0),
415
- free: balance.free || new _util.BN(0) // free is actually total balance
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: freeBalance.toString(),
427
- locked: lockedBalance.toString()
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(subProm => {
440
- subProm.then(unsub => {
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, address, originTokenInfo, destinationTokenInfo) => {
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
- return relayChainToSystemChain || systemChainToRelayChain;
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
  };