@subwallet/extension-base 1.3.66-0 → 1.3.67-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 (31) hide show
  1. package/cjs/core/substrate/xcm-parser.js +0 -176
  2. package/cjs/koni/background/handlers/Extension.js +1 -1
  3. package/cjs/packageInfo.js +1 -1
  4. package/cjs/services/balance-service/transfer/smart-contract.js +54 -23
  5. package/cjs/services/balance-service/transfer/xcm/index.js +30 -44
  6. package/cjs/services/balance-service/transfer/xcm/utils.js +53 -18
  7. package/cjs/services/swap-service/handler/base-handler.js +18 -21
  8. package/cjs/utils/fee/transfer.js +5 -2
  9. package/core/substrate/xcm-parser.d.ts +1 -49
  10. package/core/substrate/xcm-parser.js +1 -173
  11. package/koni/background/handlers/Extension.js +1 -1
  12. package/package.json +5 -20
  13. package/packageInfo.js +1 -1
  14. package/services/balance-service/transfer/smart-contract.d.ts +4 -0
  15. package/services/balance-service/transfer/smart-contract.js +52 -23
  16. package/services/balance-service/transfer/xcm/index.d.ts +2 -2
  17. package/services/balance-service/transfer/xcm/index.js +18 -32
  18. package/services/balance-service/transfer/xcm/utils.d.ts +1 -2
  19. package/services/balance-service/transfer/xcm/utils.js +51 -15
  20. package/services/swap-service/handler/base-handler.d.ts +0 -1
  21. package/services/swap-service/handler/base-handler.js +19 -22
  22. package/utils/fee/transfer.js +6 -3
  23. package/cjs/services/balance-service/transfer/xcm/polkadotXcm.js +0 -30
  24. package/cjs/services/balance-service/transfer/xcm/xTokens.js +0 -32
  25. package/cjs/services/balance-service/transfer/xcm/xcmPallet.js +0 -23
  26. package/services/balance-service/transfer/xcm/polkadotXcm.d.ts +0 -3
  27. package/services/balance-service/transfer/xcm/polkadotXcm.js +0 -24
  28. package/services/balance-service/transfer/xcm/xTokens.d.ts +0 -3
  29. package/services/balance-service/transfer/xcm/xTokens.js +0 -26
  30. package/services/balance-service/transfer/xcm/xcmPallet.d.ts +0 -3
  31. package/services/balance-service/transfer/xcm/xcmPallet.js +0 -17
@@ -4,10 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports._adaptX1Interior = _adaptX1Interior;
7
- exports._getXcmBeneficiary = _getXcmBeneficiary;
8
- exports._getXcmDestWeight = _getXcmDestWeight;
9
- exports._getXcmMultiAssets = _getXcmMultiAssets;
10
- exports._getXcmMultiLocation = _getXcmMultiLocation;
11
7
  exports._getXcmUnstableWarning = _getXcmUnstableWarning;
12
8
  exports._isAcrossBridgeXcm = _isAcrossBridgeXcm;
13
9
  exports._isAvailBridgeXcm = _isAvailBridgeXcm;
@@ -23,52 +19,9 @@ var _availBridge = require("@subwallet/extension-base/services/balance-service/t
23
19
  var _polygonBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge");
24
20
  var _posBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge");
25
21
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
26
- var _utilCrypto = require("@polkadot/util-crypto");
27
22
  // Copyright 2019-2022 @subwallet/extension-base
28
23
  // SPDX-License-Identifier: Apache-2.0
29
24
 
30
- const FOUR_INSTRUCTIONS_WEIGHT = 5000000000;
31
- const UNLIMITED_WEIGHT = 'Unlimited';
32
- function _getXcmDestWeight(originChainInfo) {
33
- if (['pioneer'].includes(originChainInfo.slug)) {
34
- return FOUR_INSTRUCTIONS_WEIGHT;
35
- }
36
- return UNLIMITED_WEIGHT;
37
- }
38
- function _getXcmBeneficiary(destChainInfo, recipient, version) {
39
- const receiverLocation = version < 4 // from V4, X1 is also an array
40
- ? _getRecipientLocation(destChainInfo, recipient, version) : [_getRecipientLocation(destChainInfo, recipient, version)];
41
- return {
42
- [`V${version}`]: {
43
- parents: 0,
44
- interior: {
45
- X1: receiverLocation
46
- }
47
- }
48
- };
49
- }
50
- function _getXcmMultiAssets(tokenInfo, value, version) {
51
- const assetId = _getAssetIdentifier(tokenInfo, version);
52
- return {
53
- [`V${version}`]: [{
54
- id: assetId,
55
- fun: {
56
- Fungible: value
57
- }
58
- }]
59
- };
60
- }
61
- function _getXcmMultiLocation(originChainInfo, destChainInfo, version, recipient) {
62
- const isWithinSameConsensus = _isXcmWithinSameConsensus(originChainInfo, destChainInfo);
63
- const parents = _getMultiLocationParent(originChainInfo, isWithinSameConsensus);
64
- const interior = _getMultiLocationInterior(destChainInfo, isWithinSameConsensus, version, recipient);
65
- return {
66
- [`V${version}`]: {
67
- parents,
68
- interior
69
- }
70
- };
71
- }
72
25
  function _isXcmTransferUnstable(originChainInfo, destChainInfo, assetSlug) {
73
26
  return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) || _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug) || _isPolygonBridgeXcm(originChainInfo, destChainInfo) || _isPosBridgeXcm(originChainInfo, destChainInfo);
74
27
  }
@@ -152,123 +105,6 @@ function _isAcrossBridgeXcm(originChainInfo, destChainInfo) {
152
105
  }
153
106
  // ---------------------------------------------------------------------------------------------------------------------
154
107
 
155
- function _getMultiLocationParent(originChainInfo, isWithinSameConsensus) {
156
- let parent = 0; // how many hops up the hierarchy
157
-
158
- if ((0, _utils._isSubstrateParaChain)(originChainInfo)) {
159
- parent += 1;
160
- }
161
- if (!isWithinSameConsensus) {
162
- parent += 1;
163
- }
164
- return parent;
165
- }
166
- function _getMultiLocationInterior(destChainInfo, isWithinSameConsensus, version, recipient) {
167
- const junctions = [];
168
- if (isWithinSameConsensus) {
169
- if ((0, _utils._isSubstrateParaChain)(destChainInfo)) {
170
- junctions.push({
171
- Parachain: (0, _utils._getSubstrateParaId)(destChainInfo)
172
- });
173
- }
174
- } else {
175
- junctions.push({
176
- GlobalConsensus: _getGlobalConsensusJunction(destChainInfo, version)
177
- });
178
- if ((0, _utils._isSubstrateParaChain)(destChainInfo)) {
179
- junctions.push({
180
- Parachain: (0, _utils._getSubstrateParaId)(destChainInfo)
181
- });
182
- }
183
- }
184
- if (recipient) {
185
- junctions.push(_getRecipientLocation(destChainInfo, recipient, version));
186
- }
187
- if (junctions.length === 0 && !recipient) {
188
- return 'Here';
189
- }
190
- if (version < 4 && junctions.length === 1) {
191
- return {
192
- X1: junctions[0]
193
- };
194
- }
195
- return {
196
- [`X${junctions.length}`]: junctions
197
- };
198
- }
199
- function _getGlobalConsensusJunction(destChainInfo, version) {
200
- let chainSlug = destChainInfo.slug;
201
- let evmChainId;
202
- if ((0, _utils._isSubstrateParaChain)(destChainInfo)) {
203
- const relaySlug = (0, _utils._getSubstrateRelayParent)(destChainInfo);
204
- if (!relaySlug) {
205
- throw Error('Parachain must have a parent chainSlug');
206
- }
207
- chainSlug = relaySlug;
208
- } else {
209
- evmChainId = (0, _utils._getEvmChainId)(destChainInfo);
210
- }
211
- if (evmChainId) {
212
- return {
213
- Ethereum: {
214
- chainId: evmChainId
215
- }
216
- };
217
- }
218
- switch (chainSlug) {
219
- case _chainList.COMMON_CHAIN_SLUGS.POLKADOT:
220
- return version < 4 ? {
221
- Polkadot: null
222
- } : 'Polkadot';
223
- case _chainList.COMMON_CHAIN_SLUGS.KUSAMA:
224
- return version < 4 ? {
225
- Kusama: null
226
- } : 'Kusama';
227
- default:
228
- return version < 4 ? {
229
- Rococo: null
230
- } : 'Rococo';
231
- }
232
- }
233
- function _getRecipientLocation(destChainInfo, recipient, version) {
234
- const network = _getNetworkByVersion(version);
235
- if (destChainInfo.slug === _chainList.COMMON_CHAIN_SLUGS.ASTAR_EVM) {
236
- const ss58Address = (0, _utilCrypto.evmToAddress)(recipient, (0, _utils._getChainSubstrateAddressPrefix)(destChainInfo)); // TODO: shouldn't pass addressPrefix directly
237
-
238
- return {
239
- AccountId32: {
240
- network,
241
- id: (0, _utilCrypto.decodeAddress)(ss58Address)
242
- }
243
- };
244
- }
245
- if ((0, _utils._isChainEvmCompatible)(destChainInfo)) {
246
- return {
247
- AccountKey20: {
248
- network,
249
- key: recipient
250
- }
251
- };
252
- }
253
- return {
254
- AccountId32: {
255
- network,
256
- id: (0, _utilCrypto.decodeAddress)(recipient)
257
- }
258
- };
259
- }
260
- function _getAssetIdentifier(tokenInfo, version) {
261
- const _assetIdentifier = (0, _utils._getXcmAssetMultilocation)(tokenInfo);
262
- if (!_assetIdentifier) {
263
- throw new Error('Asset must have multilocation');
264
- }
265
- const assetIdentifier = ['statemint-LOCAL-KSM', 'statemine-LOCAL-DOT'].includes(tokenInfo.slug) // todo: hotfix for ksm statemint recheck all chain
266
- ? _assetIdentifier : _adaptX1Interior(_assetIdentifier, version);
267
- return version >= 4 // from V4, Concrete is removed
268
- ? assetIdentifier : {
269
- Concrete: assetIdentifier
270
- };
271
- }
272
108
  function _adaptX1Interior(_assetIdentifier, version) {
273
109
  const assetIdentifier = structuredClone(_assetIdentifier);
274
110
  const interior = assetIdentifier.interior;
@@ -281,16 +117,4 @@ function _adaptX1Interior(_assetIdentifier, version) {
281
117
  interior.X1 = interior.X1[0];
282
118
  }
283
119
  return assetIdentifier;
284
- }
285
- function _getNetworkByVersion(version) {
286
- switch (version) {
287
- case 1:
288
- case 2:
289
- return 'Any';
290
- case 3:
291
- case 4:
292
- return undefined;
293
- default:
294
- return undefined;
295
- }
296
120
  }
@@ -1694,7 +1694,7 @@ class KoniExtension {
1694
1694
  error.length && inputTransaction.errors.push(...error);
1695
1695
  }
1696
1696
  if (isSubstrateXcm) {
1697
- const isDryRunSuccess = await (0, _xcm.dryRunXcmExtrinsicV2)(params);
1697
+ const isDryRunSuccess = await (0, _xcm.dryRunXcmExtrinsicV2)(params, false);
1698
1698
  if (!isDryRunSuccess) {
1699
1699
  inputTransaction.errors.push(new _TransactionError.TransactionError(_types4.BasicTxErrorType.UNABLE_TO_SEND, 'Unable to perform transaction. Select another token or destination chain and try again'));
1700
1700
  }
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.3.66-0'
16
+ version: '1.3.67-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -4,6 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.gasSettingsForEWC = void 0;
7
8
  exports.getERC20TransactionObject = getERC20TransactionObject;
8
9
  exports.getERC721Transaction = getERC721Transaction;
9
10
  exports.getEVMTransactionObject = getEVMTransactionObject;
@@ -19,6 +20,12 @@ var _i18next = require("i18next");
19
20
  // Copyright 2019-2022 @subwallet/extension-base
20
21
  // SPDX-License-Identifier: Apache-2.0
21
22
 
23
+ // hot fix gas settings for Energy Web Chain
24
+ const gasSettingsForEWC = {
25
+ gasLimit: 4900000,
26
+ maxFeePerGas: '10000000'
27
+ };
28
+ exports.gasSettingsForEWC = gasSettingsForEWC;
22
29
  async function getEVMTransactionObject(props) {
23
30
  const {
24
31
  chain,
@@ -33,10 +40,18 @@ async function getEVMTransactionObject(props) {
33
40
  transferAll,
34
41
  value
35
42
  } = props;
43
+ const isEnergyWebChain = chain === 'energy_web_chain'; // hot fix gas settings for Energy Web Chain
44
+
36
45
  const feeCustom = _feeCustom;
37
46
  const feeInfo = _feeInfo;
38
47
  const feeCombine = (0, _utils3.combineEthFee)(feeInfo, feeOption, feeCustom);
39
48
  let errorOnEstimateFee = '';
49
+ if (isEnergyWebChain) {
50
+ feeCombine.maxFeePerGas = gasSettingsForEWC.maxFeePerGas;
51
+ if (!feeCombine.maxPriorityFeePerGas || new _bignumber.default(feeCombine.maxPriorityFeePerGas).gt(feeCombine.maxFeePerGas)) {
52
+ feeCombine.maxPriorityFeePerGas = gasSettingsForEWC.maxFeePerGas;
53
+ }
54
+ }
40
55
  const transactionObject = {
41
56
  to,
42
57
  value,
@@ -44,16 +59,21 @@ async function getEVMTransactionObject(props) {
44
59
  data,
45
60
  ...feeCombine
46
61
  };
47
- const gasEstimate = await evmApi.api.eth.estimateGas(transactionObject).catch(e => {
48
- console.log('Cannot estimate fee with native transfer on', chain, e);
49
- if (fallbackFee) {
50
- errorOnEstimateFee = e.message;
51
- return 21000;
52
- } else {
53
- throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
54
- }
55
- });
56
- const gasLimit = Math.floor(gasEstimate * 1.1); // 10% buffer for fluctuations
62
+ let gasLimit;
63
+ if (isEnergyWebChain) {
64
+ gasLimit = gasSettingsForEWC.gasLimit;
65
+ } else {
66
+ const gasEstimate = await evmApi.api.eth.estimateGas(transactionObject).catch(e => {
67
+ console.log('Cannot estimate fee with native transfer on', chain, e);
68
+ if (fallbackFee) {
69
+ errorOnEstimateFee = e.message;
70
+ return 21000;
71
+ } else {
72
+ throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
73
+ }
74
+ });
75
+ gasLimit = Math.floor(gasEstimate * 1.1); // 10% buffer for fluctuations
76
+ }
57
77
 
58
78
  transactionObject.gas = gasLimit;
59
79
  let estimateFee;
@@ -84,6 +104,8 @@ async function getERC20TransactionObject(props) {
84
104
  transferAll,
85
105
  value
86
106
  } = props;
107
+ const isEnergyWebChain = chain === 'energy_web_chain'; // hot fix gas settings for Energy Web Chain
108
+
87
109
  const erc20Contract = (0, _web.getERC20Contract)(assetAddress, evmApi);
88
110
  const feeCustom = _feeCustom;
89
111
  let freeAmount = new _bignumber.default(0);
@@ -99,21 +121,30 @@ async function getERC20TransactionObject(props) {
99
121
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
100
122
  return erc20Contract.methods.transfer(to, transferValue).encodeABI();
101
123
  }
102
- const transferData = generateTransferData(to, transferValue);
103
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
104
- const gasLimit = await erc20Contract.methods.transfer(to, transferValue).estimateGas({
105
- from
106
- }).catch(e => {
107
- console.log('Cannot estimate fee with token contract', assetAddress, chain, e);
108
- if (fallbackFee) {
109
- errorOnEstimateFee = e.message;
110
- return 70000;
111
- } else {
112
- throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
113
- }
114
- });
115
124
  const feeInfo = _feeInfo;
116
125
  const feeCombine = (0, _utils3.combineEthFee)(feeInfo, feeOption, feeCustom);
126
+ const transferData = generateTransferData(to, transferValue);
127
+ let gasLimit;
128
+ if (isEnergyWebChain) {
129
+ gasLimit = gasSettingsForEWC.gasLimit;
130
+ feeCombine.maxFeePerGas = gasSettingsForEWC.maxFeePerGas;
131
+ if (!feeCombine.maxPriorityFeePerGas || new _bignumber.default(feeCombine.maxPriorityFeePerGas).gt(feeCombine.maxFeePerGas)) {
132
+ feeCombine.maxPriorityFeePerGas = gasSettingsForEWC.maxFeePerGas;
133
+ }
134
+ } else {
135
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
136
+ gasLimit = await erc20Contract.methods.transfer(to, transferValue).estimateGas({
137
+ from
138
+ }).catch(e => {
139
+ console.log('Cannot estimate fee with token contract', assetAddress, chain, e);
140
+ if (fallbackFee) {
141
+ errorOnEstimateFee = e.message;
142
+ return 70000;
143
+ } else {
144
+ throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
145
+ }
146
+ });
147
+ }
117
148
  const transactionObject = {
118
149
  gas: gasLimit,
119
150
  from,
@@ -4,18 +4,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.dryRunXcmExtrinsicV2 = exports.createXcmExtrinsicV2 = exports.createXcmExtrinsic = exports.createSnowBridgeExtrinsic = exports.createPolygonBridgeExtrinsic = exports.createAvailBridgeTxFromEth = exports.createAvailBridgeExtrinsicFromAvail = exports.createAcrossBridgeExtrinsic = void 0;
7
+ exports.getXcmOriginFee = exports.dryRunXcmExtrinsicV2 = exports.createXcmExtrinsicV2 = exports.createSnowBridgeExtrinsic = exports.createPolygonBridgeExtrinsic = exports.createAvailBridgeTxFromEth = exports.createAvailBridgeExtrinsicFromAvail = exports.createAcrossBridgeExtrinsic = void 0;
8
8
  var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
9
9
  var _availBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge");
10
- var _polkadotXcm = require("@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm");
11
10
  var _polygonBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge");
12
11
  var _snowBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/snowBridge");
13
12
  var _utils = require("@subwallet/extension-base/services/balance-service/transfer/xcm/utils");
14
- var _xcmPallet = require("@subwallet/extension-base/services/balance-service/transfer/xcm/xcmPallet");
15
- var _xTokens = require("@subwallet/extension-base/services/balance-service/transfer/xcm/xTokens");
16
- var _constants = require("@subwallet/extension-base/services/chain-service/constants");
17
- var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
18
- var _utils3 = require("@subwallet/extension-base/utils");
13
+ var _utils2 = require("@subwallet/extension-base/utils");
19
14
  var _subwalletServicesSdk = _interopRequireDefault(require("@subwallet-monorepos/subwallet-services-sdk"));
20
15
  var _posBridge = require("./posBridge");
21
16
  // Copyright 2019-2022 @subwallet/extension-base
@@ -46,34 +41,8 @@ const createSnowBridgeExtrinsic = async _ref => {
46
41
  }
47
42
  return (0, _snowBridge.getSnowBridgeEvmTransfer)(originTokenInfo, originChain, destinationChain, sender, recipient, sendingValue, evmApi, feeInfo, feeCustom, feeOption);
48
43
  };
49
-
50
- // deprecated
51
44
  exports.createSnowBridgeExtrinsic = createSnowBridgeExtrinsic;
52
- const createXcmExtrinsic = async _ref2 => {
53
- let {
54
- destinationChain,
55
- originChain,
56
- originTokenInfo,
57
- recipient,
58
- sendingValue,
59
- substrateApi
60
- } = _ref2;
61
- if (!substrateApi) {
62
- throw Error('Substrate API is not available');
63
- }
64
- const chainApi = await substrateApi.isReady;
65
- const api = chainApi.api;
66
- const polkadotXcmSpecialCases = _constants._XCM_CHAIN_GROUP.polkadotXcmSpecialCases.includes(originChain.slug) && (0, _utils2._isNativeToken)(originTokenInfo);
67
- if (_constants._XCM_CHAIN_GROUP.polkadotXcm.includes(originTokenInfo.originChain) || polkadotXcmSpecialCases) {
68
- return (0, _polkadotXcm.getExtrinsicByPolkadotXcmPallet)(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
69
- }
70
- if (_constants._XCM_CHAIN_GROUP.xcmPallet.includes(originTokenInfo.originChain)) {
71
- return (0, _xcmPallet.getExtrinsicByXcmPalletPallet)(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
72
- }
73
- return (0, _xTokens.getExtrinsicByXtokensPallet)(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
74
- };
75
- exports.createXcmExtrinsic = createXcmExtrinsic;
76
- const createAvailBridgeTxFromEth = _ref3 => {
45
+ const createAvailBridgeTxFromEth = _ref2 => {
77
46
  let {
78
47
  evmApi,
79
48
  feeCustom,
@@ -83,7 +52,7 @@ const createAvailBridgeTxFromEth = _ref3 => {
83
52
  recipient,
84
53
  sender,
85
54
  sendingValue
86
- } = _ref3;
55
+ } = _ref2;
87
56
  if (!evmApi) {
88
57
  throw Error('Evm API is not available');
89
58
  }
@@ -93,19 +62,19 @@ const createAvailBridgeTxFromEth = _ref3 => {
93
62
  return (0, _availBridge.getAvailBridgeTxFromEth)(originChain, sender, recipient, sendingValue, evmApi, feeInfo, feeCustom, feeOption);
94
63
  };
95
64
  exports.createAvailBridgeTxFromEth = createAvailBridgeTxFromEth;
96
- const createAvailBridgeExtrinsicFromAvail = async _ref4 => {
65
+ const createAvailBridgeExtrinsicFromAvail = async _ref3 => {
97
66
  let {
98
67
  recipient,
99
68
  sendingValue,
100
69
  substrateApi
101
- } = _ref4;
70
+ } = _ref3;
102
71
  if (!substrateApi) {
103
72
  throw Error('Substrate API is not available');
104
73
  }
105
74
  return await (0, _availBridge.getAvailBridgeExtrinsicFromAvail)(recipient, sendingValue, substrateApi);
106
75
  };
107
76
  exports.createAvailBridgeExtrinsicFromAvail = createAvailBridgeExtrinsicFromAvail;
108
- const createPolygonBridgeExtrinsic = async _ref5 => {
77
+ const createPolygonBridgeExtrinsic = async _ref4 => {
109
78
  let {
110
79
  destinationChain,
111
80
  evmApi,
@@ -117,7 +86,7 @@ const createPolygonBridgeExtrinsic = async _ref5 => {
117
86
  recipient,
118
87
  sender,
119
88
  sendingValue
120
- } = _ref5;
89
+ } = _ref4;
121
90
  const isPolygonBridgeXcm = (0, _xcmParser._isPolygonBridgeXcm)(originChain, destinationChain);
122
91
  const isValidBridge = isPolygonBridgeXcm || (0, _xcmParser._isPosBridgeXcm)(originChain, destinationChain);
123
92
  if (!isValidBridge) {
@@ -143,9 +112,10 @@ const createXcmExtrinsicV2 = async request => {
143
112
  }
144
113
  };
145
114
  exports.createXcmExtrinsicV2 = createXcmExtrinsicV2;
146
- const dryRunXcmExtrinsicV2 = async request => {
115
+ const dryRunXcmExtrinsicV2 = async function (request) {
116
+ let isPreview = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
147
117
  try {
148
- const dryRunResult = await (0, _utils.dryRunXcm)(request);
118
+ const dryRunResult = isPreview ? await (0, _utils.dryRunPreviewXcm)(request) : await (0, _utils.dryRunXcm)(request);
149
119
  const originDryRunRs = dryRunResult.origin;
150
120
  if (originDryRunRs.success) {
151
121
  const {
@@ -176,7 +146,23 @@ const dryRunXcmExtrinsicV2 = async request => {
176
146
  }
177
147
  };
178
148
  exports.dryRunXcmExtrinsicV2 = dryRunXcmExtrinsicV2;
179
- const createAcrossBridgeExtrinsic = async _ref6 => {
149
+ const getXcmOriginFee = async request => {
150
+ try {
151
+ const xcmFeeInfo = await (0, _utils.estimateXcmFee)({
152
+ fromChainInfo: request.originChain,
153
+ fromTokenInfo: request.originTokenInfo,
154
+ toChainInfo: request.destinationChain,
155
+ recipient: request.recipient,
156
+ sender: request.sender,
157
+ value: request.sendingValue
158
+ });
159
+ return xcmFeeInfo === null || xcmFeeInfo === void 0 ? void 0 : xcmFeeInfo.origin.fee;
160
+ } catch (e) {
161
+ return undefined;
162
+ }
163
+ };
164
+ exports.getXcmOriginFee = getXcmOriginFee;
165
+ const createAcrossBridgeExtrinsic = async _ref5 => {
180
166
  let {
181
167
  destinationChain,
182
168
  destinationTokenInfo,
@@ -189,7 +175,7 @@ const createAcrossBridgeExtrinsic = async _ref6 => {
189
175
  recipient,
190
176
  sender,
191
177
  sendingValue
192
- } = _ref6;
178
+ } = _ref5;
193
179
  const isAcrossBridgeXcm = (0, _xcmParser._isAcrossBridgeXcm)(originChain, destinationChain);
194
180
  if (!isAcrossBridgeXcm) {
195
181
  throw new Error('This is not a valid AcrossBridge transfer');
@@ -209,7 +195,7 @@ const createAcrossBridgeExtrinsic = async _ref6 => {
209
195
  value: sendingValue
210
196
  });
211
197
  const _feeCustom = feeCustom;
212
- const feeCombine = (0, _utils3.combineEthFee)(feeInfo, feeOption, _feeCustom);
198
+ const feeCombine = (0, _utils2.combineEthFee)(feeInfo, feeOption, _feeCustom);
213
199
  if (!data) {
214
200
  throw new Error('Failed to fetch Across Bridge Data. Please try again later');
215
201
  }
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.STABLE_XCM_VERSION = void 0;
7
7
  exports.buildXcm = buildXcm;
8
+ exports.dryRunPreviewXcm = dryRunPreviewXcm;
8
9
  exports.dryRunXcm = dryRunXcm;
9
10
  exports.estimateXcmFee = estimateXcmFee;
10
11
  exports.isChainNotSupportDryRun = isChainNotSupportDryRun;
11
12
  exports.isChainNotSupportPolkadotApi = isChainNotSupportPolkadotApi;
12
- exports.isUseTeleportProtocol = isUseTeleportProtocol;
13
13
  var _paraspellChainMap = require("@subwallet/extension-base/constants/paraspell-chain-map");
14
14
  var _environment = require("@subwallet/extension-base/types/environment");
15
15
  var _utils = require("@subwallet/extension-base/utils");
16
+ var _bignumber = _interopRequireDefault(require("bignumber.js"));
16
17
  var _util = require("@polkadot/util");
17
18
  // Copyright 2019-2022 @subwallet/extension-base
18
19
  // SPDX-License-Identifier: Apache-2.0
@@ -20,8 +21,9 @@ var _util = require("@polkadot/util");
20
21
  const version = '/v4';
21
22
  const paraSpellApi = {
22
23
  buildXcm: `${version}/x-transfer`,
24
+ feeXcm: `${version}/xcm-fee`,
23
25
  dryRunXcm: `${version}/dry-run`,
24
- feeXcm: `${version}/xcm-fee`
26
+ dryRunPreviewXcm: `${version}/dry-run-preview`
25
27
  };
26
28
  function txHexToSubmittableExtrinsic(api, hex) {
27
29
  try {
@@ -163,6 +165,51 @@ async function dryRunXcm(request) {
163
165
  }
164
166
  return await response.json();
165
167
  }
168
+ async function dryRunPreviewXcm(request) {
169
+ var _originTokenInfo$meta3;
170
+ const {
171
+ destinationChain,
172
+ originChain,
173
+ originTokenInfo,
174
+ recipient,
175
+ sender,
176
+ sendingValue
177
+ } = request;
178
+ const paraSpellChainMap = await (0, _paraspellChainMap.fetchParaSpellChainMap)();
179
+ const paraSpellIdentifyV4 = (_originTokenInfo$meta3 = originTokenInfo.metadata) === null || _originTokenInfo$meta3 === void 0 ? void 0 : _originTokenInfo$meta3.paraSpellIdentifyV4;
180
+ if (!paraSpellIdentifyV4) {
181
+ throw new Error('Token is not support XCM at this time');
182
+ }
183
+ const bodyData = {
184
+ senderAddress: sender,
185
+ address: recipient,
186
+ from: paraSpellChainMap[originChain.slug],
187
+ to: paraSpellChainMap[destinationChain.slug],
188
+ currency: createParaSpellCurrency(paraSpellIdentifyV4, sendingValue),
189
+ options: {
190
+ abstractDecimals: false,
191
+ mintFeeAssets: true
192
+ }
193
+ };
194
+ const response = await (0, _utils.fetchFromProxyService)(_environment.ProxyServiceRoute.PARASPELL, paraSpellApi.dryRunPreviewXcm, {
195
+ method: 'POST',
196
+ body: JSON.stringify(bodyData),
197
+ headers: {
198
+ 'Content-Type': 'application/json',
199
+ Accept: 'application/json'
200
+ }
201
+ });
202
+ if (!response.ok) {
203
+ const error = await response.json();
204
+ return {
205
+ origin: {
206
+ success: false,
207
+ failureReason: error.message
208
+ }
209
+ };
210
+ }
211
+ return await response.json();
212
+ }
166
213
  async function estimateXcmFee(request) {
167
214
  var _fromTokenInfo$metada;
168
215
  const {
@@ -175,6 +222,8 @@ async function estimateXcmFee(request) {
175
222
  } = request;
176
223
  const paraSpellChainMap = await (0, _paraspellChainMap.fetchParaSpellChainMap)();
177
224
  const paraSpellIdentifyV4 = (_fromTokenInfo$metada = fromTokenInfo.metadata) === null || _fromTokenInfo$metada === void 0 ? void 0 : _fromTokenInfo$metada.paraSpellIdentifyV4;
225
+ const requestValue = (0, _bignumber.default)(value).gt(0) ? value : '1'; // avoid bug in-case estimate fee sendingValue <= 0;
226
+
178
227
  if (!paraSpellIdentifyV4) {
179
228
  console.error('Lack of paraspell metadata');
180
229
  return undefined;
@@ -184,7 +233,7 @@ async function estimateXcmFee(request) {
184
233
  address: recipient,
185
234
  from: paraSpellChainMap[fromChainInfo.slug],
186
235
  to: paraSpellChainMap[toChainInfo.slug],
187
- currency: createParaSpellCurrency(paraSpellIdentifyV4, value),
236
+ currency: createParaSpellCurrency(paraSpellIdentifyV4, requestValue),
188
237
  options: {
189
238
  abstractDecimals: false
190
239
  }
@@ -204,8 +253,6 @@ async function estimateXcmFee(request) {
204
253
  return await response.json();
205
254
  }
206
255
  function createParaSpellCurrency(paraSpellIdentifyV4, amount) {
207
- // todo: handle complex conditions for asset has same symbol in a chain: Id, Multi-location, ...
208
- // todo: or update all asset to use multi-location
209
256
  return {
210
257
  ...paraSpellIdentifyV4,
211
258
  amount
@@ -220,16 +267,4 @@ function isChainNotSupportDryRun(str) {
220
267
  const regex = /(?=.*DryRunApi)(?=.*not available).*/i; // Example: DryRunApi is not available on node Acala
221
268
 
222
269
  return regex.test(str);
223
- }
224
-
225
- // todo: remove
226
- const STABLE_XCM_VERSION = 3;
227
-
228
- // todo: remove
229
- exports.STABLE_XCM_VERSION = STABLE_XCM_VERSION;
230
- function isUseTeleportProtocol(originChainInfo, destChainInfo, tokenSlug) {
231
- 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);
232
- 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);
233
- const isXcmMythos = originChainInfo.slug === 'mythos' && destChainInfo.slug === 'statemint' && tokenSlug === 'mythos-NATIVE-MYTH' || originChainInfo.slug === 'statemint' && destChainInfo.slug === 'mythos' && tokenSlug === 'statemint-LOCAL-MYTH';
234
- return relayChainToSystemChain || systemChainToRelayChain || isXcmMythos;
235
270
  }