@subwallet/extension-base 1.2.15-0 → 1.2.16-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 (58) hide show
  1. package/background/KoniTypes.d.ts +6 -1
  2. package/cjs/koni/background/handlers/Extension.js +33 -7
  3. package/cjs/koni/background/handlers/State.js +11 -1
  4. package/cjs/packageInfo.js +1 -1
  5. package/cjs/services/balance-service/helpers/subscribe/index.js +1 -1
  6. package/cjs/services/balance-service/helpers/subscribe/substrate/gear.js +135 -0
  7. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +9 -62
  8. package/cjs/services/balance-service/transfer/token.js +4 -3
  9. package/cjs/services/chain-service/handler/SubstrateApi.js +3 -1
  10. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +21 -26
  11. package/cjs/services/chain-service/index.js +48 -3
  12. package/cjs/services/chain-service/types.js +1 -1
  13. package/cjs/services/chain-service/utils/index.js +18 -12
  14. package/cjs/services/earning-service/service.js +3 -0
  15. package/cjs/services/migration-service/scripts/databases/ClearMetadataDatabase.js +16 -0
  16. package/cjs/services/migration-service/scripts/index.js +7 -7
  17. package/cjs/services/transaction-service/index.js +12 -7
  18. package/cjs/utils/gear/combine.js +28 -0
  19. package/cjs/utils/gear/grc20.js +56 -49
  20. package/cjs/utils/gear/index.js +22 -0
  21. package/cjs/utils/gear/vft.js +173 -0
  22. package/cjs/utils/metadata.js +45 -34
  23. package/koni/background/handlers/Extension.d.ts +2 -0
  24. package/koni/background/handlers/Extension.js +25 -1
  25. package/koni/background/handlers/State.d.ts +2 -0
  26. package/koni/background/handlers/State.js +11 -1
  27. package/package.json +24 -8
  28. package/packageInfo.js +1 -1
  29. package/services/balance-service/helpers/subscribe/index.js +1 -1
  30. package/services/balance-service/helpers/subscribe/substrate/gear.d.ts +4 -0
  31. package/services/balance-service/helpers/subscribe/substrate/gear.js +123 -0
  32. package/services/balance-service/helpers/subscribe/substrate/index.js +10 -61
  33. package/services/balance-service/transfer/token.js +5 -4
  34. package/services/chain-service/handler/SubstrateApi.d.ts +1 -1
  35. package/services/chain-service/handler/SubstrateApi.js +3 -1
  36. package/services/chain-service/handler/SubstrateChainHandler.d.ts +1 -0
  37. package/services/chain-service/handler/SubstrateChainHandler.js +22 -27
  38. package/services/chain-service/index.d.ts +4 -0
  39. package/services/chain-service/index.js +49 -4
  40. package/services/chain-service/types.d.ts +1 -0
  41. package/services/chain-service/types.js +1 -1
  42. package/services/chain-service/utils/index.d.ts +1 -0
  43. package/services/chain-service/utils/index.js +16 -12
  44. package/services/earning-service/service.js +3 -0
  45. package/services/migration-service/scripts/databases/ClearMetadataDatabase.js +16 -0
  46. package/services/migration-service/scripts/index.js +7 -7
  47. package/services/transaction-service/index.js +13 -8
  48. package/types/metadata.d.ts +9 -2
  49. package/utils/gear/combine.d.ts +10 -0
  50. package/utils/gear/combine.js +18 -0
  51. package/utils/gear/grc20.d.ts +18 -20
  52. package/utils/gear/grc20.js +53 -45
  53. package/utils/gear/index.d.ts +2 -0
  54. package/utils/gear/index.js +3 -1
  55. package/utils/gear/vft.d.ts +36 -0
  56. package/utils/gear/vft.js +162 -0
  57. package/utils/metadata.d.ts +7 -2
  58. package/utils/metadata.js +41 -31
@@ -38,6 +38,7 @@ var _exportNames = {
38
38
  _isChainSupportEvmERC20: true,
39
39
  _isChainSupportWasmPSP22: true,
40
40
  _isChainSupportGRC20: true,
41
+ _isChainSupportVFT: true,
41
42
  _isSupportOrdinal: true,
42
43
  _getNftTypesSupportedByChain: true,
43
44
  _getTokenTypesSupportedByChain: true,
@@ -131,6 +132,7 @@ exports._isChainSupportEvmNft = _isChainSupportEvmNft;
131
132
  exports._isChainSupportGRC20 = _isChainSupportGRC20;
132
133
  exports._isChainSupportNativeNft = _isChainSupportNativeNft;
133
134
  exports._isChainSupportSubstrateStaking = _isChainSupportSubstrateStaking;
135
+ exports._isChainSupportVFT = _isChainSupportVFT;
134
136
  exports._isChainSupportWasmNft = _isChainSupportWasmNft;
135
137
  exports._isChainSupportWasmPSP22 = _isChainSupportWasmPSP22;
136
138
  exports._isChainTestNet = _isChainTestNet;
@@ -357,6 +359,10 @@ function _isChainSupportGRC20(chainInfo) {
357
359
  var _chainInfo$substrateI12, _chainInfo$substrateI13;
358
360
  return ((_chainInfo$substrateI12 = chainInfo.substrateInfo) === null || _chainInfo$substrateI12 === void 0 ? void 0 : (_chainInfo$substrateI13 = _chainInfo$substrateI12.supportSmartContract) === null || _chainInfo$substrateI13 === void 0 ? void 0 : _chainInfo$substrateI13.includes(_types._AssetType.GRC20)) || false;
359
361
  }
362
+ function _isChainSupportVFT(chainInfo) {
363
+ var _chainInfo$substrateI14, _chainInfo$substrateI15;
364
+ return ((_chainInfo$substrateI14 = chainInfo.substrateInfo) === null || _chainInfo$substrateI14 === void 0 ? void 0 : (_chainInfo$substrateI15 = _chainInfo$substrateI14.supportSmartContract) === null || _chainInfo$substrateI15 === void 0 ? void 0 : _chainInfo$substrateI15.includes(_types._AssetType.VFT)) || false;
365
+ }
360
366
  const _isSupportOrdinal = chain => {
361
367
  const chains = ['polkadot', 'astar', 'bifrost_dot', 'moonbeam'];
362
368
  return chains.includes(chain);
@@ -384,7 +390,7 @@ function _getTokenTypesSupportedByChain(chainInfo) {
384
390
  const result = [];
385
391
  if (chainInfo.substrateInfo && chainInfo.substrateInfo.supportSmartContract) {
386
392
  chainInfo.substrateInfo.supportSmartContract.forEach(assetType => {
387
- if ([_types._AssetType.PSP22, _types._AssetType.GRC20].includes(assetType)) {
393
+ if ([_types._AssetType.PSP22, _types._AssetType.GRC20, _types._AssetType.VFT].includes(assetType)) {
388
394
  result.push(assetType);
389
395
  }
390
396
  });
@@ -441,7 +447,7 @@ function _isAssetSmartContractNft(assetInfo) {
441
447
  return [_types._AssetType.PSP34, _types._AssetType.ERC721].includes(assetInfo.assetType);
442
448
  }
443
449
  function _isTokenGearSmartContract(tokenInfo) {
444
- return [_types._AssetType.GRC20, _types._AssetType.GRC721].includes(tokenInfo.assetType);
450
+ return [_types._AssetType.GRC20, _types._AssetType.GRC721, _types._AssetType.VFT].includes(tokenInfo.assetType);
445
451
  }
446
452
  function _parseAssetRefKey(originTokenSlug, destinationTokenSlug) {
447
453
  return `${originTokenSlug}___${destinationTokenSlug}`;
@@ -473,12 +479,12 @@ function _isRelayChain(chainInfo) {
473
479
  return _isSubstrateRelayChain(chainInfo) || _isPureEvmChain(chainInfo);
474
480
  }
475
481
  function _isSubstrateRelayChain(chainInfo) {
476
- var _chainInfo$substrateI14;
477
- return ((_chainInfo$substrateI14 = chainInfo.substrateInfo) === null || _chainInfo$substrateI14 === void 0 ? void 0 : _chainInfo$substrateI14.chainType) === _types._SubstrateChainType.RELAYCHAIN;
482
+ var _chainInfo$substrateI16;
483
+ return ((_chainInfo$substrateI16 = chainInfo.substrateInfo) === null || _chainInfo$substrateI16 === void 0 ? void 0 : _chainInfo$substrateI16.chainType) === _types._SubstrateChainType.RELAYCHAIN;
478
484
  }
479
485
  function _isSubstrateParaChain(chainInfo) {
480
- var _chainInfo$substrateI15;
481
- return chainInfo.substrateInfo !== null && chainInfo.substrateInfo.paraId !== null && ((_chainInfo$substrateI15 = chainInfo.substrateInfo) === null || _chainInfo$substrateI15 === void 0 ? void 0 : _chainInfo$substrateI15.chainType) === _types._SubstrateChainType.PARACHAIN;
486
+ var _chainInfo$substrateI17;
487
+ return chainInfo.substrateInfo !== null && chainInfo.substrateInfo.paraId !== null && ((_chainInfo$substrateI17 = chainInfo.substrateInfo) === null || _chainInfo$substrateI17 === void 0 ? void 0 : _chainInfo$substrateI17.chainType) === _types._SubstrateChainType.PARACHAIN;
482
488
  }
483
489
  function _getEvmAbiExplorer(chainInfo) {
484
490
  var _chainInfo$evmInfo4;
@@ -523,8 +529,8 @@ function _getBlockExplorerFromChain(chainInfo) {
523
529
  var _chainInfo$evmInfo5;
524
530
  blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo5 = chainInfo.evmInfo) === null || _chainInfo$evmInfo5 === void 0 ? void 0 : _chainInfo$evmInfo5.blockExplorer;
525
531
  } else {
526
- var _chainInfo$substrateI16;
527
- blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI16 = chainInfo.substrateInfo) === null || _chainInfo$substrateI16 === void 0 ? void 0 : _chainInfo$substrateI16.blockExplorer;
532
+ var _chainInfo$substrateI18;
533
+ blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI18 = chainInfo.substrateInfo) === null || _chainInfo$substrateI18 === void 0 ? void 0 : _chainInfo$substrateI18.blockExplorer;
528
534
  }
529
535
  if (!blockExplorer) {
530
536
  return undefined;
@@ -551,8 +557,8 @@ const _isAssetAutoEnable = chainAsset => {
551
557
  };
552
558
  exports._isAssetAutoEnable = _isAssetAutoEnable;
553
559
  function _getCrowdloanUrlFromChain(chainInfo) {
554
- var _chainInfo$substrateI17;
555
- return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI17 = chainInfo.substrateInfo) === null || _chainInfo$substrateI17 === void 0 ? void 0 : _chainInfo$substrateI17.crowdloanUrl) || '';
560
+ var _chainInfo$substrateI19;
561
+ return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI19 = chainInfo.substrateInfo) === null || _chainInfo$substrateI19 === void 0 ? void 0 : _chainInfo$substrateI19.crowdloanUrl) || '';
556
562
  }
557
563
  function _isCustomProvider(providerKey) {
558
564
  return providerKey.startsWith(_types2._CUSTOM_PREFIX);
@@ -590,8 +596,8 @@ function _isMantaZkAsset(chainAsset) {
590
596
  return _constants._MANTA_ZK_CHAIN_GROUP.includes(chainAsset.originChain) && chainAsset.symbol.startsWith(_constants._ZK_ASSET_PREFIX);
591
597
  }
592
598
  function _getChainExistentialDeposit(chainInfo) {
593
- var _chainInfo$substrateI18;
594
- return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI18 = chainInfo.substrateInfo) === null || _chainInfo$substrateI18 === void 0 ? void 0 : _chainInfo$substrateI18.existentialDeposit) || '0';
599
+ var _chainInfo$substrateI20;
600
+ return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI20 = chainInfo.substrateInfo) === null || _chainInfo$substrateI20 === void 0 ? void 0 : _chainInfo$substrateI20.existentialDeposit) || '0';
595
601
  }
596
602
  function randomizeProvider(providers, excludedKeys) {
597
603
  if (Object.keys(providers).length === 0) {
@@ -144,6 +144,9 @@ class EarningService {
144
144
  if (event.type === 'account.remove') {
145
145
  removedAddresses.push(event.data[0]);
146
146
  }
147
+ if (event.type === 'account.add') {
148
+ delayReload = true;
149
+ }
147
150
  if (event.type === 'chain.updateState') {
148
151
  const chainState = this.state.getChainStateByKey(event.data[0]);
149
152
  if (chainState && !(0, _utils._isChainEnabled)(chainState)) {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _Base = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/Base"));
9
+ var _utils = require("@subwallet/extension-base/utils");
9
10
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
10
11
  // SPDX-License-Identifier: Apache-2.0
11
12
 
@@ -13,6 +14,21 @@ class ClearMetadataDatabase extends _Base.default {
13
14
  async run() {
14
15
  // Clear all old metadata data
15
16
  await this.state.dbService.stores.metadata.clear();
17
+ const activeChains = this.state.chainService.getActiveChains();
18
+ const chainInfoMap = this.state.chainService.getChainInfoMap();
19
+ const reloadChains = activeChains.filter(chain => {
20
+ var _chainInfoMap$chain$s;
21
+ return !!((_chainInfoMap$chain$s = chainInfoMap[chain].substrateInfo) !== null && _chainInfoMap$chain$s !== void 0 && _chainInfoMap$chain$s.genesisHash);
22
+ });
23
+ for (const chain of reloadChains) {
24
+ const substrateApi = this.state.chainService.getSubstrateApi(chain);
25
+ const callback = substrateApi => {
26
+ (0, _utils.cacheMetadata)(chain, substrateApi, this.state.chainService);
27
+ };
28
+ Promise.race([substrateApi.isReady, (0, _utils.waitTimeout)(2000)]).finally(() => {
29
+ substrateApi === null || substrateApi === void 0 ? void 0 : substrateApi.connect(callback);
30
+ });
31
+ }
16
32
  return Promise.resolve();
17
33
  }
18
34
  }
@@ -5,14 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.EVERYTIME = void 0;
8
- var _AutoEnableSomeTokens = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/databases/AutoEnableSomeTokens"));
9
- var _ReloadMetadata = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/databases/ReloadMetadata"));
10
- var _DeleteEarningData = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/DeleteEarningData"));
11
- var _MigrateRemoveGenesisHash = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/MigrateRemoveGenesisHash"));
12
- var _MigrateTransactionHistoryBySymbol = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/MigrateTransactionHistoryBySymbol"));
8
+ var _AutoEnableSomeTokens = _interopRequireDefault(require("./databases/AutoEnableSomeTokens"));
13
9
  var _ClearMetadataDatabase = _interopRequireDefault(require("./databases/ClearMetadataDatabase"));
14
10
  var _MigrateAssetSetting = _interopRequireDefault(require("./databases/MigrateAssetSetting"));
15
11
  var _MigrateEarningVersion = _interopRequireDefault(require("./databases/MigrateEarningVersion"));
12
+ var _ReloadMetadata = _interopRequireDefault(require("./databases/ReloadMetadata"));
16
13
  var _MigrateEthProvider = _interopRequireDefault(require("./providers/MigrateEthProvider"));
17
14
  var _MigratePioneerProvider = _interopRequireDefault(require("./providers/MigratePioneerProvider"));
18
15
  var _MigrateProvidersV1M1P = _interopRequireDefault(require("./providers/MigrateProvidersV1M1P24"));
@@ -20,6 +17,7 @@ var _MigratePolygonUSDCProvider = _interopRequireDefault(require("./tokens/Migra
20
17
  var _AutoEnableChainsTokens = _interopRequireDefault(require("./AutoEnableChainsTokens"));
21
18
  var _DeleteChain = _interopRequireDefault(require("./DeleteChain"));
22
19
  var _DeleteChainStaking = _interopRequireDefault(require("./DeleteChainStaking"));
20
+ var _DeleteEarningData = _interopRequireDefault(require("./DeleteEarningData"));
23
21
  var _EnableVaraChain = _interopRequireDefault(require("./EnableVaraChain"));
24
22
  var _MigrateAuthUrls = _interopRequireDefault(require("./MigrateAuthUrls"));
25
23
  var _MigrateAutoLock = _interopRequireDefault(require("./MigrateAutoLock"));
@@ -28,9 +26,11 @@ var _MigrateImportedToken = _interopRequireDefault(require("./MigrateImportedTok
28
26
  var _MigrateLedgerAccount = _interopRequireDefault(require("./MigrateLedgerAccount"));
29
27
  var _MigrateLedgerAccountV = _interopRequireDefault(require("./MigrateLedgerAccountV2"));
30
28
  var _MigrateNetworkSettings = _interopRequireDefault(require("./MigrateNetworkSettings"));
29
+ var _MigrateRemoveGenesisHash = _interopRequireDefault(require("./MigrateRemoveGenesisHash"));
31
30
  var _MigrateSettings = _interopRequireDefault(require("./MigrateSettings"));
32
31
  var _MigrateTokenDecimals = _interopRequireDefault(require("./MigrateTokenDecimals"));
33
32
  var _MigrateTransactionHistory = _interopRequireDefault(require("./MigrateTransactionHistory"));
33
+ var _MigrateTransactionHistoryBySymbol = _interopRequireDefault(require("./MigrateTransactionHistoryBySymbol"));
34
34
  var _MigrateWalletReference = _interopRequireDefault(require("./MigrateWalletReference"));
35
35
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
36
36
  // SPDX-License-Identifier: Apache-2.0
@@ -64,8 +64,8 @@ var _default = {
64
64
  '1.1.69-03': _MigrateAssetSetting.default,
65
65
  '1.1.69-02': _MigrateTransactionHistoryBySymbol.default,
66
66
  '1.2.69-01': _MigrateRemoveGenesisHash.default,
67
- '1.2.1-01': _ClearMetadataDatabase.default,
68
- '1.2.13-01': _ReloadMetadata.default
67
+ '1.2.13-01': _ReloadMetadata.default,
68
+ '1.2.14-01': _ClearMetadataDatabase.default
69
69
  // [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
70
70
  // [`${EVERYTIME}-1`]: AutoEnableChainsTokens
71
71
  };
@@ -1047,20 +1047,25 @@ class TransactionService {
1047
1047
  const signerOption = {
1048
1048
  signer: {
1049
1049
  signPayload: async payload => {
1050
- const signing = await this.state.requestService.signInternalTransaction(id, address, url || _constants2.EXTENSION_REQUEST_URL, payload);
1050
+ const {
1051
+ signature,
1052
+ signedTransaction
1053
+ } = await this.state.requestService.signInternalTransaction(id, address, url || _constants2.EXTENSION_REQUEST_URL, payload);
1051
1054
  return {
1052
1055
  id: new Date().getTime(),
1053
- signature: signing.signature
1056
+ signature,
1057
+ signedTransaction
1054
1058
  };
1055
1059
  }
1056
- }
1060
+ },
1061
+ withSignedTransaction: true
1057
1062
  };
1058
1063
  if ((0, _utils3._isRuntimeUpdated)(signedExtensions)) {
1059
- try {
1060
- const metadataHash = await (0, _utils3.getMetadataHash)(chain);
1064
+ const metadataHash = await this.state.chainService.calculateMetadataHash(chain);
1065
+ if (metadataHash) {
1061
1066
  signerOption.mode = 1;
1062
- signerOption.metadataHash = `0x${metadataHash}`;
1063
- } catch (e) {}
1067
+ signerOption.metadataHash = metadataHash;
1068
+ }
1064
1069
  }
1065
1070
  extrinsic.signAsync(address, signerOption).then(async rs => {
1066
1071
  // Emit signed event
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.GEAR_DEFAULT_ADDRESS = exports.DEFAULT_GEAR_ADDRESS = void 0;
7
+ exports.getGRC20ContractPromise = getGRC20ContractPromise;
8
+ exports.getVFTContractPromise = getVFTContractPromise;
9
+ var _grc = require("./grc20");
10
+ var _vft = require("./vft");
11
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
12
+ // SPDX-License-Identifier: Apache-2.0
13
+
14
+ const DEFAULT_GEAR_ADDRESS = {
15
+ ALICE: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
16
+ BOB: '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'
17
+ };
18
+ exports.DEFAULT_GEAR_ADDRESS = DEFAULT_GEAR_ADDRESS;
19
+ const GEAR_DEFAULT_ADDRESS = '5EYCAe5ijiYfAXEth5DGRKiKuVjTXQKr877tUPz6eLz2t9aG';
20
+ exports.GEAR_DEFAULT_ADDRESS = GEAR_DEFAULT_ADDRESS;
21
+ function getGRC20ContractPromise(apiPromise, contractAddress) {
22
+ const gearApi = apiPromise;
23
+ return new _grc.GRC20(gearApi, contractAddress);
24
+ }
25
+ function getVFTContractPromise(apiPromise, contractAddress) {
26
+ const gearApi = apiPromise;
27
+ return new _vft.VFT(gearApi, contractAddress);
28
+ }
@@ -3,21 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.GRC20 = exports.DEFAULT_GEAR_ADDRESS = void 0;
7
- exports.getGRC20ContractPromise = getGRC20ContractPromise;
6
+ exports.Grc20Service = exports.GRC20 = void 0;
8
7
  var _api = require("@gear-js/api");
9
8
  var _sailsJs = require("sails-js");
10
9
  var _types = require("@polkadot/types");
11
- // Copyright 2019-2022 @subwallet/extension-base
10
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
12
11
  // SPDX-License-Identifier: Apache-2.0
13
12
 
14
- // https://github.com/breathx/gear-erc20/blob/master/js/src/lib.ts
15
-
16
- const DEFAULT_GEAR_ADDRESS = {
17
- ALICE: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
18
- BOB: '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'
19
- };
20
- exports.DEFAULT_GEAR_ADDRESS = DEFAULT_GEAR_ADDRESS;
21
13
  class GRC20 {
22
14
  constructor(api) {
23
15
  let programId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0x';
@@ -32,6 +24,7 @@ class GRC20 {
32
24
  types
33
25
  });
34
26
  this.registry.register(types);
27
+ this.service = new Grc20Service(this);
35
28
  }
36
29
  newCtorFromCode(code, name, symbol, decimals) {
37
30
  const builder = new _sailsJs.TransactionBuilder(this.api, this.registry, 'upload_program', ['New', name, symbol, decimals], '(String, String, String, u8)', 'String', code);
@@ -43,99 +36,113 @@ class GRC20 {
43
36
  this.programId = builder.programId;
44
37
  return builder;
45
38
  }
39
+ }
40
+ exports.GRC20 = GRC20;
41
+ class Grc20Service {
42
+ constructor(_program) {
43
+ this._program = _program;
44
+ }
46
45
  approve(spender, value) {
47
- return new _sailsJs.TransactionBuilder(this.api, this.registry, 'send_message', ['Approve', spender, value], '(String, ActorId, U256)', 'bool', this.programId);
46
+ if (!this._program.programId) {
47
+ throw new Error('Program ID is not set');
48
+ }
49
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Approve', spender, value], '(String, ActorId, U256)', 'bool', this._program.programId);
48
50
  }
49
51
  fromTransfer(from, to, value) {
50
- return new _sailsJs.TransactionBuilder(this.api, this.registry, 'send_message', ['FromTransfer', from, to, value], '(String, ActorId, ActorId, U256)', 'bool', this.programId);
52
+ if (!this._program.programId) {
53
+ throw new Error('Program ID is not set');
54
+ }
55
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['FromTransfer', from, to, value], '(String, ActorId, ActorId, U256)', 'bool', this._program.programId);
51
56
  }
52
57
  setBalance(newBalance) {
53
- return new _sailsJs.TransactionBuilder(this.api, this.registry, 'send_message', ['SetBalance', newBalance], '(String, U256)', 'bool', this.programId);
58
+ if (!this._program.programId) {
59
+ throw new Error('Program ID is not set');
60
+ }
61
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['SetBalance', newBalance], '(String, U256)', 'bool', this._program.programId);
54
62
  }
55
63
  transfer(to, value) {
56
- return new _sailsJs.TransactionBuilder(this.api, this.registry, 'send_message', ['Transfer', to, value], '(String, ActorId, U256)', 'bool', this.programId);
64
+ if (!this._program.programId) {
65
+ throw new Error('Program ID is not set');
66
+ }
67
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Transfer', to, value], '(String, ActorId, U256)', 'bool', this._program.programId);
57
68
  }
58
69
  async allowance(owner, spender, originAddress, value, atBlock) {
59
- const payload = this.registry.createType('(String, ActorId, ActorId)', ['Allowance', owner, spender]).toU8a();
60
- const reply = await this.api.message.calculateReply({
61
- destination: this.programId,
70
+ const payload = this._program.registry.createType('(String, ActorId, ActorId)', ['Allowance', owner, spender]).toHex();
71
+ const reply = await this._program.api.message.calculateReply({
72
+ destination: this._program.programId,
62
73
  origin: (0, _api.decodeAddress)(originAddress),
63
74
  payload,
64
75
  value: value || 0,
65
- gasLimit: this.api.blockGasLimit.toBigInt(),
76
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
66
77
  at: atBlock
67
78
  });
68
- const result = this.registry.createType('(String, U256)', reply.payload);
79
+ const result = this._program.registry.createType('(String, U256)', reply.payload);
69
80
  return result[1].toBigInt();
70
81
  }
71
82
  async balanceOf(owner, originAddress, value, atBlock) {
72
- const payload = this.registry.createType('(String, ActorId)', ['BalanceOf', owner]).toU8a();
73
- const reply = await this.api.message.calculateReply({
74
- destination: this.programId,
83
+ const payload = this._program.registry.createType('(String, ActorId)', ['BalanceOf', owner]).toHex();
84
+ const reply = await this._program.api.message.calculateReply({
85
+ destination: this._program.programId,
75
86
  origin: (0, _api.decodeAddress)(originAddress),
76
87
  payload,
77
88
  value: value || 0,
78
- gasLimit: this.api.blockGasLimit.toBigInt(),
89
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
79
90
  at: atBlock
80
91
  });
81
- const result = this.registry.createType('(String, U256)', reply.payload);
92
+ const result = this._program.registry.createType('(String, U256)', reply.payload);
82
93
  return result[1].toBigInt();
83
94
  }
84
95
  async decimals(originAddress, value, atBlock) {
85
- const payload = this.registry.createType('String', 'Decimals').toU8a();
86
- const reply = await this.api.message.calculateReply({
87
- destination: this.programId,
96
+ const payload = this._program.registry.createType('String', 'Decimals').toHex();
97
+ const reply = await this._program.api.message.calculateReply({
98
+ destination: this._program.programId,
88
99
  origin: (0, _api.decodeAddress)(originAddress),
89
100
  payload,
90
101
  value: value || 0,
91
- gasLimit: this.api.blockGasLimit.toBigInt(),
102
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
92
103
  at: atBlock
93
104
  });
94
- const result = this.registry.createType('(String, u8)', reply.payload);
105
+ const result = this._program.registry.createType('(String, u8)', reply.payload);
95
106
  return result[1].toNumber();
96
107
  }
97
108
  async name(originAddress, value, atBlock) {
98
- const payload = this.registry.createType('String', 'Name').toU8a();
99
- const reply = await this.api.message.calculateReply({
100
- destination: this.programId,
109
+ const payload = this._program.registry.createType('String', 'Name').toHex();
110
+ const reply = await this._program.api.message.calculateReply({
111
+ destination: this._program.programId,
101
112
  origin: (0, _api.decodeAddress)(originAddress),
102
113
  payload,
103
114
  value: value || 0,
104
- gasLimit: this.api.blockGasLimit.toBigInt(),
115
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
105
116
  at: atBlock
106
117
  });
107
- const result = this.registry.createType('(String, String)', reply.payload);
118
+ const result = this._program.registry.createType('(String, String)', reply.payload);
108
119
  return result[1].toString();
109
120
  }
110
121
  async symbol(originAddress, value, atBlock) {
111
- const payload = this.registry.createType('String', 'Symbol').toU8a();
112
- const reply = await this.api.message.calculateReply({
113
- destination: this.programId,
122
+ const payload = this._program.registry.createType('String', 'Symbol').toHex();
123
+ const reply = await this._program.api.message.calculateReply({
124
+ destination: this._program.programId,
114
125
  origin: (0, _api.decodeAddress)(originAddress),
115
126
  payload,
116
127
  value: value || 0,
117
- gasLimit: this.api.blockGasLimit.toBigInt(),
128
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
118
129
  at: atBlock
119
130
  });
120
- const result = this.registry.createType('(String, String)', reply.payload);
131
+ const result = this._program.registry.createType('(String, String)', reply.payload);
121
132
  return result[1].toString();
122
133
  }
123
134
  async totalSupply(originAddress, value, atBlock) {
124
- const payload = this.registry.createType('String', 'TotalSupply').toU8a();
125
- const reply = await this.api.message.calculateReply({
126
- destination: this.programId,
135
+ const payload = this._program.registry.createType('String', 'TotalSupply').toHex();
136
+ const reply = await this._program.api.message.calculateReply({
137
+ destination: this._program.programId,
127
138
  origin: (0, _api.decodeAddress)(originAddress),
128
139
  payload,
129
140
  value: value || 0,
130
- gasLimit: this.api.blockGasLimit.toBigInt(),
141
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
131
142
  at: atBlock
132
143
  });
133
- const result = this.registry.createType('(String, U256)', reply.payload);
144
+ const result = this._program.registry.createType('(String, U256)', reply.payload);
134
145
  return result[1].toBigInt();
135
146
  }
136
147
  }
137
- exports.GRC20 = GRC20;
138
- function getGRC20ContractPromise(apiPromise, contractAddress) {
139
- const gearApi = apiPromise;
140
- return new GRC20(gearApi, contractAddress);
141
- }
148
+ exports.Grc20Service = Grc20Service;
@@ -3,6 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _combine = require("./combine");
7
+ Object.keys(_combine).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _combine[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _combine[key];
14
+ }
15
+ });
16
+ });
6
17
  var _grc = require("./grc20");
7
18
  Object.keys(_grc).forEach(function (key) {
8
19
  if (key === "default" || key === "__esModule") return;
@@ -13,4 +24,15 @@ Object.keys(_grc).forEach(function (key) {
13
24
  return _grc[key];
14
25
  }
15
26
  });
27
+ });
28
+ var _vft = require("./vft");
29
+ Object.keys(_vft).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _vft[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _vft[key];
36
+ }
37
+ });
16
38
  });
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VftService = exports.VFT = void 0;
7
+ var _api = require("@gear-js/api");
8
+ var _sailsJs = require("sails-js");
9
+ var _types = require("@polkadot/types");
10
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ class VFT {
14
+ constructor(api) {
15
+ let programId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0x';
16
+ this.api = api;
17
+ this.programId = programId;
18
+ const types = {};
19
+ this.registry = new _types.TypeRegistry();
20
+ this.registry.setKnownTypes({
21
+ types
22
+ });
23
+ this.registry.register(types);
24
+ this.service = new VftService(this);
25
+ }
26
+ newCtorFromCode(code, name, symbol, decimals) {
27
+ const builder = new _sailsJs.TransactionBuilder(this.api, this.registry, 'upload_program', ['New', name, symbol, decimals], '(String, String, String, u8)', 'String', code);
28
+ this.programId = builder.programId;
29
+ return builder;
30
+ }
31
+ newCtorFromCodeId(codeId, name, symbol, decimals) {
32
+ const builder = new _sailsJs.TransactionBuilder(this.api, this.registry, 'create_program', ['New', name, symbol, decimals], '(String, String, String, u8)', 'String', codeId);
33
+ this.programId = builder.programId;
34
+ return builder;
35
+ }
36
+ }
37
+ exports.VFT = VFT;
38
+ class VftService {
39
+ constructor(_program) {
40
+ this._program = _program;
41
+ }
42
+ approve(spender, value) {
43
+ if (!this._program.programId) {
44
+ throw new Error('Program ID is not set');
45
+ }
46
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Vft', 'Approve', spender, value], '(String, String, [u8;32], U256)', 'bool', this._program.programId);
47
+ }
48
+ transfer(to, value) {
49
+ if (!this._program.programId) {
50
+ throw new Error('Program ID is not set');
51
+ }
52
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Vft', 'Transfer', to, value], '(String, String, [u8;32], U256)', 'bool', this._program.programId);
53
+ }
54
+ transferFrom(from, to, value) {
55
+ if (!this._program.programId) {
56
+ throw new Error('Program ID is not set');
57
+ }
58
+ return new _sailsJs.TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Vft', 'TransferFrom', from, to, value], '(String, String, [u8;32], [u8;32], U256)', 'bool', this._program.programId);
59
+ }
60
+ async allowance(owner, spender, originAddress, value, atBlock) {
61
+ const payload = this._program.registry.createType('(String, String, [u8;32], [u8;32])', ['Vft', 'Allowance', owner, spender]).toHex();
62
+ const reply = await this._program.api.message.calculateReply({
63
+ destination: this._program.programId,
64
+ origin: (0, _api.decodeAddress)(originAddress),
65
+ payload,
66
+ value: value || 0,
67
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
68
+ at: atBlock
69
+ });
70
+ const result = this._program.registry.createType('(String, String, U256)', reply.payload);
71
+ return result[2].toBigInt();
72
+ }
73
+ async balanceOf(account, originAddress, value, atBlock) {
74
+ const payload = this._program.registry.createType('(String, String, [u8;32])', ['Vft', 'BalanceOf', account]).toHex();
75
+ const reply = await this._program.api.message.calculateReply({
76
+ destination: this._program.programId,
77
+ origin: (0, _api.decodeAddress)(originAddress),
78
+ payload,
79
+ value: value || 0,
80
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
81
+ at: atBlock
82
+ });
83
+ const result = this._program.registry.createType('(String, String, U256)', reply.payload);
84
+ return result[2].toBigInt();
85
+ }
86
+ async decimals(originAddress, value, atBlock) {
87
+ const payload = this._program.registry.createType('(String, String)', ['Vft', 'Decimals']).toHex();
88
+ const reply = await this._program.api.message.calculateReply({
89
+ destination: this._program.programId,
90
+ origin: (0, _api.decodeAddress)(originAddress),
91
+ payload,
92
+ value: value || 0,
93
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
94
+ at: atBlock
95
+ });
96
+ const result = this._program.registry.createType('(String, String, u8)', reply.payload);
97
+ return result[2].toNumber();
98
+ }
99
+ async name(originAddress, value, atBlock) {
100
+ const payload = this._program.registry.createType('(String, String)', ['Vft', 'Name']).toHex();
101
+ const reply = await this._program.api.message.calculateReply({
102
+ destination: this._program.programId,
103
+ origin: (0, _api.decodeAddress)(originAddress),
104
+ payload,
105
+ value: value || 0,
106
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
107
+ at: atBlock
108
+ });
109
+ const result = this._program.registry.createType('(String, String, String)', reply.payload);
110
+ return result[2].toString();
111
+ }
112
+ async symbol(originAddress, value, atBlock) {
113
+ const payload = this._program.registry.createType('(String, String)', ['Vft', 'Symbol']).toHex();
114
+ const reply = await this._program.api.message.calculateReply({
115
+ destination: this._program.programId,
116
+ origin: (0, _api.decodeAddress)(originAddress),
117
+ payload,
118
+ value: value || 0,
119
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
120
+ at: atBlock
121
+ });
122
+ const result = this._program.registry.createType('(String, String, String)', reply.payload);
123
+ return result[2].toString();
124
+ }
125
+ async totalSupply(originAddress, value, atBlock) {
126
+ const payload = this._program.registry.createType('(String, String)', ['Vft', 'TotalSupply']).toHex();
127
+ const reply = await this._program.api.message.calculateReply({
128
+ destination: this._program.programId,
129
+ origin: (0, _api.decodeAddress)(originAddress),
130
+ payload,
131
+ value: value || 0,
132
+ gasLimit: this._program.api.blockGasLimit.toBigInt(),
133
+ at: atBlock
134
+ });
135
+ const result = this._program.registry.createType('(String, String, U256)', reply.payload);
136
+ return result[2].toBigInt();
137
+ }
138
+ subscribeToApprovalEvent(callback) {
139
+ return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', _ref => {
140
+ let {
141
+ data: {
142
+ message
143
+ }
144
+ } = _ref;
145
+ if (!message.source.eq(this._program.programId) || !message.destination.eq(_sailsJs.ZERO_ADDRESS)) {
146
+ return;
147
+ }
148
+ const payload = message.payload.toHex();
149
+ if ((0, _sailsJs.getServiceNamePrefix)(payload) === 'Vft' && (0, _sailsJs.getFnNamePrefix)(payload) === 'Approval') {
150
+ // eslint-disable-next-line node/no-callback-literal,@typescript-eslint/no-floating-promises
151
+ callback(this._program.registry.createType('(String, String, {"owner":"[u8;32]","spender":"[u8;32]","value":"U256"})', message.payload)[2].toJSON());
152
+ }
153
+ });
154
+ }
155
+ subscribeToTransferEvent(callback) {
156
+ return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', _ref2 => {
157
+ let {
158
+ data: {
159
+ message
160
+ }
161
+ } = _ref2;
162
+ if (!message.source.eq(this._program.programId) || !message.destination.eq(_sailsJs.ZERO_ADDRESS)) {
163
+ return;
164
+ }
165
+ const payload = message.payload.toHex();
166
+ if ((0, _sailsJs.getServiceNamePrefix)(payload) === 'Service' && (0, _sailsJs.getFnNamePrefix)(payload) === 'Transfer') {
167
+ // eslint-disable-next-line node/no-callback-literal,@typescript-eslint/no-floating-promises
168
+ callback(this._program.registry.createType('(String, String, {"from":"[u8;32]","to":"[u8;32]","value":"U256"})', message.payload)[2].toJSON());
169
+ }
170
+ });
171
+ }
172
+ }
173
+ exports.VftService = VftService;