@subwallet/extension-base 1.1.64-0 → 1.1.66-0

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 (60) hide show
  1. package/cjs/koni/api/dotsama/transfer.js +16 -0
  2. package/cjs/koni/api/staking/bonding/relayChain.js +6 -0
  3. package/cjs/koni/api/tokens/wasm/utils.js +5 -3
  4. package/cjs/koni/background/handlers/State.js +2 -0
  5. package/cjs/packageInfo.js +1 -1
  6. package/cjs/services/balance-service/helpers/subscribe/index.js +1 -1
  7. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +88 -8
  8. package/cjs/services/chain-service/constants.js +8 -1
  9. package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
  10. package/cjs/services/chain-service/handler/SubstrateApi.js +15 -9
  11. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +76 -57
  12. package/cjs/services/chain-service/index.js +45 -30
  13. package/cjs/services/chain-service/types.js +1 -1
  14. package/cjs/services/chain-service/utils/index.js +38 -15
  15. package/cjs/services/chain-service/utils/patch.js +1 -1
  16. package/cjs/services/earning-service/constants/chains.js +2 -2
  17. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +3 -0
  18. package/cjs/services/earning-service/handlers/nomination-pool/index.js +1 -0
  19. package/cjs/services/price-service/index.js +31 -17
  20. package/cjs/stores/CurrentCurrencyStore.js +18 -0
  21. package/cjs/stores/index.js +8 -1
  22. package/cjs/utils/gear/grc20.js +141 -0
  23. package/cjs/utils/gear/index.js +16 -0
  24. package/cjs/utils/index.js +40 -28
  25. package/koni/api/dotsama/transfer.js +18 -2
  26. package/koni/api/staking/bonding/relayChain.d.ts +1 -2
  27. package/koni/api/staking/bonding/relayChain.js +6 -0
  28. package/koni/api/tokens/wasm/utils.js +5 -3
  29. package/koni/background/handlers/State.js +2 -0
  30. package/package.json +32 -15
  31. package/packageInfo.js +1 -1
  32. package/services/balance-service/helpers/subscribe/index.js +1 -1
  33. package/services/balance-service/helpers/subscribe/substrate/index.js +81 -4
  34. package/services/chain-service/constants.d.ts +1 -0
  35. package/services/chain-service/constants.js +8 -1
  36. package/services/chain-service/handler/EvmChainHandler.d.ts +1 -1
  37. package/services/chain-service/handler/EvmChainHandler.js +1 -1
  38. package/services/chain-service/handler/SubstrateApi.js +6 -0
  39. package/services/chain-service/handler/SubstrateChainHandler.d.ts +4 -1
  40. package/services/chain-service/handler/SubstrateChainHandler.js +76 -57
  41. package/services/chain-service/index.js +17 -8
  42. package/services/chain-service/types.js +1 -1
  43. package/services/chain-service/utils/index.d.ts +4 -0
  44. package/services/chain-service/utils/index.js +30 -15
  45. package/services/chain-service/utils/patch.js +1 -1
  46. package/services/earning-service/constants/chains.js +2 -2
  47. package/services/earning-service/handlers/native-staking/relay-chain.js +3 -0
  48. package/services/earning-service/handlers/nomination-pool/index.js +1 -0
  49. package/services/price-service/index.d.ts +4 -1
  50. package/services/price-service/index.js +31 -17
  51. package/stores/CurrentCurrencyStore.d.ts +5 -0
  52. package/stores/CurrentCurrencyStore.js +10 -0
  53. package/stores/index.d.ts +1 -0
  54. package/stores/index.js +2 -1
  55. package/utils/gear/grc20.d.ts +29 -0
  56. package/utils/gear/grc20.js +131 -0
  57. package/utils/gear/index.d.ts +1 -0
  58. package/utils/gear/index.js +4 -0
  59. package/utils/index.d.ts +6 -5
  60. package/utils/index.js +7 -6
@@ -6,11 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.checkReferenceCount = checkReferenceCount;
7
7
  exports.checkSupportTransfer = checkSupportTransfer;
8
8
  exports.createTransferExtrinsic = void 0;
9
+ var _api = require("@gear-js/api");
9
10
  var _wasm = require("@subwallet/extension-base/koni/api/tokens/wasm");
10
11
  var _utils = require("@subwallet/extension-base/koni/api/tokens/wasm/utils");
11
12
  var _constants = require("@subwallet/extension-base/services/chain-service/constants");
12
13
  var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
14
+ var _utils3 = require("@subwallet/extension-base/utils");
13
15
  var _util = require("@polkadot/util");
16
+ var _utilCrypto = require("@polkadot/util-crypto");
14
17
  // Copyright 2019-2022 @subwallet/extension-base
15
18
  // SPDX-License-Identifier: Apache-2.0
16
19
 
@@ -114,6 +117,7 @@ async function checkSupportTransfer(networkKey, tokenInfo, substrateApiMap, chai
114
117
  return result;
115
118
  }
116
119
  const createTransferExtrinsic = async _ref => {
120
+ var _tokenInfo$metadata;
117
121
  let {
118
122
  from,
119
123
  networkKey,
@@ -124,6 +128,10 @@ const createTransferExtrinsic = async _ref => {
124
128
  value
125
129
  } = _ref;
126
130
  const api = substrateApi.api;
131
+ const isDisableTransfer = (_tokenInfo$metadata = tokenInfo.metadata) === null || _tokenInfo$metadata === void 0 ? void 0 : _tokenInfo$metadata.isDisableTransfer;
132
+ if (isDisableTransfer) {
133
+ return [null, value];
134
+ }
127
135
 
128
136
  // @ts-ignore
129
137
  let transfer = null;
@@ -144,6 +152,14 @@ const createTransferExtrinsic = async _ref => {
144
152
  gasLimit
145
153
  }, to, value, {});
146
154
  transferAmount = value;
155
+ } else if ((0, _utils2._isTokenGearSmartContract)(tokenInfo) && api instanceof _api.GearApi) {
156
+ const contractPromise = (0, _utils3.getGRC20ContractPromise)(api, (0, _utils2._getContractAddressOfToken)(tokenInfo));
157
+ const transaction = await contractPromise.transfer((0, _util.u8aToHex)((0, _utilCrypto.decodeAddress)(to)), BigInt(value)) // Create transfer transaction
158
+ .withAccount(from) // Set sender account
159
+ .calculateGas(); // Add account arg to extrinsic
160
+
161
+ transfer = transaction.tx;
162
+ transferAmount = value;
147
163
  } else if (_constants._TRANSFER_CHAIN_GROUP.acala.includes(networkKey)) {
148
164
  if (!(0, _utils2._isNativeToken)(tokenInfo)) {
149
165
  if (isTxCurrenciesSupported) {
@@ -708,6 +708,7 @@ async function getRelayBondingExtrinsic(substrateApi, amount, targetValidators,
708
708
  if (paramsCount === 2) {
709
709
  bondTx = chainApi.api.tx.staking.bond(binaryAmount, bondDest);
710
710
  } else {
711
+ // @ts-ignore
711
712
  bondTx = chainApi.api.tx.staking.bond(address, binaryAmount, bondDest);
712
713
  }
713
714
  nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
@@ -718,6 +719,7 @@ async function getRelayBondingExtrinsic(substrateApi, amount, targetValidators,
718
719
  if (paramsCount === 2) {
719
720
  bondTx = chainApi.api.tx.staking.bond(binaryAmount, bondDest);
720
721
  } else {
722
+ // @ts-ignore
721
723
  bondTx = chainApi.api.tx.staking.bond(nominatorMetadata.address, binaryAmount, bondDest);
722
724
  }
723
725
  nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
@@ -735,6 +737,8 @@ async function getRelayBondingExtrinsic(substrateApi, amount, targetValidators,
735
737
  } else if (nominateTx && !bondTx) {
736
738
  return nominateTx;
737
739
  }
740
+
741
+ // @ts-ignore
738
742
  return chainApi.api.tx.utility.batchAll([bondTx, nominateTx]);
739
743
  }
740
744
  async function getRelayUnbondingExtrinsic(substrateApi, amount, nominatorMetadata) {
@@ -755,6 +759,7 @@ async function getRelayWithdrawalExtrinsic(substrateApi, address) {
755
759
  const slashingSpanCount = _slashingSpans !== null ? _slashingSpans.spanIndex : '0';
756
760
  return chainApi.api.tx.staking.withdrawUnbonded(slashingSpanCount);
757
761
  } else {
762
+ // @ts-ignore
758
763
  return chainApi.api.tx.staking.withdrawUnbonded();
759
764
  }
760
765
  }
@@ -799,6 +804,7 @@ async function getPoolingWithdrawalExtrinsic(substrateApi, nominatorMetadata) {
799
804
  Id: nominatorMetadata.address
800
805
  }, slashingSpanCount);
801
806
  } else {
807
+ // @ts-ignore
802
808
  return chainApi.api.tx.nominationPools.withdrawUnbonded({
803
809
  Id: nominatorMetadata.address
804
810
  });
@@ -42,11 +42,13 @@ async function getWasmContractGasLimit(api, callerAddress, message, contract) {
42
42
  storageDepositLimit,
43
43
  value
44
44
  } = options;
45
-
46
- // @ts-ignore
47
45
  const {
48
46
  gasRequired
49
- } = await api.call.contractsApi.call(callerAddress, contract.address, value !== null && value !== void 0 ? value : new _util.BN(0), gasLimit !== null && gasLimit !== void 0 ? gasLimit : null, storageDepositLimit !== null && storageDepositLimit !== void 0 ? storageDepositLimit : null, abiMessage === null || abiMessage === void 0 ? void 0 : (_abiMessage$value = abiMessage.value) === null || _abiMessage$value === void 0 ? void 0 : _abiMessage$value.toU8a(args));
47
+ } = await api.call.contractsApi.call(callerAddress, contract.address, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
48
+ value !== null && value !== void 0 ? value : new _util.BN(0), // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
49
+ gasLimit !== null && gasLimit !== void 0 ? gasLimit : null, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
50
+ storageDepositLimit !== null && storageDepositLimit !== void 0 ? storageDepositLimit : null, // @ts-ignore
51
+ abiMessage === null || abiMessage === void 0 ? void 0 : (_abiMessage$value = abiMessage.value) === null || _abiMessage$value === void 0 ? void 0 : _abiMessage$value.toU8a(args));
50
52
  return gasRequired;
51
53
  } catch {
52
54
  return getDefaultWeightV2(api, true);
@@ -67,6 +67,7 @@ const generateDefaultCrowdloanMap = () => {
67
67
  const crowdloanMap = {};
68
68
  return crowdloanMap;
69
69
  };
70
+ const DEFAULT_CURRENCY = 'USD';
70
71
  class KoniState {
71
72
  injectedProviders = new Map();
72
73
  unsubscriptionMap = {};
@@ -1570,6 +1571,7 @@ class KoniState {
1570
1571
  this.accountRefStore.set('refList', []);
1571
1572
  if (resetAll) {
1572
1573
  this.settingService.resetWallet();
1574
+ await this.priceService.setPriceCurrency(DEFAULT_CURRENCY);
1573
1575
  }
1574
1576
  this.chainService.resetWallet(resetAll);
1575
1577
  await this.walletConnectService.resetWallet(resetAll);
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.1.64-0'
16
+ version: '1.1.66-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -102,7 +102,7 @@ function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoM
102
102
  const chainSlug = chainInfo.slug;
103
103
  const [useAddresses, notSupportAddresses] = filterAddress(addresses, chainInfo);
104
104
  if (notSupportAddresses.length) {
105
- const tokens = (0, _utils2.filterAssetsByChainAndType)(chainAssetMap, chainSlug, [_types._AssetType.NATIVE, _types._AssetType.ERC20, _types._AssetType.PSP22, _types._AssetType.LOCAL]);
105
+ const tokens = (0, _utils2.filterAssetsByChainAndType)(chainAssetMap, chainSlug, [_types._AssetType.NATIVE, _types._AssetType.ERC20, _types._AssetType.PSP22, _types._AssetType.LOCAL, _types._AssetType.GRC20]);
106
106
  const now = new Date().getTime();
107
107
  Object.values(tokens).forEach(token => {
108
108
  const items = notSupportAddresses.map(address => ({
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.subscribeSubstrateBalance = void 0;
8
+ var _api = require("@gear-js/api");
7
9
  var _types = require("@subwallet/chain-list/types");
8
10
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
11
  var _constants = require("@subwallet/extension-base/constants");
@@ -12,8 +14,10 @@ var _utils = require("@subwallet/extension-base/koni/api/tokens/wasm/utils");
12
14
  var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
13
15
  var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
14
16
  var _utils3 = require("@subwallet/extension-base/utils");
17
+ var _bignumber = _interopRequireDefault(require("bignumber.js"));
15
18
  var _rxjs = require("rxjs");
16
19
  var _util = require("@polkadot/util");
20
+ var _utilCrypto = require("@polkadot/util-crypto");
17
21
  var _evm = require("../evm");
18
22
  var _equilibrium = require("./equilibrium");
19
23
  // Copyright 2019-2022 @subwallet/extension-base
@@ -25,6 +29,7 @@ const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap, substra
25
29
  let unsubEvmContractToken;
26
30
  let unsubWasmContractToken;
27
31
  let unsubBridgedToken;
32
+ let unsubGrcToken;
28
33
  const chain = chainInfo.slug;
29
34
  const baseParams = {
30
35
  addresses,
@@ -76,15 +81,21 @@ const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap, substra
76
81
  // Get sub-token for substrate-based chains
77
82
  unsubWasmContractToken = subscribePSP22Balance(substrateParams);
78
83
  }
84
+ if ((0, _utils2._checkSmartContractSupportByChain)(chainInfo, _types._AssetType.GRC20)) {
85
+ // Get sub-token for substrate-based chains
86
+ unsubGrcToken = subscribeGRC20Balance(substrateParams);
87
+ }
79
88
  } catch (err) {
80
89
  console.warn(err);
81
90
  }
82
91
  return () => {
92
+ var _unsubGrcToken;
83
93
  unsubNativeToken && unsubNativeToken();
84
94
  unsubLocalToken && unsubLocalToken();
85
95
  unsubEvmContractToken && unsubEvmContractToken();
86
96
  unsubWasmContractToken && unsubWasmContractToken();
87
97
  unsubBridgedToken && unsubBridgedToken();
98
+ (_unsubGrcToken = unsubGrcToken) === null || _unsubGrcToken === void 0 ? void 0 : _unsubGrcToken();
88
99
  };
89
100
  };
90
101
 
@@ -233,6 +244,15 @@ const subscribeBridgedBalance = async _ref4 => {
233
244
  });
234
245
  };
235
246
  };
247
+ function extractOkResponse(response) {
248
+ if ('ok' in response) {
249
+ return response.ok;
250
+ }
251
+ if ('Ok' in response) {
252
+ return response.Ok;
253
+ }
254
+ return undefined;
255
+ }
236
256
  const subscribePSP22Balance = _ref5 => {
237
257
  let {
238
258
  addresses,
@@ -254,15 +274,17 @@ const subscribePSP22Balance = _ref5 => {
254
274
  const contract = psp22ContractMap[tokenInfo.slug];
255
275
  const balances = await Promise.all(addresses.map(async address => {
256
276
  try {
257
- var _balanceOf$output, _ref7;
277
+ var _balanceOf$output;
258
278
  const _balanceOf = await contract.query['psp22::balanceOf'](address, {
259
279
  gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi)
260
280
  }, address);
261
281
  const balanceObj = _balanceOf === null || _balanceOf === void 0 ? void 0 : (_balanceOf$output = _balanceOf.output) === null || _balanceOf$output === void 0 ? void 0 : _balanceOf$output.toPrimitive();
282
+ const freeResponse = extractOkResponse(balanceObj);
283
+ const free = freeResponse ? new _bignumber.default(freeResponse).toString() : '0';
262
284
  return {
263
285
  address: address,
264
286
  tokenSlug: tokenInfo.slug,
265
- free: _balanceOf.output ? (_ref7 = balanceObj.ok) !== null && _ref7 !== void 0 ? _ref7 : balanceObj.Ok : '0',
287
+ free,
266
288
  locked: '0',
267
289
  state: _KoniTypes.APIItemState.READY
268
290
  };
@@ -290,7 +312,7 @@ const subscribePSP22Balance = _ref5 => {
290
312
  clearInterval(interval);
291
313
  };
292
314
  };
293
- const subscribeTokensAccountsPallet = async _ref8 => {
315
+ const subscribeTokensAccountsPallet = async _ref7 => {
294
316
  let {
295
317
  addresses,
296
318
  assetMap,
@@ -298,7 +320,7 @@ const subscribeTokensAccountsPallet = async _ref8 => {
298
320
  chainInfo,
299
321
  includeNativeToken,
300
322
  substrateApi
301
- } = _ref8;
323
+ } = _ref7;
302
324
  const chain = chainInfo.slug;
303
325
  const tokenTypes = includeNativeToken ? [_types._AssetType.NATIVE, _types._AssetType.LOCAL] : [_types._AssetType.LOCAL];
304
326
  const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, tokenTypes);
@@ -344,7 +366,7 @@ const subscribeTokensAccountsPallet = async _ref8 => {
344
366
  });
345
367
  };
346
368
  };
347
- const subscribeAssetsAccountPallet = async _ref9 => {
369
+ const subscribeAssetsAccountPallet = async _ref8 => {
348
370
  let {
349
371
  addresses,
350
372
  assetMap,
@@ -352,7 +374,7 @@ const subscribeAssetsAccountPallet = async _ref9 => {
352
374
  chainInfo,
353
375
  includeNativeToken,
354
376
  substrateApi
355
- } = _ref9;
377
+ } = _ref8;
356
378
  const chain = chainInfo.slug;
357
379
  const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.LOCAL]);
358
380
  Object.values(tokenMap).forEach(token => {
@@ -409,14 +431,14 @@ const subscribeAssetsAccountPallet = async _ref9 => {
409
431
  };
410
432
 
411
433
  // eslint-disable-next-line @typescript-eslint/require-await
412
- const subscribeOrmlTokensPallet = async _ref10 => {
434
+ const subscribeOrmlTokensPallet = async _ref9 => {
413
435
  let {
414
436
  addresses,
415
437
  assetMap,
416
438
  callback,
417
439
  chainInfo,
418
440
  substrateApi
419
- } = _ref10;
441
+ } = _ref9;
420
442
  const chain = chainInfo.slug;
421
443
  const tokenTypes = [_types._AssetType.LOCAL];
422
444
  const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, tokenTypes);
@@ -465,4 +487,62 @@ const subscribeOrmlTokensPallet = async _ref10 => {
465
487
  }).catch(console.error);
466
488
  });
467
489
  };
490
+ };
491
+ const subscribeGRC20Balance = _ref10 => {
492
+ let {
493
+ addresses,
494
+ assetMap,
495
+ callback,
496
+ chainInfo,
497
+ substrateApi
498
+ } = _ref10;
499
+ if (!(substrateApi instanceof _api.GearApi)) {
500
+ console.warn('Cannot subscribe GRC20 balance without GearApi instance');
501
+ return _util.noop;
502
+ }
503
+ const chain = chainInfo.slug;
504
+ const psp22ContractMap = {};
505
+ const tokenList = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.GRC20]);
506
+ Object.entries(tokenList).forEach(_ref11 => {
507
+ let [slug, tokenInfo] = _ref11;
508
+ psp22ContractMap[slug] = (0, _utils3.getGRC20ContractPromise)(substrateApi, (0, _utils2._getContractAddressOfToken)(tokenInfo));
509
+ });
510
+ const getTokenBalances = () => {
511
+ Object.values(tokenList).map(async tokenInfo => {
512
+ try {
513
+ const contract = psp22ContractMap[tokenInfo.slug];
514
+ const balances = await Promise.all(addresses.map(async address => {
515
+ try {
516
+ const actor = (0, _util.u8aToHex)((0, _utilCrypto.decodeAddress)(address));
517
+ const _balanceOf = await contract.balanceOf(actor, address);
518
+ return {
519
+ address: address,
520
+ tokenSlug: tokenInfo.slug,
521
+ free: _balanceOf.toString(10),
522
+ locked: '0',
523
+ state: _KoniTypes.APIItemState.READY
524
+ };
525
+ } catch (err) {
526
+ console.error(`Error on get balance of account ${address} for token ${tokenInfo.slug}`, err);
527
+ return {
528
+ address: address,
529
+ tokenSlug: tokenInfo.slug,
530
+ free: '0',
531
+ locked: '0',
532
+ state: _KoniTypes.APIItemState.READY
533
+ };
534
+ }
535
+ }));
536
+ callback(balances);
537
+ } catch (err) {
538
+ console.warn(tokenInfo.slug, err); // TODO: error createType
539
+ }
540
+ });
541
+ };
542
+
543
+ getTokenBalances();
544
+ const interval = setInterval(getTokenBalances, _constants.SUB_TOKEN_REFRESH_BALANCE_INTERVAL);
545
+ return () => {
546
+ clearInterval(interval);
547
+ };
468
548
  };
@@ -20,7 +20,8 @@ const _API_OPTIONS_CHAIN_GROUP = {
20
20
  acala: ['acala', 'karura', 'origintrail', 'kintsugi'],
21
21
  turing: ['turingStaging', 'turing'],
22
22
  avail: ['kate', 'availTuringTest', 'avail_mainnet'],
23
- goldberg: ['goldberg_testnet']
23
+ goldberg: ['goldberg_testnet'],
24
+ gear: ['vara_network', 'vara_testnet']
24
25
  };
25
26
  exports._API_OPTIONS_CHAIN_GROUP = _API_OPTIONS_CHAIN_GROUP;
26
27
  const _PREDEFINED_SINGLE_MODES = {
@@ -99,6 +100,7 @@ const _STAKING_ERA_LENGTH_MAP = {
99
100
  kate: 6,
100
101
  creditcoin: 24,
101
102
  vara_network: 12,
103
+ vara_testnet: 12,
102
104
  goldberg_testnet: 24,
103
105
  manta_network: 6,
104
106
  krest_network: 4,
@@ -123,6 +125,7 @@ const _EXPECTED_BLOCK_TIME = {
123
125
  edgeware: 6,
124
126
  creditcoin: 12,
125
127
  vara_network: 3,
128
+ vara_testnet: 3,
126
129
  goldberg_testnet: 20,
127
130
  polimec: 12,
128
131
  bifrost: 13,
@@ -229,6 +232,10 @@ const _KNOWN_CHAIN_INFLATION_PARAMS = {
229
232
  vara_network: {
230
233
  ..._SUBSTRATE_DEFAULT_INFLATION_PARAMS,
231
234
  stakeTarget: 0.8
235
+ },
236
+ vara_testnet: {
237
+ ..._SUBSTRATE_DEFAULT_INFLATION_PARAMS,
238
+ stakeTarget: 0.8
232
239
  }
233
240
  };
234
241
 
@@ -109,7 +109,7 @@ class EvmChainHandler extends _AbstractChainHandler.AbstractChainHandler {
109
109
  }
110
110
  return result;
111
111
  }
112
- async getSmartContractTokenInfo(contractAddress, tokenType, originChain) {
112
+ async getEvmContractTokenInfo(contractAddress, tokenType, originChain) {
113
113
  let tokenContract;
114
114
  let name = '';
115
115
  let decimals = -1;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.SubstrateApi = void 0;
7
7
  require("@polkadot/types-augment");
8
8
  var _api = require("@acala-network/api");
9
+ var _api2 = require("@gear-js/api");
9
10
  var _types = require("@oak-foundation/types");
10
11
  var _constants = require("@subwallet/extension-base/services/chain-service/constants");
11
12
  var _lightClient = require("@subwallet/extension-base/services/chain-service/handler/light-client");
@@ -14,8 +15,8 @@ var _types2 = require("@subwallet/extension-base/services/chain-service/types");
14
15
  var _promise = require("@subwallet/extension-base/utils/promise");
15
16
  var _availJsSdk = require("avail-js-sdk");
16
17
  var _rxjs = require("rxjs");
17
- var _api2 = require("@polkadot/api");
18
- var _api3 = require("@polkadot/apps-config/api");
18
+ var _api3 = require("@polkadot/api");
19
+ var _api4 = require("@polkadot/apps-config/api");
19
20
  var _create = require("@polkadot/types/create");
20
21
  var _util = require("@polkadot/util");
21
22
  var _defaults = require("@polkadot/util-crypto/address/defaults");
@@ -55,13 +56,13 @@ class SubstrateApi {
55
56
  return (0, _lightClient.getSubstrateConnectProvider)(apiUrl.replace('light://substrate-connect/', ''));
56
57
  } else {
57
58
  this.useLightClient = true;
58
- return new _api2.WsProvider(apiUrl, _constants.API_AUTO_CONNECT_MS, {}, _constants.API_CONNECT_TIMEOUT);
59
+ return new _api3.WsProvider(apiUrl, _constants.API_AUTO_CONNECT_MS, {}, _constants.API_CONNECT_TIMEOUT);
59
60
  }
60
61
  }
61
62
  createApi(provider, externalApiPromise) {
62
63
  const apiOption = {
63
64
  provider,
64
- typesBundle: _api3.typesBundle,
65
+ typesBundle: _api4.typesBundle,
65
66
  registry: this.registry,
66
67
  noInitWarn: true
67
68
  };
@@ -76,19 +77,19 @@ class SubstrateApi {
76
77
  if (externalApiPromise) {
77
78
  api = externalApiPromise;
78
79
  } else if (_constants._API_OPTIONS_CHAIN_GROUP.acala.includes(this.chainSlug)) {
79
- api = new _api2.ApiPromise((0, _api.options)({
80
+ api = new _api3.ApiPromise((0, _api.options)({
80
81
  provider,
81
82
  noInitWarn: true
82
83
  }));
83
84
  } else if (_constants._API_OPTIONS_CHAIN_GROUP.turing.includes(this.chainSlug)) {
84
- api = new _api2.ApiPromise({
85
+ api = new _api3.ApiPromise({
85
86
  provider,
86
87
  rpc: _types.rpc,
87
88
  types: _types.types,
88
89
  noInitWarn: true
89
90
  });
90
91
  } else if (_constants._API_OPTIONS_CHAIN_GROUP.avail.includes(this.chainSlug)) {
91
- api = new _api2.ApiPromise({
92
+ api = new _api3.ApiPromise({
92
93
  provider,
93
94
  rpc: _availJsSdk.spec.rpc,
94
95
  types: _availJsSdk.spec.types,
@@ -96,15 +97,20 @@ class SubstrateApi {
96
97
  noInitWarn: true
97
98
  });
98
99
  } else if (_constants._API_OPTIONS_CHAIN_GROUP.goldberg.includes(this.chainSlug)) {
99
- api = new _api2.ApiPromise({
100
+ api = new _api3.ApiPromise({
100
101
  provider,
101
102
  rpc: _availJsSdk.goldbergRpc,
102
103
  types: _availJsSdk.goldbergTypes,
103
104
  signedExtensions: _availJsSdk.spec.signedExtensions,
104
105
  noInitWarn: true
105
106
  });
107
+ } else if (_constants._API_OPTIONS_CHAIN_GROUP.gear.includes(this.chainSlug)) {
108
+ api = new _api2.GearApi({
109
+ provider,
110
+ noInitWarn: true
111
+ });
106
112
  } else {
107
- api = new _api2.ApiPromise(apiOption);
113
+ api = new _api3.ApiPromise(apiOption);
108
114
  }
109
115
  api.on('ready', this.onReady.bind(this));
110
116
  api.on('connected', this.onConnect.bind(this));
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.SubstrateChainHandler = exports.DEFAULT_AUX = void 0;
7
+ var _api = require("@gear-js/api");
7
8
  var _types = require("@subwallet/chain-list/types");
8
9
  var _utils = require("@subwallet/extension-base/koni/api/tokens/wasm/utils");
9
10
  var _AbstractChainHandler = require("@subwallet/extension-base/services/chain-service/handler/AbstractChainHandler");
10
11
  var _SubstrateApi2 = require("@subwallet/extension-base/services/chain-service/handler/SubstrateApi");
12
+ var _utils2 = require("@subwallet/extension-base/utils");
11
13
  var _apiContract = require("@polkadot/api-contract");
12
14
  var _util = require("@polkadot/util");
13
15
  var _logger = require("@polkadot/util/logger");
@@ -93,69 +95,86 @@ class SubstrateChainHandler extends _AbstractChainHandler.AbstractChainHandler {
93
95
  result.existentialDeposit = substrateApi.api.consts.balances.existentialDeposit.toString();
94
96
  return result;
95
97
  }
96
- async getSmartContractTokenInfo(contractAddress, tokenType, originChain, contractCaller) {
97
- let tokenContract;
98
+ async getPsp22TokenInfo(apiPromise, contractAddress, contractCaller) {
99
+ const tokenContract = new _apiContract.ContractPromise(apiPromise, _helper._PSP22_ABI, contractAddress);
100
+ const [nameResp, symbolResp, decimalsResp] = await Promise.all([tokenContract.query['psp22Metadata::tokenName'](contractCaller || contractAddress, {
101
+ gasLimit: (0, _utils.getDefaultWeightV2)(apiPromise)
102
+ }),
103
+ // read-only operation so no gas limit
104
+ tokenContract.query['psp22Metadata::tokenSymbol'](contractCaller || contractAddress, {
105
+ gasLimit: (0, _utils.getDefaultWeightV2)(apiPromise)
106
+ }), tokenContract.query['psp22Metadata::tokenDecimals'](contractCaller || contractAddress, {
107
+ gasLimit: (0, _utils.getDefaultWeightV2)(apiPromise)
108
+ })]);
109
+ if (!(nameResp.result.isOk && symbolResp.result.isOk && decimalsResp.result.isOk) || !nameResp.output || !decimalsResp.output || !symbolResp.output) {
110
+ return ['', 1, '', true];
111
+ } else {
112
+ var _symbolResp$output, _decimalsResp$output, _nameResp$output;
113
+ let contractError = false;
114
+ const symbolObj = (_symbolResp$output = symbolResp.output) === null || _symbolResp$output === void 0 ? void 0 : _symbolResp$output.toHuman();
115
+ const decimalsObj = (_decimalsResp$output = decimalsResp.output) === null || _decimalsResp$output === void 0 ? void 0 : _decimalsResp$output.toHuman();
116
+ const nameObj = (_nameResp$output = nameResp.output) === null || _nameResp$output === void 0 ? void 0 : _nameResp$output.toHuman();
117
+ const name = nameResp.output ? nameObj.Ok || nameObj.ok : '';
118
+ const decimals = decimalsResp.output ? new _util.BN(decimalsObj.Ok || decimalsObj.ok).toNumber() : 0;
119
+ const symbol = decimalsResp.output ? symbolObj.Ok || symbolObj.ok : '';
120
+ if (!name || !symbol || typeof name === 'object' || typeof symbol === 'object') {
121
+ contractError = true;
122
+ }
123
+ return [name, decimals, symbol, contractError];
124
+ }
125
+ }
126
+ async getPsp34TokenInfo(apiPromise, contractAddress, contractCaller) {
127
+ const tokenContract = new _apiContract.ContractPromise(apiPromise, _helper._PSP34_ABI, contractAddress);
128
+ const collectionIdResp = await tokenContract.query['psp34::collectionId'](contractCaller || contractAddress, {
129
+ gasLimit: (0, _utils.getDefaultWeightV2)(apiPromise)
130
+ }); // read-only operation so no gas limit
131
+
132
+ if (!collectionIdResp.result.isOk || !collectionIdResp.output) {
133
+ return ['', -1, '', true];
134
+ } else {
135
+ var _collectionIdResp$out;
136
+ let contractError = false;
137
+ const collectionIdDict = (_collectionIdResp$out = collectionIdResp.output) === null || _collectionIdResp$out === void 0 ? void 0 : _collectionIdResp$out.toHuman();
138
+ if (collectionIdDict.Bytes === '') {
139
+ contractError = true;
140
+ }
141
+ return ['', -1, '', contractError];
142
+ }
143
+ }
144
+ async getGrc20TokenInfo(apiPromise, contractAddress) {
145
+ if (!(apiPromise instanceof _api.GearApi)) {
146
+ console.warn('Cannot subscribe GRC20 balance without GearApi instance');
147
+ return ['', -1, '', true];
148
+ }
149
+ let contractError = false;
150
+ const tokenContract = (0, _utils2.getGRC20ContractPromise)(apiPromise, contractAddress);
151
+ const [nameRes, symbolRes, decimalsRes] = await Promise.all([tokenContract.name(_utils2.DEFAULT_GEAR_ADDRESS.ALICE), tokenContract.symbol(_utils2.DEFAULT_GEAR_ADDRESS.ALICE), tokenContract.decimals(_utils2.DEFAULT_GEAR_ADDRESS.ALICE)]);
152
+ const decimals = typeof decimalsRes === 'string' ? parseInt(decimalsRes) : decimalsRes;
153
+ if (!nameRes || !symbolRes) {
154
+ contractError = true;
155
+ }
156
+ return [nameRes, decimals, symbolRes, contractError];
157
+ }
158
+ async getSubstrateContractTokenInfo(contractAddress, tokenType, originChain, contractCaller) {
159
+ // todo: improve this funtion later
160
+
98
161
  let name = '';
99
162
  let decimals = -1;
100
163
  let symbol = '';
101
164
  let contractError = false;
102
- const substrateApi = this.getSubstrateApiByChain(originChain);
165
+ const apiPromise = this.getSubstrateApiByChain(originChain).api;
103
166
  try {
104
- if (tokenType === _types._AssetType.PSP22) {
105
- tokenContract = new _apiContract.ContractPromise(substrateApi.api, _helper._PSP22_ABI, contractAddress);
106
- const [nameResp, symbolResp, decimalsResp] = await Promise.all([tokenContract.query['psp22Metadata::tokenName'](contractCaller || contractAddress, {
107
- gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi.api)
108
- }),
109
- // read-only operation so no gas limit
110
- tokenContract.query['psp22Metadata::tokenSymbol'](contractCaller || contractAddress, {
111
- gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi.api)
112
- }), tokenContract.query['psp22Metadata::tokenDecimals'](contractCaller || contractAddress, {
113
- gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi.api)
114
- })]);
115
- if (!(nameResp.result.isOk && symbolResp.result.isOk && decimalsResp.result.isOk) || !nameResp.output || !decimalsResp.output || !symbolResp.output) {
116
- return {
117
- name: '',
118
- decimals: -1,
119
- symbol: '',
120
- contractError: true
121
- };
122
- } else {
123
- var _symbolResp$output, _decimalsResp$output, _nameResp$output;
124
- const symbolObj = (_symbolResp$output = symbolResp.output) === null || _symbolResp$output === void 0 ? void 0 : _symbolResp$output.toHuman();
125
- const decimalsObj = (_decimalsResp$output = decimalsResp.output) === null || _decimalsResp$output === void 0 ? void 0 : _decimalsResp$output.toHuman();
126
- const nameObj = (_nameResp$output = nameResp.output) === null || _nameResp$output === void 0 ? void 0 : _nameResp$output.toHuman();
127
- name = nameResp.output ? nameObj.Ok || nameObj.ok : '';
128
- decimals = decimalsResp.output ? new _util.BN(decimalsObj.Ok || decimalsObj.ok).toNumber() : 0;
129
- symbol = decimalsResp.output ? symbolObj.Ok || symbolObj.ok : '';
130
- if (!name || !symbol || typeof name === 'object' || typeof symbol === 'object') {
131
- contractError = true;
132
- }
133
- console.log('validate PSP22', name, symbol, decimals);
134
- }
135
- } else {
136
- tokenContract = new _apiContract.ContractPromise(substrateApi.api, _helper._PSP34_ABI, contractAddress);
137
- const collectionIdResp = await tokenContract.query['psp34::collectionId'](contractCaller || contractAddress, {
138
- gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi.api)
139
- }); // read-only operation so no gas limit
140
-
141
- if (!collectionIdResp.result.isOk || !collectionIdResp.output) {
142
- return {
143
- name: '',
144
- decimals: -1,
145
- symbol: '',
146
- contractError: true
147
- };
148
- } else {
149
- var _collectionIdResp$out;
150
- const collectionIdDict = (_collectionIdResp$out = collectionIdResp.output) === null || _collectionIdResp$out === void 0 ? void 0 : _collectionIdResp$out.toHuman();
151
- if (collectionIdDict.Bytes === '') {
152
- contractError = true;
153
- } else {
154
- name = ''; // no function to get collection name, let user manually put in the name
155
- }
156
- }
167
+ switch (tokenType) {
168
+ case _types._AssetType.PSP22:
169
+ [name, decimals, symbol, contractError] = await this.getPsp22TokenInfo(apiPromise, contractAddress, contractCaller);
170
+ break;
171
+ case _types._AssetType.PSP34:
172
+ [name, decimals, symbol, contractError] = await this.getPsp34TokenInfo(apiPromise, contractAddress, contractCaller);
173
+ break;
174
+ case _types._AssetType.GRC20:
175
+ [name, decimals, symbol, contractError] = await this.getGrc20TokenInfo(apiPromise, contractAddress);
176
+ break;
157
177
  }
158
-
159
178
  return {
160
179
  name,
161
180
  decimals,