@subwallet/extension-base 1.3.45-1 → 1.3.47-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 (128) hide show
  1. package/background/KoniTypes.d.ts +5 -0
  2. package/background/KoniTypes.js +5 -0
  3. package/background/types.d.ts +2 -0
  4. package/cjs/background/KoniTypes.js +7 -1
  5. package/cjs/core/logic-validation/request.js +55 -28
  6. package/cjs/core/utils.js +22 -0
  7. package/cjs/koni/api/nft/ordinal_nft/index.js +3 -2
  8. package/cjs/koni/background/handlers/Extension.js +84 -61
  9. package/cjs/koni/background/handlers/State.js +3 -0
  10. package/cjs/koni/background/handlers/Tabs.js +11 -3
  11. package/cjs/packageInfo.js +1 -1
  12. package/cjs/page/evm/index.js +64 -105
  13. package/cjs/page/index.js +5 -3
  14. package/cjs/page/substrate/Accounts.js +2 -1
  15. package/cjs/services/balance-service/helpers/subscribe/index.js +3 -76
  16. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +8 -14
  17. package/cjs/services/buy-service/index.js +2 -0
  18. package/cjs/services/chain-service/index.js +3 -0
  19. package/cjs/services/chain-service/utils/index.js +34 -1
  20. package/cjs/services/chain-service/utils/patch.js +1 -1
  21. package/cjs/services/earning-service/constants/chains.js +2 -1
  22. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +32 -0
  23. package/cjs/services/earning-service/handlers/native-staking/astar.js +18 -0
  24. package/cjs/services/earning-service/handlers/native-staking/base.js +40 -29
  25. package/cjs/services/earning-service/handlers/native-staking/dtao.js +5 -0
  26. package/cjs/services/earning-service/handlers/native-staking/mythos.js +28 -0
  27. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +17 -0
  28. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +25 -2
  29. package/cjs/services/earning-service/handlers/native-staking/tao.js +5 -0
  30. package/cjs/services/earning-service/handlers/nomination-pool/index.js +6 -3
  31. package/cjs/services/earning-service/service.js +65 -22
  32. package/cjs/services/history-service/index.js +12 -7
  33. package/cjs/services/keyring-service/context/handlers/Json.js +2 -1
  34. package/cjs/services/keyring-service/context/handlers/Ledger.js +7 -2
  35. package/cjs/services/request-service/handler/AuthRequestHandler.js +30 -6
  36. package/cjs/services/subscan-service/index.js +35 -104
  37. package/cjs/services/transaction-service/utils.js +10 -1
  38. package/cjs/strategy/api-request-strategy/index.js +1 -0
  39. package/cjs/strategy/api-request-strategy/utils/index.js +2 -2
  40. package/cjs/strategy/api-request-strategy-v2/index.js +138 -0
  41. package/cjs/strategy/api-request-strategy-v2/types.js +1 -0
  42. package/cjs/types/account/info/keyring.js +1 -0
  43. package/cjs/utils/account/analyze.js +5 -2
  44. package/cjs/utils/account/common.js +93 -2
  45. package/cjs/utils/account/transform.js +10 -0
  46. package/cjs/utils/asset.js +9 -2
  47. package/cjs/utils/gear/combine.js +4 -3
  48. package/cjs/utils/gear/vft.js +104 -135
  49. package/cjs/utils/staticData/index.js +7 -2
  50. package/core/logic-validation/request.js +31 -4
  51. package/core/types.d.ts +3 -2
  52. package/core/utils.js +24 -2
  53. package/koni/api/nft/ordinal_nft/index.js +3 -2
  54. package/koni/background/handlers/Extension.js +31 -8
  55. package/koni/background/handlers/State.js +4 -1
  56. package/koni/background/handlers/Tabs.js +11 -4
  57. package/package.json +21 -9
  58. package/packageInfo.js +1 -1
  59. package/page/evm/index.d.ts +9 -18
  60. package/page/evm/index.js +62 -101
  61. package/page/index.js +5 -3
  62. package/page/substrate/Accounts.js +2 -1
  63. package/services/balance-service/helpers/subscribe/index.d.ts +1 -11
  64. package/services/balance-service/helpers/subscribe/index.js +3 -74
  65. package/services/balance-service/helpers/subscribe/substrate/index.js +8 -14
  66. package/services/buy-service/index.js +2 -0
  67. package/services/chain-service/index.d.ts +1 -0
  68. package/services/chain-service/index.js +3 -0
  69. package/services/chain-service/utils/index.d.ts +10 -2
  70. package/services/chain-service/utils/index.js +29 -2
  71. package/services/chain-service/utils/patch.js +1 -1
  72. package/services/earning-service/constants/chains.d.ts +1 -0
  73. package/services/earning-service/constants/chains.js +2 -1
  74. package/services/earning-service/handlers/native-staking/amplitude.d.ts +1 -0
  75. package/services/earning-service/handlers/native-staking/amplitude.js +32 -0
  76. package/services/earning-service/handlers/native-staking/astar.d.ts +1 -0
  77. package/services/earning-service/handlers/native-staking/astar.js +18 -0
  78. package/services/earning-service/handlers/native-staking/base.d.ts +2 -0
  79. package/services/earning-service/handlers/native-staking/base.js +40 -29
  80. package/services/earning-service/handlers/native-staking/dtao.d.ts +1 -0
  81. package/services/earning-service/handlers/native-staking/dtao.js +5 -0
  82. package/services/earning-service/handlers/native-staking/mythos.d.ts +1 -0
  83. package/services/earning-service/handlers/native-staking/mythos.js +28 -0
  84. package/services/earning-service/handlers/native-staking/para-chain.d.ts +1 -0
  85. package/services/earning-service/handlers/native-staking/para-chain.js +17 -0
  86. package/services/earning-service/handlers/native-staking/relay-chain.d.ts +1 -0
  87. package/services/earning-service/handlers/native-staking/relay-chain.js +25 -2
  88. package/services/earning-service/handlers/native-staking/tao.d.ts +1 -0
  89. package/services/earning-service/handlers/native-staking/tao.js +5 -0
  90. package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -0
  91. package/services/earning-service/handlers/nomination-pool/index.js +6 -3
  92. package/services/earning-service/service.d.ts +3 -0
  93. package/services/earning-service/service.js +68 -25
  94. package/services/history-service/index.js +12 -7
  95. package/services/keyring-service/context/handlers/Json.js +2 -1
  96. package/services/keyring-service/context/handlers/Ledger.js +7 -2
  97. package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
  98. package/services/request-service/handler/AuthRequestHandler.js +30 -6
  99. package/services/request-service/types.d.ts +1 -0
  100. package/services/subscan-service/index.d.ts +13 -27
  101. package/services/subscan-service/index.js +26 -95
  102. package/services/transaction-service/utils.js +11 -2
  103. package/strategy/api-request-strategy/context/base.d.ts +2 -6
  104. package/strategy/api-request-strategy/index.js +1 -0
  105. package/strategy/api-request-strategy/types.d.ts +4 -2
  106. package/strategy/api-request-strategy/utils/index.js +2 -2
  107. package/strategy/api-request-strategy-v2/index.d.ts +22 -0
  108. package/strategy/api-request-strategy-v2/index.js +128 -0
  109. package/strategy/api-request-strategy-v2/types.d.ts +11 -0
  110. package/strategy/api-request-strategy-v2/types.js +1 -0
  111. package/types/account/action/subscribe.d.ts +3 -0
  112. package/types/account/info/keyring.d.ts +3 -0
  113. package/types/account/info/keyring.js +1 -0
  114. package/types/balance/transfer.d.ts +1 -0
  115. package/types/buy.d.ts +1 -1
  116. package/utils/account/analyze.js +5 -2
  117. package/utils/account/common.d.ts +13 -1
  118. package/utils/account/common.js +91 -2
  119. package/utils/account/transform.js +10 -0
  120. package/utils/asset.d.ts +2 -1
  121. package/utils/asset.js +7 -1
  122. package/utils/gear/combine.d.ts +2 -1
  123. package/utils/gear/combine.js +4 -4
  124. package/utils/gear/vft.d.ts +20 -9
  125. package/utils/gear/vft.js +104 -135
  126. package/utils/staticData/assetHubStaking.json +1 -0
  127. package/utils/staticData/index.d.ts +4 -1
  128. package/utils/staticData/index.js +5 -1
@@ -2,11 +2,12 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
5
- import { _chainInfoToChainType, _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
5
+ import { _chainInfoToChainType, _getChainSubstrateAddressPrefix, _getSubstrateGenesisHash, _isChainBitcoinCompatible, _isChainCardanoCompatible, _isChainEvmCompatible, _isChainTonCompatible, _isSubstrateEvmCompatibleChain } from '@subwallet/extension-base/services/chain-service/utils';
6
6
  import { AccountChainType } from '@subwallet/extension-base/types';
7
- import { getAccountChainTypeFromKeypairType } from '@subwallet/extension-base/utils';
7
+ import { getAccountChainTypeFromKeypairType, pairToAccount } from '@subwallet/extension-base/utils';
8
8
  import { decodeAddress, encodeAddress, getKeypairTypeByAddress, isAddress, isBitcoinAddress, isCardanoAddress, isTonAddress } from '@subwallet/keyring';
9
9
  import { getBitcoinAddressInfo } from '@subwallet/keyring/utils/address/validate';
10
+ import { keyring } from '@subwallet/ui-keyring';
10
11
  import { ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
11
12
  export function isAccountAll(address) {
12
13
  return address === ALL_ACCOUNT_KEY;
@@ -123,4 +124,92 @@ export const modifyAccountName = (type, name, modify) => {
123
124
  break;
124
125
  }
125
126
  return network ? [name, network].join(' - ') : name;
127
+ };
128
+
129
+ /**
130
+ * @function getAccountJsonByAddress
131
+ * @desc Get account info by address
132
+ * <p>
133
+ * Note: Use on the background only
134
+ * </p>
135
+ * @param {string} address - Address
136
+ * @returns {AccountJson|null} - Account info or null if not found
137
+ */
138
+ export const getAccountJsonByAddress = address => {
139
+ try {
140
+ const pair = keyring.getPair(address);
141
+ if (pair) {
142
+ return pairToAccount(pair);
143
+ } else {
144
+ return null;
145
+ }
146
+ } catch (e) {
147
+ console.warn(e);
148
+ return null;
149
+ }
150
+ };
151
+
152
+ /** Filter addresses to subscribe by chain info */
153
+ export const filterAddressByChainInfo = (addresses, chainInfo) => {
154
+ const {
155
+ _bitcoin,
156
+ bitcoin,
157
+ cardano,
158
+ evm,
159
+ substrate,
160
+ ton
161
+ } = getAddressesByChainTypeMap(addresses, chainInfo);
162
+ if (_isChainEvmCompatible(chainInfo)) {
163
+ const [fetchList, unFetchList] = processEvmAndSubstrateAddresses(evm, chainInfo);
164
+ return [fetchList, [...unFetchList, ...bitcoin, ...ton, ...substrate, ...cardano, ..._bitcoin].flat()];
165
+ } else if (_isChainBitcoinCompatible(chainInfo)) {
166
+ return [bitcoin, [...evm, ...substrate, ...ton, ...cardano, ..._bitcoin].flat()];
167
+ } else if (_isChainTonCompatible(chainInfo)) {
168
+ return [ton, [...bitcoin, ...evm, ...substrate, ...cardano, ..._bitcoin].flat()];
169
+ } else if (_isChainCardanoCompatible(chainInfo)) {
170
+ return [cardano, [...bitcoin, ...evm, ...substrate, ...ton, ..._bitcoin].flat()];
171
+ } else {
172
+ const [fetchList, unFetchList] = processEvmAndSubstrateAddresses(substrate, chainInfo);
173
+ return [fetchList, [...unFetchList, ...bitcoin, ...evm, ...ton, ...cardano, ..._bitcoin].flat()];
174
+ }
175
+ };
176
+ const processEvmAndSubstrateAddresses = (addressList, chainInfo) => {
177
+ const fetchList = [];
178
+ const unFetchList = [];
179
+ const isEvm = isEthereumAddress(addressList[0]);
180
+ addressList.forEach(address => {
181
+ const account = getAccountJsonByAddress(address);
182
+ if (account) {
183
+ if (account.isHardware) {
184
+ if (isEvm) {
185
+ if (account.isGeneric && account.isSubstrateECDSA) {
186
+ if (_isSubstrateEvmCompatibleChain(chainInfo)) {
187
+ fetchList.push(address);
188
+ } else {
189
+ unFetchList.push(address);
190
+ }
191
+ } else {
192
+ fetchList.push(address);
193
+ }
194
+ } else {
195
+ if (account.isGeneric) {
196
+ fetchList.push(address);
197
+ } else {
198
+ const availGen = account.availableGenesisHashes || [];
199
+ const gen = _getSubstrateGenesisHash(chainInfo);
200
+ if (availGen.includes(gen)) {
201
+ fetchList.push(address);
202
+ } else {
203
+ unFetchList.push(address);
204
+ }
205
+ }
206
+ }
207
+ } else {
208
+ fetchList.push(address);
209
+ }
210
+ } else {
211
+ fetchList.push(address);
212
+ }
213
+ });
214
+ return [fetchList, unFetchList];
126
215
  };
@@ -62,6 +62,9 @@ export const getAccountSignMode = (address, _meta) => {
62
62
  if (meta.isExternal) {
63
63
  if (meta.isHardware) {
64
64
  if (meta.isGeneric) {
65
+ if (meta.isSubstrateECDSA) {
66
+ return AccountSignMode.ECDSA_SUBSTRATE_LEDGER;
67
+ }
65
68
  return AccountSignMode.GENERIC_LEDGER;
66
69
  } else {
67
70
  return AccountSignMode.LEGACY_LEDGER;
@@ -233,6 +236,11 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
233
236
  result.push(...CLAIM_AVAIL_BRIDGE);
234
237
  }
235
238
  return result;
239
+ } else if (signMode === AccountSignMode.ECDSA_SUBSTRATE_LEDGER) {
240
+ // Only for account substrate with ECDSA scheme format
241
+ const result = [];
242
+ result.push(...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ExtrinsicType.TRANSFER_XCM, ExtrinsicType.SWAP, ExtrinsicType.CROWDLOAN);
243
+ return result;
236
244
  }
237
245
  return [];
238
246
  };
@@ -352,6 +360,7 @@ export const convertAccountProxyType = accountSignMode => {
352
360
  switch (accountSignMode) {
353
361
  case AccountSignMode.GENERIC_LEDGER:
354
362
  case AccountSignMode.LEGACY_LEDGER:
363
+ case AccountSignMode.ECDSA_SUBSTRATE_LEDGER:
355
364
  return AccountProxyType.LEDGER;
356
365
  case AccountSignMode.QR:
357
366
  return AccountProxyType.QR;
@@ -460,6 +469,7 @@ export const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
460
469
  switch (account.signMode) {
461
470
  case AccountSignMode.GENERIC_LEDGER:
462
471
  case AccountSignMode.LEGACY_LEDGER:
472
+ case AccountSignMode.ECDSA_SUBSTRATE_LEDGER:
463
473
  specialChain = account.specialChain;
464
474
  break;
465
475
  }
package/utils/asset.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { _AssetType, _ChainAsset } from '@subwallet/chain-list/types';
1
+ import { _AssetType, _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
2
  export declare const filterAssetsByChainAndType: (chainAssetMap: Record<string, _ChainAsset>, chain: string, assetTypes: _AssetType[]) => Record<string, _ChainAsset>;
3
3
  export declare const filterAlphaAssetsByChain: (chainAssetMap: Record<string, _ChainAsset>, chain: string) => Record<string, _ChainAsset>;
4
+ export declare const isSubstrateEcdsaLedgerAssetSupported: (chainsAsset: _ChainAsset, chainInfo: _ChainInfo) => boolean;
package/utils/asset.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { _AssetType } from '@subwallet/chain-list/types';
5
- import { _getAssetNetuid } from '@subwallet/extension-base/services/chain-service/utils';
5
+ import { _getAssetNetuid, _getContractAddressOfToken, _isNativeToken, _isSubstrateEvmCompatibleChain } from '@subwallet/extension-base/services/chain-service/utils';
6
6
  export const filterAssetsByChainAndType = (chainAssetMap, chain, assetTypes) => {
7
7
  const result = {};
8
8
  Object.values(chainAssetMap).forEach(assetInfo => {
@@ -23,4 +23,10 @@ export const filterAlphaAssetsByChain = (chainAssetMap, chain) => {
23
23
  }
24
24
  });
25
25
  return result;
26
+ };
27
+ export const isSubstrateEcdsaLedgerAssetSupported = (chainsAsset, chainInfo) => {
28
+ if (!_isSubstrateEvmCompatibleChain(chainInfo)) {
29
+ return false;
30
+ }
31
+ return _isNativeToken(chainsAsset) || !_getContractAddressOfToken(chainsAsset);
26
32
  };
@@ -1,3 +1,4 @@
1
+ import { GearApi } from '@gear-js/api';
1
2
  import { ApiPromise } from '@polkadot/api';
2
3
  import { GRC20 } from './grc20';
3
4
  import { VFT } from './vft';
@@ -7,4 +8,4 @@ export declare const DEFAULT_GEAR_ADDRESS: {
7
8
  };
8
9
  export declare const GEAR_DEFAULT_ADDRESS = "5EYCAe5ijiYfAXEth5DGRKiKuVjTXQKr877tUPz6eLz2t9aG";
9
10
  export declare function getGRC20ContractPromise(apiPromise: ApiPromise, contractAddress: string): GRC20;
10
- export declare function getVFTContractPromise(apiPromise: ApiPromise, contractAddress: string): VFT;
11
+ export declare function getVFTContractPromise(api: GearApi, contractAddress?: string): VFT;
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { GRC20 } from "./grc20.js";
5
- import { VFT } from "./vft.js";
5
+ import { sailsCache, VFT } from "./vft.js";
6
6
  export const DEFAULT_GEAR_ADDRESS = {
7
7
  ALICE: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
8
8
  BOB: '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'
@@ -12,7 +12,7 @@ export function getGRC20ContractPromise(apiPromise, contractAddress) {
12
12
  const gearApi = apiPromise;
13
13
  return new GRC20(gearApi, contractAddress);
14
14
  }
15
- export function getVFTContractPromise(apiPromise, contractAddress) {
16
- const gearApi = apiPromise;
17
- return new VFT(gearApi, contractAddress);
15
+ export function getVFTContractPromise(api, contractAddress = '0x') {
16
+ const sails = sailsCache.get();
17
+ return new VFT(api, contractAddress, sails);
18
18
  }
@@ -1,19 +1,20 @@
1
1
  /// <reference types="node" />
2
2
  import { GearApi } from '@gear-js/api';
3
- import { ActorId, TransactionBuilder } from 'sails-js';
4
- import { TypeRegistry } from '@polkadot/types';
3
+ import { ActorId, Sails, TransactionBuilder } from 'sails-js';
5
4
  export declare class VFT {
6
- api: GearApi;
5
+ readonly api: GearApi;
7
6
  programId: `0x${string}`;
8
- readonly registry: TypeRegistry;
9
7
  readonly service: VftService;
10
- constructor(api: GearApi, programId?: `0x${string}`);
11
- newCtorFromCode(code: Uint8Array | Buffer, name: string, symbol: string, decimals: number): TransactionBuilder<null>;
12
- newCtorFromCodeId(codeId: `0x${string}`, name: string, symbol: string, decimals: number): TransactionBuilder<null>;
8
+ readonly sails: Sails;
9
+ constructor(api: GearApi, programId: `0x${string}`, sails: Sails);
10
+ newCtorFromCode(code: Uint8Array | Buffer, name: string, symbol: string, decimals: number): TransactionBuilder<any>;
11
+ newCtorFromCodeId(codeId: `0x${string}`, name: string, symbol: string, decimals: number): TransactionBuilder<any>;
13
12
  }
14
13
  export declare class VftService {
15
14
  private _program;
16
15
  constructor(_program: VFT);
16
+ private get functions();
17
+ private get queries();
17
18
  approve(spender: ActorId, value: number | string | bigint): TransactionBuilder<boolean>;
18
19
  transfer(to: ActorId, value: number | string | bigint): TransactionBuilder<boolean>;
19
20
  transferFrom(from: ActorId, to: ActorId, value: number | string | bigint): TransactionBuilder<boolean>;
@@ -26,11 +27,21 @@ export declare class VftService {
26
27
  subscribeToApprovalEvent(callback: (data: {
27
28
  owner: ActorId;
28
29
  spender: ActorId;
29
- value: number | string | bigint;
30
+ value: bigint;
30
31
  }) => void | Promise<void>): Promise<() => void>;
31
32
  subscribeToTransferEvent(callback: (data: {
32
33
  from: ActorId;
33
34
  to: ActorId;
34
- value: number | string | bigint;
35
+ value: bigint;
35
36
  }) => void | Promise<void>): Promise<() => void>;
36
37
  }
38
+ declare class SailsCache {
39
+ private static instance;
40
+ private sail;
41
+ private constructor();
42
+ static getInstance(): SailsCache;
43
+ init(): Promise<void>;
44
+ get(): Sails;
45
+ }
46
+ export declare const sailsCache: SailsCache;
47
+ export {};
package/utils/gear/vft.js CHANGED
@@ -1,28 +1,26 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { decodeAddress } from '@gear-js/api';
5
- import { getFnNamePrefix, getServiceNamePrefix, TransactionBuilder, ZERO_ADDRESS } from 'sails-js';
6
- import { TypeRegistry } from '@polkadot/types';
4
+ import { Sails } from 'sails-js';
5
+ import { SailsIdlParser } from 'sails-js-parser';
7
6
  export class VFT {
8
- constructor(api, programId = '0x') {
7
+ constructor(api, programId = '0x', sails) {
9
8
  this.api = api;
10
9
  this.programId = programId;
11
- const types = {};
12
- this.registry = new TypeRegistry();
13
- this.registry.setKnownTypes({
14
- types
15
- });
16
- this.registry.register(types);
10
+ this.sails = sails;
11
+ this.sails.setApi(api);
12
+ this.sails.setProgramId(programId);
17
13
  this.service = new VftService(this);
18
14
  }
19
15
  newCtorFromCode(code, name, symbol, decimals) {
20
- const builder = new TransactionBuilder(this.api, this.registry, 'upload_program', ['New', name, symbol, decimals], '(String, String, String, u8)', 'String', code);
16
+ const ctor = this.sails.ctors.New;
17
+ const builder = ctor.fromCode(code, name, symbol, decimals);
21
18
  this.programId = builder.programId;
22
19
  return builder;
23
20
  }
24
21
  newCtorFromCodeId(codeId, name, symbol, decimals) {
25
- const builder = new TransactionBuilder(this.api, this.registry, 'create_program', ['New', name, symbol, decimals], '(String, String, String, u8)', 'String', codeId);
22
+ const ctor = this.sails.ctors.New;
23
+ const builder = ctor.fromCodeId(codeId, name, symbol, decimals);
26
24
  this.programId = builder.programId;
27
25
  return builder;
28
26
  }
@@ -31,132 +29,103 @@ export class VftService {
31
29
  constructor(_program) {
32
30
  this._program = _program;
33
31
  }
32
+ get functions() {
33
+ return this._program.sails.services.Vft.functions;
34
+ }
35
+ get queries() {
36
+ return this._program.sails.services.Vft.queries;
37
+ }
34
38
  approve(spender, value) {
35
- if (!this._program.programId) {
36
- throw new Error('Program ID is not set');
37
- }
38
- return new TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Vft', 'Approve', spender, value], '(String, String, [u8;32], U256)', 'bool', this._program.programId);
39
+ return this.functions.Approve(spender, value);
39
40
  }
40
41
  transfer(to, value) {
41
- if (!this._program.programId) {
42
- throw new Error('Program ID is not set');
43
- }
44
- return new TransactionBuilder(this._program.api, this._program.registry, 'send_message', ['Vft', 'Transfer', to, value], '(String, String, [u8;32], U256)', 'bool', this._program.programId);
42
+ return this.functions.Transfer(to, value);
45
43
  }
46
44
  transferFrom(from, to, value) {
47
- if (!this._program.programId) {
48
- throw new Error('Program ID is not set');
45
+ return this.functions.TransferFrom(from, to, value);
46
+ }
47
+ allowance(owner, spender, originAddress, value, atBlock) {
48
+ return this.queries.Allowance(originAddress, BigInt(value || 0), atBlock, owner, spender);
49
+ }
50
+ balanceOf(account, originAddress, value, atBlock) {
51
+ return this.queries.BalanceOf(originAddress, BigInt(value || 0), atBlock, account);
52
+ }
53
+ decimals(originAddress, value, atBlock) {
54
+ return this.queries.Decimals(originAddress, BigInt(value || 0), atBlock);
55
+ }
56
+ name(originAddress, value, atBlock) {
57
+ return this.queries.Name(originAddress, BigInt(value || 0), atBlock);
58
+ }
59
+ symbol(originAddress, value, atBlock) {
60
+ return this.queries.Symbol(originAddress, BigInt(value || 0), atBlock);
61
+ }
62
+ totalSupply(originAddress, value, atBlock) {
63
+ return this.queries.TotalSupply(originAddress, BigInt(value || 0), atBlock);
64
+ }
65
+ async subscribeToApprovalEvent(callback) {
66
+ return this._program.sails.services.Vft.events.Approval.subscribe(callback);
67
+ }
68
+ async subscribeToTransferEvent(callback) {
69
+ return this._program.sails.services.Vft.events.Transfer.subscribe(callback);
70
+ }
71
+ }
72
+
73
+ // Cache sai
74
+ const vftIdl = `
75
+ constructor {
76
+ New : (name: str, symbol: str, decimals: u8);
77
+ };
78
+
79
+ service Vft {
80
+ Approve : (spender: actor_id, value: u256) -> bool;
81
+ Transfer : (to: actor_id, value: u256) -> bool;
82
+ TransferFrom : (from: actor_id, to: actor_id, value: u256) -> bool;
83
+
84
+ query Allowance : (owner: actor_id, spender: actor_id) -> u256;
85
+ query BalanceOf : (account: actor_id) -> u256;
86
+ query Decimals : () -> u8;
87
+ query Name : () -> str;
88
+ query Symbol : () -> str;
89
+ query TotalSupply : () -> u256;
90
+
91
+ events {
92
+ Approval: struct {
93
+ owner: actor_id,
94
+ spender: actor_id,
95
+ value: u256,
96
+ };
97
+ Transfer: struct {
98
+ from: actor_id,
99
+ to: actor_id,
100
+ value: u256,
101
+ };
102
+ }
103
+ };
104
+ `;
105
+ class SailsCache {
106
+ static instance = null;
107
+ sail = null;
108
+
109
+ // eslint-disable-next-line no-useless-constructor, @typescript-eslint/no-empty-function
110
+ constructor() {}
111
+ static getInstance() {
112
+ if (!SailsCache.instance) {
113
+ SailsCache.instance = new SailsCache();
49
114
  }
50
- return new 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);
51
- }
52
- async allowance(owner, spender, originAddress, value, atBlock) {
53
- const payload = this._program.registry.createType('(String, String, [u8;32], [u8;32])', ['Vft', 'Allowance', owner, spender]).toHex();
54
- const reply = await this._program.api.message.calculateReply({
55
- destination: this._program.programId,
56
- origin: decodeAddress(originAddress),
57
- payload,
58
- value: value || 0,
59
- gasLimit: this._program.api.blockGasLimit.toBigInt(),
60
- at: atBlock
61
- });
62
- const result = this._program.registry.createType('(String, String, U256)', reply.payload);
63
- return result[2].toBigInt();
64
- }
65
- async balanceOf(account, originAddress, value, atBlock) {
66
- const payload = this._program.registry.createType('(String, String, [u8;32])', ['Vft', 'BalanceOf', account]).toHex();
67
- const reply = await this._program.api.message.calculateReply({
68
- destination: this._program.programId,
69
- origin: decodeAddress(originAddress),
70
- payload,
71
- value: value || 0,
72
- gasLimit: this._program.api.blockGasLimit.toBigInt(),
73
- at: atBlock
74
- });
75
- const result = this._program.registry.createType('(String, String, U256)', reply.payload);
76
- return result[2].toBigInt();
77
- }
78
- async decimals(originAddress, value, atBlock) {
79
- const payload = this._program.registry.createType('(String, String)', ['Vft', 'Decimals']).toHex();
80
- const reply = await this._program.api.message.calculateReply({
81
- destination: this._program.programId,
82
- origin: decodeAddress(originAddress),
83
- payload,
84
- value: value || 0,
85
- gasLimit: this._program.api.blockGasLimit.toBigInt(),
86
- at: atBlock
87
- });
88
- const result = this._program.registry.createType('(String, String, u8)', reply.payload);
89
- return result[2].toNumber();
90
- }
91
- async name(originAddress, value, atBlock) {
92
- const payload = this._program.registry.createType('(String, String)', ['Vft', 'Name']).toHex();
93
- const reply = await this._program.api.message.calculateReply({
94
- destination: this._program.programId,
95
- origin: decodeAddress(originAddress),
96
- payload,
97
- value: value || 0,
98
- gasLimit: this._program.api.blockGasLimit.toBigInt(),
99
- at: atBlock
100
- });
101
- const result = this._program.registry.createType('(String, String, String)', reply.payload);
102
- return result[2].toString();
103
- }
104
- async symbol(originAddress, value, atBlock) {
105
- const payload = this._program.registry.createType('(String, String)', ['Vft', 'Symbol']).toHex();
106
- const reply = await this._program.api.message.calculateReply({
107
- destination: this._program.programId,
108
- origin: decodeAddress(originAddress),
109
- payload,
110
- value: value || 0,
111
- gasLimit: this._program.api.blockGasLimit.toBigInt(),
112
- at: atBlock
113
- });
114
- const result = this._program.registry.createType('(String, String, String)', reply.payload);
115
- return result[2].toString();
116
- }
117
- async totalSupply(originAddress, value, atBlock) {
118
- const payload = this._program.registry.createType('(String, String)', ['Vft', 'TotalSupply']).toHex();
119
- const reply = await this._program.api.message.calculateReply({
120
- destination: this._program.programId,
121
- origin: decodeAddress(originAddress),
122
- payload,
123
- value: value || 0,
124
- gasLimit: this._program.api.blockGasLimit.toBigInt(),
125
- at: atBlock
126
- });
127
- const result = this._program.registry.createType('(String, String, U256)', reply.payload);
128
- return result[2].toBigInt();
129
- }
130
- subscribeToApprovalEvent(callback) {
131
- return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({
132
- data: {
133
- message
134
- }
135
- }) => {
136
- if (!message.source.eq(this._program.programId) || !message.destination.eq(ZERO_ADDRESS)) {
137
- return;
138
- }
139
- const payload = message.payload.toHex();
140
- if (getServiceNamePrefix(payload) === 'Vft' && getFnNamePrefix(payload) === 'Approval') {
141
- // eslint-disable-next-line node/no-callback-literal,@typescript-eslint/no-floating-promises
142
- callback(this._program.registry.createType('(String, String, {"owner":"[u8;32]","spender":"[u8;32]","value":"U256"})', message.payload)[2].toJSON());
143
- }
144
- });
145
- }
146
- subscribeToTransferEvent(callback) {
147
- return this._program.api.gearEvents.subscribeToGearEvent('UserMessageSent', ({
148
- data: {
149
- message
150
- }
151
- }) => {
152
- if (!message.source.eq(this._program.programId) || !message.destination.eq(ZERO_ADDRESS)) {
153
- return;
154
- }
155
- const payload = message.payload.toHex();
156
- if (getServiceNamePrefix(payload) === 'Service' && getFnNamePrefix(payload) === 'Transfer') {
157
- // eslint-disable-next-line node/no-callback-literal,@typescript-eslint/no-floating-promises
158
- callback(this._program.registry.createType('(String, String, {"from":"[u8;32]","to":"[u8;32]","value":"U256"})', message.payload)[2].toJSON());
159
- }
160
- });
161
- }
162
- }
115
+ return SailsCache.instance;
116
+ }
117
+ async init() {
118
+ if (!this.sail) {
119
+ const parser = await SailsIdlParser.new();
120
+ const sails = new Sails(parser);
121
+ this.sail = sails.parseIdl(vftIdl);
122
+ }
123
+ }
124
+ get() {
125
+ if (!this.sail) {
126
+ throw new Error('Sails is not init yet');
127
+ }
128
+ return this.sail;
129
+ }
130
+ }
131
+ export const sailsCache = SailsCache.getInstance();
@@ -0,0 +1 @@
1
+ {}
@@ -11,6 +11,7 @@ export declare const remindNotificationTime: Record<NotificationActionType, numb
11
11
  export declare const blockedActions: Record<string, EnvConfig>;
12
12
  export declare const oldChainPrefix: Record<string, EnvConfig>;
13
13
  export declare const paraSpellChainMap: Record<string, EnvConfig>;
14
+ export declare const assetHubStakingMap: Record<string, EnvConfig>;
14
15
  export declare enum StaticKey {
15
16
  BUY_SERVICE_INFOS = "buy-service-infos",
16
17
  CHAINS = "chains",
@@ -23,7 +24,8 @@ export declare enum StaticKey {
23
24
  REMIND_NOTIFICATION_TIME = "remind-notification-time",
24
25
  BLOCKED_ACTIONS = "blocked-actions",
25
26
  OLD_CHAIN_PREFIX = "old-chain-prefix",
26
- PARASPELL_CHAIN_MAP = "paraspell-chain-map"
27
+ PARASPELL_CHAIN_MAP = "paraspell-chain-map",
28
+ ASSET_HUB_STAKING_MAP = "asset-hub-staking-map"
27
29
  }
28
30
  export declare const staticData: {
29
31
  chains: import("@subwallet/chain-list/types")._ChainInfo[];
@@ -38,4 +40,5 @@ export declare const staticData: {
38
40
  "blocked-actions": Record<string, EnvConfig>;
39
41
  "old-chain-prefix": Record<string, EnvConfig>;
40
42
  "paraspell-chain-map": Record<string, EnvConfig>;
43
+ "asset-hub-staking-map": Record<string, EnvConfig>;
41
44
  };
@@ -25,6 +25,8 @@ export const blockedActions = require("./blockedActions.json");
25
25
  export const oldChainPrefix = require("./oldChainPrefix.json");
26
26
  // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
27
27
  export const paraSpellChainMap = require("./paraSpellChainMap.json");
28
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
29
+ export const assetHubStakingMap = require("./assetHubStaking.json");
28
30
  export let StaticKey;
29
31
  (function (StaticKey) {
30
32
  StaticKey["BUY_SERVICE_INFOS"] = "buy-service-infos";
@@ -39,6 +41,7 @@ export let StaticKey;
39
41
  StaticKey["BLOCKED_ACTIONS"] = "blocked-actions";
40
42
  StaticKey["OLD_CHAIN_PREFIX"] = "old-chain-prefix";
41
43
  StaticKey["PARASPELL_CHAIN_MAP"] = "paraspell-chain-map";
44
+ StaticKey["ASSET_HUB_STAKING_MAP"] = "asset-hub-staking-map";
42
45
  })(StaticKey || (StaticKey = {}));
43
46
  export const staticData = {
44
47
  [StaticKey.CHAINS]: Object.values(ChainInfoMap),
@@ -52,5 +55,6 @@ export const staticData = {
52
55
  [StaticKey.REMIND_NOTIFICATION_TIME]: remindNotificationTime,
53
56
  [StaticKey.BLOCKED_ACTIONS]: blockedActions,
54
57
  [StaticKey.OLD_CHAIN_PREFIX]: oldChainPrefix,
55
- [StaticKey.PARASPELL_CHAIN_MAP]: paraSpellChainMap
58
+ [StaticKey.PARASPELL_CHAIN_MAP]: paraSpellChainMap,
59
+ [StaticKey.ASSET_HUB_STAKING_MAP]: assetHubStakingMap
56
60
  };