@subwallet/extension-base 1.3.30-0 → 1.3.31-1

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 (75) hide show
  1. package/background/KoniTypes.d.ts +12 -0
  2. package/cjs/constants/paraspell-chain-map.js +13 -0
  3. package/cjs/core/logic-validation/transfer.js +13 -1
  4. package/cjs/core/substrate/xcm-parser.js +5 -1
  5. package/cjs/core/utils.js +36 -15
  6. package/cjs/koni/background/handlers/Extension.js +136 -90
  7. package/cjs/koni/background/handlers/State.js +8 -1
  8. package/cjs/packageInfo.js +1 -1
  9. package/cjs/services/balance-service/helpers/process.js +27 -0
  10. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +33 -1
  11. package/cjs/services/balance-service/index.js +9 -0
  12. package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +229 -0
  13. package/cjs/services/balance-service/transfer/xcm/index.js +96 -7
  14. package/cjs/services/balance-service/transfer/xcm/utils.js +213 -0
  15. package/cjs/services/chain-service/constants.js +2 -4
  16. package/cjs/services/chain-service/index.js +71 -17
  17. package/cjs/services/chain-service/utils/patch.js +1 -1
  18. package/cjs/services/earning-service/handlers/special.js +18 -9
  19. package/cjs/services/keyring-service/context/handlers/Ledger.js +1 -1
  20. package/cjs/services/keyring-service/context/state.js +3 -0
  21. package/cjs/services/migration-service/scripts/DisableZeroBalanceTokens.js +60 -0
  22. package/cjs/services/migration-service/scripts/EnableChain.js +1 -1
  23. package/cjs/services/migration-service/scripts/index.js +3 -2
  24. package/cjs/services/swap-service/handler/base-handler.js +24 -11
  25. package/cjs/services/transaction-service/utils.js +38 -14
  26. package/cjs/utils/fee/transfer.js +52 -28
  27. package/cjs/utils/staticData/index.js +7 -2
  28. package/constants/paraspell-chain-map.d.ts +1 -0
  29. package/constants/paraspell-chain-map.js +7 -0
  30. package/core/logic-validation/transfer.d.ts +1 -0
  31. package/core/logic-validation/transfer.js +12 -1
  32. package/core/substrate/xcm-parser.d.ts +1 -0
  33. package/core/substrate/xcm-parser.js +4 -1
  34. package/core/utils.d.ts +2 -2
  35. package/core/utils.js +36 -15
  36. package/koni/background/handlers/Extension.d.ts +1 -0
  37. package/koni/background/handlers/Extension.js +60 -15
  38. package/koni/background/handlers/State.d.ts +1 -0
  39. package/koni/background/handlers/State.js +7 -1
  40. package/package.json +23 -7
  41. package/packageInfo.js +1 -1
  42. package/services/balance-service/helpers/process.d.ts +2 -1
  43. package/services/balance-service/helpers/process.js +26 -0
  44. package/services/balance-service/helpers/subscribe/substrate/index.js +34 -2
  45. package/services/balance-service/index.js +11 -2
  46. package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +15 -0
  47. package/services/balance-service/transfer/xcm/acrossBridge/index.js +216 -0
  48. package/services/balance-service/transfer/xcm/index.d.ts +5 -1
  49. package/services/balance-service/transfer/xcm/index.js +85 -1
  50. package/services/balance-service/transfer/xcm/utils.d.ts +11 -0
  51. package/services/balance-service/transfer/xcm/utils.js +208 -0
  52. package/services/chain-service/constants.d.ts +0 -1
  53. package/services/chain-service/constants.js +1 -2
  54. package/services/chain-service/index.d.ts +9 -2
  55. package/services/chain-service/index.js +72 -18
  56. package/services/chain-service/utils/patch.js +1 -1
  57. package/services/earning-service/handlers/special.js +19 -10
  58. package/services/keyring-service/context/handlers/Ledger.js +1 -1
  59. package/services/keyring-service/context/state.d.ts +1 -0
  60. package/services/keyring-service/context/state.js +3 -0
  61. package/services/migration-service/scripts/DisableZeroBalanceTokens.d.ts +4 -0
  62. package/services/migration-service/scripts/DisableZeroBalanceTokens.js +51 -0
  63. package/services/migration-service/scripts/EnableChain.js +1 -1
  64. package/services/migration-service/scripts/index.js +3 -2
  65. package/services/swap-service/handler/base-handler.js +25 -12
  66. package/services/transaction-service/types.d.ts +3 -2
  67. package/services/transaction-service/utils.d.ts +1 -0
  68. package/services/transaction-service/utils.js +38 -15
  69. package/types/balance/transfer.d.ts +1 -0
  70. package/types/transaction/request.d.ts +7 -0
  71. package/utils/fee/transfer.d.ts +1 -0
  72. package/utils/fee/transfer.js +54 -30
  73. package/utils/staticData/index.d.ts +4 -1
  74. package/utils/staticData/index.js +5 -1
  75. package/utils/staticData/paraSpellChainMap.json +1 -0
@@ -0,0 +1,216 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
5
+ import { _isAcrossBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
6
+ import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
7
+ // Across Bridge
8
+ const acrossPairsMap = new Map([[COMMON_CHAIN_SLUGS.ETHEREUM, new Set(['optimism', 'base_mainnet', 'arbitrum_one'])], ['optimism', new Set([COMMON_CHAIN_SLUGS.ETHEREUM, 'base_mainnet', 'arbitrum_one'])], ['base_mainnet', new Set([COMMON_CHAIN_SLUGS.ETHEREUM, 'optimism', 'arbitrum_one'])], ['arbitrum_one', new Set([COMMON_CHAIN_SLUGS.ETHEREUM, 'optimism', 'base_mainnet'])], [COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA, new Set(['base_sepolia', 'arbitrum_sepolia'])],
9
+ // TESTNET START HERE
10
+ ['base_sepolia', new Set([COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA])], ['arbitrum_sepolia', new Set([COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA])]]);
11
+ export function _isAcrossChainBridge(srcChain, destChain) {
12
+ var _acrossPairsMap$get$h, _acrossPairsMap$get;
13
+ return (_acrossPairsMap$get$h = (_acrossPairsMap$get = acrossPairsMap.get(srcChain)) === null || _acrossPairsMap$get === void 0 ? void 0 : _acrossPairsMap$get.has(destChain)) !== null && _acrossPairsMap$get$h !== void 0 ? _acrossPairsMap$get$h : false;
14
+ }
15
+ export function _isAcrossTestnetBridge(srcChain) {
16
+ return srcChain === 'base_sepolia' || srcChain === 'arbitrum_sepolia' || srcChain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA;
17
+ }
18
+ export const SpokePoolMapping = {
19
+ 1: {
20
+ SpokePool: {
21
+ address: '0x5c7BCd6E7De5423a257D81B442095A1a6ced35C5',
22
+ blockNumber: 17117454
23
+ }
24
+ },
25
+ 10: {
26
+ SpokePool: {
27
+ address: '0x6f26Bf09B1C792e3228e5467807a900A503c0281',
28
+ blockNumber: 93903076
29
+ }
30
+ },
31
+ 11155111: {
32
+ SpokePool: {
33
+ address: '0x5ef6C01E11889d86803e0B23e3cB3F9E9d97B662',
34
+ blockNumber: 5288470
35
+ }
36
+ },
37
+ 11155420: {
38
+ SpokePool: {
39
+ address: '0x4e8E101924eDE233C13e2D8622DC8aED2872d505',
40
+ blockNumber: 7762656
41
+ }
42
+ },
43
+ 1135: {
44
+ SpokePool: {
45
+ address: '0x9552a0a6624A23B848060AE5901659CDDa1f83f8',
46
+ blockNumber: 2602337
47
+ }
48
+ },
49
+ 130: {
50
+ SpokePool: {
51
+ address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64',
52
+ blockNumber: 7915488
53
+ }
54
+ },
55
+ 137: {
56
+ SpokePool: {
57
+ address: '0x9295ee1d8C5b022Be115A2AD3c30C72E34e7F096',
58
+ blockNumber: 41908657
59
+ }
60
+ },
61
+ 168587773: {
62
+ SpokePool: {
63
+ address: '0x5545092553Cf5Bf786e87a87192E902D50D8f022',
64
+ blockNumber: 7634204
65
+ }
66
+ },
67
+ 1868: {
68
+ SpokePool: {
69
+ address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96',
70
+ blockNumber: 1709997
71
+ }
72
+ },
73
+ 288: {
74
+ SpokePool: {
75
+ address: '0xBbc6009fEfFc27ce705322832Cb2068F8C1e0A58',
76
+ blockNumber: 619993
77
+ }
78
+ },
79
+ 324: {
80
+ SpokePool: {
81
+ address: '0xE0B015E54d54fc84a6cB9B666099c46adE9335FF',
82
+ blockNumber: 10352565
83
+ }
84
+ },
85
+ 34443: {
86
+ SpokePool: {
87
+ address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96',
88
+ blockNumber: 8043187
89
+ }
90
+ },
91
+ 37111: {
92
+ SpokePool: {
93
+ address: '0x6A0a7f39530923911832Dd60667CE5da5449967B',
94
+ blockNumber: 156275
95
+ }
96
+ },
97
+ 41455: {
98
+ SpokePool: {
99
+ address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97',
100
+ blockNumber: 4240318
101
+ }
102
+ },
103
+ 4202: {
104
+ SpokePool: {
105
+ address: '0xeF684C38F94F48775959ECf2012D7E864ffb9dd4',
106
+ blockNumber: 7267988
107
+ }
108
+ },
109
+ 42161: {
110
+ SpokePool: {
111
+ address: '0xe35e9842fceaCA96570B734083f4a58e8F7C5f2A',
112
+ blockNumber: 83868041
113
+ }
114
+ },
115
+ 421614: {
116
+ SpokePool: {
117
+ address: '0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75',
118
+ blockNumber: 12411026
119
+ }
120
+ },
121
+ 480: {
122
+ SpokePool: {
123
+ address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64',
124
+ blockNumber: 4524742
125
+ }
126
+ },
127
+ 534352: {
128
+ SpokePool: {
129
+ address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96',
130
+ blockNumber: 7489705
131
+ }
132
+ },
133
+ 57073: {
134
+ SpokePool: {
135
+ address: '0xeF684C38F94F48775959ECf2012D7E864ffb9dd4',
136
+ blockNumber: 1139240
137
+ }
138
+ },
139
+ 59144: {
140
+ SpokePool: {
141
+ address: '0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75',
142
+ blockNumber: 2721169
143
+ }
144
+ },
145
+ 690: {
146
+ SpokePool: {
147
+ address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97',
148
+ blockNumber: 5512122
149
+ }
150
+ },
151
+ 7777777: {
152
+ SpokePool: {
153
+ address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97',
154
+ blockNumber: 18382867
155
+ }
156
+ },
157
+ 80002: {
158
+ SpokePool: {
159
+ address: '0xd08baaE74D6d2eAb1F3320B2E1a53eeb391ce8e5',
160
+ blockNumber: 7529960
161
+ }
162
+ },
163
+ 81457: {
164
+ SpokePool: {
165
+ address: '0x2D509190Ed0172ba588407D4c2df918F955Cc6E1',
166
+ blockNumber: 5574280
167
+ }
168
+ },
169
+ 8453: {
170
+ SpokePool: {
171
+ address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64',
172
+ blockNumber: 2164878
173
+ }
174
+ },
175
+ 84532: {
176
+ SpokePool: {
177
+ address: '0x82B564983aE7274c86695917BBf8C99ECb6F0F8F',
178
+ blockNumber: 6082004
179
+ }
180
+ },
181
+ 919: {
182
+ SpokePool: {
183
+ address: '0xbd886FC0725Cc459b55BbFEb3E4278610331f83b',
184
+ blockNumber: 13999465
185
+ }
186
+ }
187
+ };
188
+ // Calculate fee for across bridge transfer
189
+ export const getAcrossQuote = async ({
190
+ destinationChain,
191
+ destinationTokenInfo,
192
+ originChain,
193
+ originTokenInfo,
194
+ recipient,
195
+ sender,
196
+ sendingValue
197
+ }) => {
198
+ const isAcrossBridgeXcm = _isAcrossBridgeXcm(originChain, destinationChain);
199
+ console.log('sendingValue', sendingValue);
200
+ if (!isAcrossBridgeXcm) {
201
+ throw new Error('This is not a valid AcrossBridge transfer');
202
+ }
203
+ if (!sender) {
204
+ throw new Error('Sender is required');
205
+ }
206
+ try {
207
+ var _subwalletApiSdk$xcmA;
208
+ const data = await ((_subwalletApiSdk$xcmA = subwalletApiSdk.xcmApi) === null || _subwalletApiSdk$xcmA === void 0 ? void 0 : _subwalletApiSdk$xcmA.fetchXcmData(sender, originTokenInfo.slug, destinationTokenInfo.slug, recipient, sendingValue));
209
+ if (!data || !data.metadata) {
210
+ throw new Error('Failed to get AcrossBridge quote');
211
+ }
212
+ return data.metadata;
213
+ } catch (error) {
214
+ return Promise.reject(error);
215
+ }
216
+ };
@@ -1,4 +1,5 @@
1
1
  import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
+ import { DryRunInfo } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
2
3
  import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
3
4
  import { FeeInfo, TransactionFee } from '@subwallet/extension-base/types';
4
5
  import { TransactionConfig } from 'web3-core';
@@ -15,9 +16,12 @@ export declare type CreateXcmExtrinsicProps = {
15
16
  substrateApi?: _SubstrateApi;
16
17
  feeInfo: FeeInfo;
17
18
  } & TransactionFee;
18
- export declare type FunctionCreateXcmExtrinsic = (props: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | TransactionConfig>;
19
+ export declare type FunctionCreateXcmExtrinsic = (props: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | TransactionConfig | undefined>;
19
20
  export declare const createSnowBridgeExtrinsic: ({ destinationChain, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
20
21
  export declare const createXcmExtrinsic: ({ destinationChain, originChain, originTokenInfo, recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
21
22
  export declare const createAvailBridgeTxFromEth: ({ evmApi, feeCustom, feeInfo, feeOption, originChain, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
22
23
  export declare const createAvailBridgeExtrinsicFromAvail: ({ recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
23
24
  export declare const createPolygonBridgeExtrinsic: ({ destinationChain, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
25
+ export declare const createXcmExtrinsicV2: (request: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | undefined>;
26
+ export declare const dryRunXcmExtrinsicV2: (request: CreateXcmExtrinsicProps) => Promise<DryRunInfo>;
27
+ export declare const createAcrossBridgeExtrinsic: ({ destinationChain, destinationTokenInfo, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
@@ -1,15 +1,19 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { _isPolygonBridgeXcm, _isPosBridgeXcm, _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
4
+ import { XCM_MIN_AMOUNT_RATIO } from '@subwallet/extension-base/constants';
5
+ import { _isAcrossBridgeXcm, _isPolygonBridgeXcm, _isPosBridgeXcm, _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
5
6
  import { getAvailBridgeExtrinsicFromAvail, getAvailBridgeTxFromEth } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
6
7
  import { getExtrinsicByPolkadotXcmPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm';
7
8
  import { _createPolygonBridgeL1toL2Extrinsic, _createPolygonBridgeL2toL1Extrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
8
9
  import { getSnowBridgeEvmTransfer } from '@subwallet/extension-base/services/balance-service/transfer/xcm/snowBridge';
10
+ import { buildXcm, dryRunXcmV2, isChainNotSupportDryRun, isChainNotSupportPolkadotApi } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
9
11
  import { getExtrinsicByXcmPalletPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xcmPallet';
10
12
  import { getExtrinsicByXtokensPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xTokens';
11
13
  import { _XCM_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
12
14
  import { _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
15
+ import { combineEthFee } from '@subwallet/extension-base/utils';
16
+ import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
13
17
  import { _createPosBridgeL1toL2Extrinsic, _createPosBridgeL2toL1Extrinsic } from "./posBridge.js";
14
18
  // SnowBridge
15
19
  export const createSnowBridgeExtrinsic = async ({
@@ -111,4 +115,84 @@ export const createPolygonBridgeExtrinsic = async ({
111
115
  const sourceChain = originChain.slug;
112
116
  const createExtrinsic = isPolygonBridgeXcm ? sourceChain === 'polygonzkEvm_cardona' || sourceChain === 'polygonZkEvm' ? _createPolygonBridgeL2toL1Extrinsic : _createPolygonBridgeL1toL2Extrinsic : sourceChain === 'polygon_amoy' || sourceChain === 'polygon' ? _createPosBridgeL2toL1Extrinsic : _createPosBridgeL1toL2Extrinsic;
113
117
  return createExtrinsic(originTokenInfo, originChain, sender, recipient, sendingValue, evmApi, feeInfo, feeCustom, feeOption);
118
+ };
119
+ export const createXcmExtrinsicV2 = async request => {
120
+ try {
121
+ return await buildXcm(request);
122
+ } catch (e) {
123
+ console.log('createXcmExtrinsicV2 error: ', e);
124
+ const errorMessage = e instanceof Error ? e.message : 'Unknown error occurred';
125
+ if (isChainNotSupportPolkadotApi(errorMessage)) {
126
+ return createXcmExtrinsic(request);
127
+ }
128
+ return undefined;
129
+ }
130
+ };
131
+ export const dryRunXcmExtrinsicV2 = async request => {
132
+ try {
133
+ return await dryRunXcmV2(request);
134
+ } catch (e) {
135
+ const errorMessage = e instanceof Error ? e.message : 'Unknown error occurred';
136
+ if (isChainNotSupportDryRun(errorMessage) || isChainNotSupportPolkadotApi(errorMessage)) {
137
+ const xcmTransfer = await createXcmExtrinsicV2(request);
138
+ if (!xcmTransfer) {
139
+ return {
140
+ success: false
141
+ };
142
+ }
143
+ const _xcmFeeInfo = await xcmTransfer.paymentInfo(request.sender);
144
+ const xcmFeeInfo = _xcmFeeInfo.toPrimitive();
145
+
146
+ // skip dry run in this case
147
+ return {
148
+ success: true,
149
+ fee: Math.round(xcmFeeInfo.partialFee * XCM_MIN_AMOUNT_RATIO).toString()
150
+ };
151
+ }
152
+ return {
153
+ success: false
154
+ };
155
+ }
156
+ };
157
+ export const createAcrossBridgeExtrinsic = async ({
158
+ destinationChain,
159
+ destinationTokenInfo,
160
+ evmApi,
161
+ feeCustom,
162
+ feeInfo,
163
+ feeOption,
164
+ originChain,
165
+ originTokenInfo,
166
+ recipient,
167
+ sender,
168
+ sendingValue
169
+ }) => {
170
+ const isAcrossBridgeXcm = _isAcrossBridgeXcm(originChain, destinationChain);
171
+ if (!isAcrossBridgeXcm) {
172
+ throw new Error('This is not a valid AcrossBridge transfer');
173
+ }
174
+ if (!evmApi) {
175
+ throw new Error('Evm API is not available');
176
+ }
177
+ if (!sender) {
178
+ throw new Error('Sender is required');
179
+ }
180
+ try {
181
+ var _subwalletApiSdk$xcmA;
182
+ const data = await ((_subwalletApiSdk$xcmA = subwalletApiSdk.xcmApi) === null || _subwalletApiSdk$xcmA === void 0 ? void 0 : _subwalletApiSdk$xcmA.fetchXcmData(sender, originTokenInfo.slug, destinationTokenInfo.slug, recipient, sendingValue));
183
+ const _feeCustom = feeCustom;
184
+ const feeCombine = combineEthFee(feeInfo, feeOption, _feeCustom);
185
+ const transactionConfig = {
186
+ from: data === null || data === void 0 ? void 0 : data.sender,
187
+ to: data === null || data === void 0 ? void 0 : data.to,
188
+ value: data === null || data === void 0 ? void 0 : data.value,
189
+ data: data === null || data === void 0 ? void 0 : data.transferEncodedCall,
190
+ ...feeCombine
191
+ };
192
+ const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
193
+ transactionConfig.gas = gasLimit.toString();
194
+ return transactionConfig;
195
+ } catch (error) {
196
+ return Promise.reject(error);
197
+ }
114
198
  };
@@ -1,3 +1,14 @@
1
1
  import { _ChainInfo } from '@subwallet/chain-list/types';
2
+ import { CreateXcmExtrinsicProps } from '@subwallet/extension-base/services/balance-service/transfer/xcm/index';
3
+ import { SubmittableExtrinsic } from '@polkadot/api/types';
4
+ export interface DryRunInfo {
5
+ success: boolean;
6
+ fee?: string;
7
+ }
8
+ export declare function buildXcm(request: CreateXcmExtrinsicProps): Promise<SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
9
+ export declare function dryRunXcm(request: CreateXcmExtrinsicProps): Promise<DryRunInfo>;
10
+ export declare function dryRunXcmV2(request: CreateXcmExtrinsicProps): Promise<DryRunInfo>;
11
+ export declare function isChainNotSupportPolkadotApi(str: string): boolean;
12
+ export declare function isChainNotSupportDryRun(str: string): boolean;
2
13
  export declare const STABLE_XCM_VERSION = 3;
3
14
  export declare function isUseTeleportProtocol(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, tokenSlug?: string): boolean;
@@ -1,7 +1,215 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
5
+ import { fetchParaSpellChainMap } from '@subwallet/extension-base/constants/paraspell-chain-map';
6
+ import { BasicTxErrorType } from '@subwallet/extension-base/types';
7
+ import { assert, compactToU8a, isHex, u8aConcat, u8aEq } from '@polkadot/util';
8
+ const paraSpellEndpoint = 'https://api.lightspell.xyz';
9
+ const paraSpellApi = {
10
+ buildXcm: `${paraSpellEndpoint}/x-transfer`,
11
+ dryRunXcm: `${paraSpellEndpoint}/dry-run`
12
+ };
13
+ const paraSpellKey = process.env.PARASPELL_API_KEY || '';
14
+ function txHexToSubmittableExtrinsic(api, hex) {
15
+ try {
16
+ assert(isHex(hex), 'Expected a hex-encoded call');
17
+ let extrinsicCall;
18
+ let extrinsicPayload = null;
19
+ let decoded = null;
20
+ try {
21
+ // attempt to decode with api.tx
22
+ const tx = api.tx(hex);
23
+
24
+ // ensure that the full data matches here
25
+ assert(tx.toHex() === hex, 'Cannot decode data as extrinsic, length mismatch');
26
+ decoded = tx;
27
+ extrinsicCall = api.createType('Call', decoded.method);
28
+ } catch {
29
+ try {
30
+ // attempt to decode as Call
31
+ extrinsicCall = api.createType('Call', hex);
32
+ const callHex = extrinsicCall.toHex();
33
+ if (callHex === hex) {
34
+ // ok
35
+ } else if (hex.startsWith(callHex)) {
36
+ // this could be an un-prefixed payload...
37
+ const prefixed = u8aConcat(compactToU8a(extrinsicCall.encodedLength), hex);
38
+ extrinsicPayload = api.createType('ExtrinsicPayload', prefixed);
39
+ assert(u8aEq(extrinsicPayload.toU8a(), prefixed), 'Unable to decode data as un-prefixed ExtrinsicPayload');
40
+ extrinsicCall = api.createType('Call', extrinsicPayload.method.toHex());
41
+ } else {
42
+ console.error('Unable to decode data as Call, length mismatch in supplied data');
43
+ }
44
+ } catch {
45
+ // final attempt, we try this as-is as a (prefixed) payload
46
+ extrinsicPayload = api.createType('ExtrinsicPayload', hex);
47
+ assert(extrinsicPayload.toHex() === hex, 'Unable to decode input data as Call, Extrinsic or ExtrinsicPayload');
48
+ extrinsicCall = api.createType('Call', extrinsicPayload.method.toHex());
49
+ }
50
+ }
51
+ const {
52
+ method,
53
+ section
54
+ } = api.registry.findMetaCall(extrinsicCall.callIndex);
55
+ const extrinsicFn = api.tx[section][method];
56
+ if (!decoded) {
57
+ decoded = extrinsicFn(...extrinsicCall.args);
58
+ }
59
+ return decoded;
60
+ } catch (e) {
61
+ console.error('Failed to decode extrinsic hex', e);
62
+ throw new Error('Failed to decode extrinsic hex');
63
+ }
64
+ }
65
+ export async function buildXcm(request) {
66
+ var _originTokenInfo$meta, _originTokenInfo$meta2;
67
+ const {
68
+ destinationChain,
69
+ originChain,
70
+ originTokenInfo,
71
+ recipient,
72
+ sendingValue,
73
+ substrateApi
74
+ } = request;
75
+ if (!substrateApi) {
76
+ return Promise.reject(new Error('Substrate API is not available'));
77
+ }
78
+ const psAssetType = (_originTokenInfo$meta = originTokenInfo.metadata) === null || _originTokenInfo$meta === void 0 ? void 0 : _originTokenInfo$meta.paraSpellAssetType;
79
+ const psAssetValue = (_originTokenInfo$meta2 = originTokenInfo.metadata) === null || _originTokenInfo$meta2 === void 0 ? void 0 : _originTokenInfo$meta2.paraSpellValue;
80
+ if (!psAssetType || !psAssetValue) {
81
+ throw new Error('Token is not support XCM at this time');
82
+ }
83
+ const paraSpellChainMap = await fetchParaSpellChainMap();
84
+ const bodyData = {
85
+ address: recipient,
86
+ from: paraSpellChainMap[originChain.slug],
87
+ to: paraSpellChainMap[destinationChain.slug],
88
+ currency: createParaSpellCurrency(psAssetType, psAssetValue, sendingValue)
89
+ };
90
+ const response = await fetch(paraSpellApi.buildXcm, {
91
+ method: 'POST',
92
+ body: JSON.stringify(bodyData),
93
+ headers: {
94
+ 'Content-Type': 'application/json',
95
+ Accept: 'application/json',
96
+ 'X-API-KEY': paraSpellKey
97
+ }
98
+ });
99
+ if (!response.ok) {
100
+ const error = await response.json();
101
+ throw new Error(error.message);
102
+ }
103
+ const extrinsicHex = await response.text();
104
+ const chainApi = await substrateApi.isReady;
105
+ return txHexToSubmittableExtrinsic(chainApi.api, extrinsicHex);
106
+ }
107
+
108
+ // dry run can fail due to sender address & amount token
109
+ export async function dryRunXcm(request) {
110
+ var _originTokenInfo$meta3, _originTokenInfo$meta4;
111
+ const {
112
+ destinationChain,
113
+ originChain,
114
+ originTokenInfo,
115
+ recipient,
116
+ sender,
117
+ sendingValue
118
+ } = request;
119
+ const paraSpellChainMap = await fetchParaSpellChainMap();
120
+ const psAssetType = (_originTokenInfo$meta3 = originTokenInfo.metadata) === null || _originTokenInfo$meta3 === void 0 ? void 0 : _originTokenInfo$meta3.paraSpellAssetType;
121
+ const psAssetValue = (_originTokenInfo$meta4 = originTokenInfo.metadata) === null || _originTokenInfo$meta4 === void 0 ? void 0 : _originTokenInfo$meta4.paraSpellValue;
122
+ if (!psAssetType || !psAssetValue) {
123
+ throw new Error('Token is not support XCM at this time'); // todo: content
124
+ }
125
+
126
+ let dryRunInfo;
127
+ try {
128
+ const bodyData = {
129
+ senderAddress: sender,
130
+ address: recipient,
131
+ from: paraSpellChainMap[originChain.slug],
132
+ to: paraSpellChainMap[destinationChain.slug],
133
+ currency: createParaSpellCurrency(psAssetType, psAssetValue, sendingValue)
134
+ };
135
+ const response = await fetch(paraSpellApi.dryRunXcm, {
136
+ method: 'POST',
137
+ body: JSON.stringify(bodyData),
138
+ headers: {
139
+ 'Content-Type': 'application/json',
140
+ Accept: 'application/json',
141
+ 'X-API-KEY': paraSpellKey
142
+ }
143
+ });
144
+ dryRunInfo = await response.json();
145
+ } catch (e) {
146
+ console.error('Unable to dry run', e);
147
+ }
148
+ if (!dryRunInfo || !dryRunInfo.success) {
149
+ throw new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, 'Unable to perform transaction. Select another token or destination chain and try again');
150
+ }
151
+ return dryRunInfo;
152
+ }
153
+ export async function dryRunXcmV2(request) {
154
+ var _originTokenInfo$meta5, _originTokenInfo$meta6;
155
+ const {
156
+ destinationChain,
157
+ originChain,
158
+ originTokenInfo,
159
+ recipient,
160
+ sender,
161
+ sendingValue
162
+ } = request;
163
+ const paraSpellChainMap = await fetchParaSpellChainMap();
164
+ const psAssetType = (_originTokenInfo$meta5 = originTokenInfo.metadata) === null || _originTokenInfo$meta5 === void 0 ? void 0 : _originTokenInfo$meta5.paraSpellAssetType;
165
+ const psAssetValue = (_originTokenInfo$meta6 = originTokenInfo.metadata) === null || _originTokenInfo$meta6 === void 0 ? void 0 : _originTokenInfo$meta6.paraSpellValue;
166
+ if (!psAssetType || !psAssetValue) {
167
+ throw new Error('Token is not support XCM at this time');
168
+ }
169
+ const bodyData = {
170
+ senderAddress: sender,
171
+ address: recipient,
172
+ from: paraSpellChainMap[originChain.slug],
173
+ to: paraSpellChainMap[destinationChain.slug],
174
+ currency: createParaSpellCurrency(psAssetType, psAssetValue, sendingValue)
175
+ };
176
+ const response = await fetch(paraSpellApi.dryRunXcm, {
177
+ method: 'POST',
178
+ body: JSON.stringify(bodyData),
179
+ headers: {
180
+ 'Content-Type': 'application/json',
181
+ Accept: 'application/json',
182
+ 'X-API-KEY': paraSpellKey
183
+ }
184
+ });
185
+ if (!response.ok) {
186
+ const error = await response.json();
187
+ throw new Error(error.message);
188
+ }
189
+ return await response.json();
190
+ }
191
+ function createParaSpellCurrency(assetType, assetValue, amount) {
192
+ // todo: handle complex conditions for asset has same symbol in a chain: Id, Multi-location, ...
193
+ return {
194
+ [assetType]: assetValue,
195
+ amount
196
+ };
197
+ }
198
+ export function isChainNotSupportPolkadotApi(str) {
199
+ const regex = /(?=.*not yet supported)(?=.*Polkadot API).*/i; // Example: The node Interlay is not yet supported by the Polkadot API.
200
+
201
+ return regex.test(str);
202
+ }
203
+ export function isChainNotSupportDryRun(str) {
204
+ const regex = /(?=.*DryRunApi)(?=.*not available).*/i; // Example: DryRunApi is not available on node Acala
205
+
206
+ return regex.test(str);
207
+ }
208
+
209
+ // todo: remove
4
210
  export const STABLE_XCM_VERSION = 3;
211
+
212
+ // todo: remove
5
213
  export function isUseTeleportProtocol(originChainInfo, destChainInfo, tokenSlug) {
6
214
  const relayChainToSystemChain = ['polkadot'].includes(originChainInfo.slug) && ['statemint'].includes(destChainInfo.slug) || ['kusama'].includes(originChainInfo.slug) && ['statemine'].includes(destChainInfo.slug) || ['rococo'].includes(originChainInfo.slug) && ['rococo_assethub'].includes(destChainInfo.slug) || ['westend'].includes(originChainInfo.slug) && ['westend_assethub'].includes(destChainInfo.slug);
7
215
  const systemChainToRelayChain = ['polkadot'].includes(destChainInfo.slug) && ['statemint'].includes(originChainInfo.slug) || ['kusama'].includes(destChainInfo.slug) && ['statemine'].includes(originChainInfo.slug) || ['rococo'].includes(destChainInfo.slug) && ['rococo_assethub'].includes(originChainInfo.slug) || ['westend'].includes(destChainInfo.slug) && ['westend_assethub'].includes(originChainInfo.slug);
@@ -83,7 +83,6 @@ export declare const _XCM_CHAIN_GROUP: {
83
83
  polkadotXcmSpecialCases: string[];
84
84
  xcmPallet: string[];
85
85
  };
86
- export declare const SUFFICIENT_CHAIN: string[];
87
86
  export declare const _XCM_TYPE: {
88
87
  RP: string;
89
88
  PP: string;
@@ -29,7 +29,7 @@ export const _BALANCE_CHAIN_GROUP = {
29
29
  kintsugi: ['kintsugi', 'interlay', 'kintsugi_test', 'mangatax_para'],
30
30
  genshiro: ['genshiro_testnet', 'genshiro'],
31
31
  equilibrium_parachain: ['equilibrium_parachain'],
32
- bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'hydradx_rococo', 'pendulum', 'amplitude', 'continuum_network'],
32
+ bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'hydradx_rococo', 'pendulum', 'amplitude', 'continuum_network', 'truth_network'],
33
33
  statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland', 'dentnet', 'pangolin', 'crust', 'phala', 'shibuya', 'dbcchain', 'westend_assethub'],
34
34
  kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
35
35
  // perhaps there are some runtime updates
@@ -278,7 +278,6 @@ export const _XCM_CHAIN_GROUP = {
278
278
  // default is xTokens pallet
279
279
  };
280
280
 
281
- export const SUFFICIENT_CHAIN = ['astar', 'calamari', 'parallel', 'darwinia2', 'crabParachain', 'pangolin', 'statemint', 'moonriver', 'shiden', 'moonbeam', 'statemine', 'liberland', 'dentnet', 'phala', 'crust', 'dbcchain', 'rococo_assethub'];
282
281
  export const _XCM_TYPE = {
283
282
  RP: `${_SubstrateChainType.RELAYCHAIN}-${_SubstrateChainType.PARACHAIN}`,
284
283
  // DMP
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
3
- import { AssetSetting, MetadataItem, TokenPriorityDetails, ValidateNetworkResponse } from '@subwallet/extension-base/background/KoniTypes';
3
+ import { AssetSetting, MetadataItem, SufficientChainsDetails, TokenPriorityDetails, ValidateNetworkResponse } from '@subwallet/extension-base/background/KoniTypes';
4
4
  import { MantaPrivateHandler } from '@subwallet/extension-base/services/chain-service/handler/manta/MantaPrivateHandler';
5
5
  import { _ChainApiStatus, _ChainConnectionStatus, _ChainState, _NetworkUpsertParams, _SubstrateApi, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse } from '@subwallet/extension-base/services/chain-service/types';
6
6
  import { EventService } from '@subwallet/extension-base/services/event-service';
@@ -32,6 +32,7 @@ export declare class ChainService {
32
32
  private chainLogoMapSubject;
33
33
  private ledgerGenericAllowChainsSubject;
34
34
  private priorityTokensSubject;
35
+ private sufficientChainsSubject;
35
36
  private store;
36
37
  private assetSettingSubject;
37
38
  private logger;
@@ -39,10 +40,12 @@ export declare class ChainService {
39
40
  get value(): {
40
41
  readonly ledgerGenericAllowChains: string[];
41
42
  readonly priorityTokens: TokenPriorityDetails;
43
+ readonly sufficientChains: SufficientChainsDetails;
42
44
  };
43
45
  get observable(): {
44
46
  readonly ledgerGenericAllowChains: import("rxjs").Observable<string[]>;
45
47
  readonly priorityTokens: import("rxjs").Observable<TokenPriorityDetails>;
48
+ readonly sufficientChains: import("rxjs").Observable<SufficientChainsDetails>;
46
49
  };
47
50
  subscribeSwapRefMap(): Subject<Record<string, _AssetRef>>;
48
51
  get xcmRefMap(): Record<string, _AssetRef>;
@@ -111,8 +114,10 @@ export declare class ChainService {
111
114
  stopCheckLatestChainData(): void;
112
115
  handleLatestChainData(latestChainInfo: _ChainInfo[]): void;
113
116
  autoEnableTokens(): Promise<void>;
117
+ enablePopularTokens(): Promise<void>;
114
118
  handleLatestLedgerGenericAllowChains(latestledgerGenericAllowChains: string[]): void;
115
119
  handleLatestPriorityTokens(latestPriorityTokens: TokenPriorityDetails): void;
120
+ handleLatestSufficientChains(latestSufficientChains: SufficientChainsDetails): void;
116
121
  handleLatestData(): void;
117
122
  private initApis;
118
123
  initSingleApi(slug: string): Promise<boolean>;
@@ -127,6 +132,7 @@ export declare class ChainService {
127
132
  private fetchLatestPriceIdsData;
128
133
  private fetchLatestLedgerGenericAllowChains;
129
134
  private fetchLatestPriorityTokens;
135
+ private fetchLatestSufficientChains;
130
136
  private initChains;
131
137
  private initAssetRegistry;
132
138
  private updateChainStateMapSubscription;
@@ -148,13 +154,14 @@ export declare class ChainService {
148
154
  refreshEvmApi(slug: string): void;
149
155
  stopAllChainApis(): Promise<void>;
150
156
  resumeAllChainApis(): Promise<void>;
151
- initAssetSettings(): Promise<void>;
157
+ initAssetSettings(): void;
152
158
  setAssetSettings(assetSettings: Record<string, AssetSetting>, emitEvent?: boolean): void;
153
159
  setMantaZkAssetSettings(visible: boolean): void;
154
160
  getStoreAssetSettings(): Promise<Record<string, AssetSetting>>;
155
161
  getAssetSettings(): Promise<Record<string, AssetSetting>>;
156
162
  updateAssetSetting(assetSlug: string, assetSetting: AssetSetting, autoEnableNativeToken?: boolean): Promise<boolean | undefined>;
157
163
  updateAssetSettingByChain(chainSlug: string, visible: boolean): Promise<void>;
164
+ updatePriorityAssetsByChain(chainSlug: string, visible: boolean): Promise<void>;
158
165
  subscribeAssetSettings(): BehaviorSubject<Record<string, AssetSetting>>;
159
166
  getAssetLogoMap(): Record<string, string>;
160
167
  subscribeAssetLogoMap(): BehaviorSubject<Record<string, string>>;