@subwallet/extension-base 1.3.17-0 → 1.3.18-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 (127) hide show
  1. package/background/KoniTypes.d.ts +7 -2
  2. package/cjs/constants/index.js +6 -3
  3. package/cjs/core/logic-validation/request.js +26 -19
  4. package/cjs/core/logic-validation/transfer.js +18 -17
  5. package/cjs/koni/api/contract-handler/evm/web3.js +3 -3
  6. package/cjs/koni/background/handlers/Extension.js +269 -123
  7. package/cjs/koni/background/handlers/State.js +1 -8
  8. package/cjs/packageInfo.js +1 -1
  9. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +1 -1
  10. package/cjs/services/balance-service/index.js +13 -0
  11. package/cjs/services/balance-service/transfer/smart-contract.js +47 -33
  12. package/cjs/services/balance-service/transfer/token.js +5 -4
  13. package/cjs/services/balance-service/transfer/xcm/availBridge.js +14 -18
  14. package/cjs/services/balance-service/transfer/xcm/index.js +30 -61
  15. package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +13 -17
  16. package/cjs/services/balance-service/transfer/xcm/posBridge.js +20 -21
  17. package/cjs/services/balance-service/transfer/xcm/snowBridge.js +7 -7
  18. package/cjs/services/balance-service/transfer/xcm/utils.js +2 -2
  19. package/cjs/services/chain-service/constants.js +3 -3
  20. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +7 -12
  21. package/cjs/services/earning-service/handlers/special.js +15 -4
  22. package/cjs/services/fee-service/interfaces.js +1 -0
  23. package/cjs/services/fee-service/service.js +111 -0
  24. package/cjs/services/fee-service/utils/index.js +99 -113
  25. package/cjs/services/storage-service/db-stores/Balance.js +3 -0
  26. package/cjs/services/swap-service/handler/asset-hub/handler.js +23 -7
  27. package/cjs/services/swap-service/handler/asset-hub/router.js +1 -1
  28. package/cjs/services/swap-service/handler/asset-hub/utils.js +4 -4
  29. package/cjs/services/swap-service/handler/base-handler.js +3 -1
  30. package/cjs/services/swap-service/handler/chainflip-handler.js +26 -5
  31. package/cjs/services/swap-service/handler/hydradx-handler.js +23 -8
  32. package/cjs/services/swap-service/handler/simpleswap-handler.js +24 -4
  33. package/cjs/services/swap-service/index.js +8 -8
  34. package/cjs/services/transaction-service/index.js +23 -3
  35. package/cjs/types/balance/transfer.js +1 -0
  36. package/cjs/types/fee/base.js +1 -0
  37. package/cjs/types/fee/evm.js +16 -1
  38. package/cjs/types/fee/index.js +37 -4
  39. package/cjs/types/fee/option.js +1 -0
  40. package/cjs/types/fee/subscription.js +1 -0
  41. package/cjs/types/fee/substrate.js +1 -0
  42. package/cjs/types/fee/ton.js +1 -0
  43. package/cjs/utils/fee/combine.js +50 -0
  44. package/cjs/utils/fee/index.js +27 -0
  45. package/cjs/utils/fee/transfer.js +374 -0
  46. package/cjs/utils/index.js +12 -0
  47. package/constants/index.d.ts +1 -0
  48. package/constants/index.js +1 -0
  49. package/core/logic-validation/request.js +17 -10
  50. package/core/logic-validation/transfer.d.ts +5 -5
  51. package/core/logic-validation/transfer.js +20 -19
  52. package/core/substrate/xcm-parser.d.ts +1 -1
  53. package/koni/api/contract-handler/evm/web3.js +3 -3
  54. package/koni/background/handlers/Extension.d.ts +3 -3
  55. package/koni/background/handlers/Extension.js +253 -107
  56. package/koni/background/handlers/State.js +1 -8
  57. package/package.json +55 -5
  58. package/packageInfo.js +1 -1
  59. package/services/balance-service/helpers/subscribe/substrate/index.js +1 -1
  60. package/services/balance-service/index.d.ts +1 -0
  61. package/services/balance-service/index.js +13 -0
  62. package/services/balance-service/transfer/smart-contract.d.ts +24 -4
  63. package/services/balance-service/transfer/smart-contract.js +45 -33
  64. package/services/balance-service/transfer/token.js +6 -5
  65. package/services/balance-service/transfer/xcm/availBridge.d.ts +3 -2
  66. package/services/balance-service/transfer/xcm/availBridge.js +11 -15
  67. package/services/balance-service/transfer/xcm/index.d.ts +12 -11
  68. package/services/balance-service/transfer/xcm/index.js +29 -58
  69. package/services/balance-service/transfer/xcm/polygonBridge.d.ts +4 -3
  70. package/services/balance-service/transfer/xcm/polygonBridge.js +13 -17
  71. package/services/balance-service/transfer/xcm/posBridge.d.ts +4 -3
  72. package/services/balance-service/transfer/xcm/posBridge.js +18 -19
  73. package/services/balance-service/transfer/xcm/snowBridge.d.ts +2 -1
  74. package/services/balance-service/transfer/xcm/snowBridge.js +7 -7
  75. package/services/balance-service/transfer/xcm/utils.js +2 -2
  76. package/services/chain-service/constants.js +3 -3
  77. package/services/earning-service/handlers/liquid-staking/stella-swap.js +7 -12
  78. package/services/earning-service/handlers/special.js +15 -4
  79. package/services/fee-service/interfaces.d.ts +5 -0
  80. package/services/fee-service/interfaces.js +1 -0
  81. package/services/fee-service/service.d.ts +4 -1
  82. package/services/fee-service/service.js +111 -0
  83. package/services/fee-service/utils/index.d.ts +8 -2
  84. package/services/fee-service/utils/index.js +92 -108
  85. package/services/storage-service/db-stores/Balance.d.ts +1 -0
  86. package/services/storage-service/db-stores/Balance.js +3 -0
  87. package/services/swap-service/handler/asset-hub/handler.d.ts +2 -1
  88. package/services/swap-service/handler/asset-hub/handler.js +23 -7
  89. package/services/swap-service/handler/asset-hub/router.js +2 -2
  90. package/services/swap-service/handler/asset-hub/utils.d.ts +1 -1
  91. package/services/swap-service/handler/asset-hub/utils.js +2 -2
  92. package/services/swap-service/handler/base-handler.d.ts +4 -1
  93. package/services/swap-service/handler/base-handler.js +3 -1
  94. package/services/swap-service/handler/chainflip-handler.d.ts +2 -1
  95. package/services/swap-service/handler/chainflip-handler.js +25 -4
  96. package/services/swap-service/handler/hydradx-handler.d.ts +2 -1
  97. package/services/swap-service/handler/hydradx-handler.js +22 -7
  98. package/services/swap-service/handler/simpleswap-handler.d.ts +2 -1
  99. package/services/swap-service/handler/simpleswap-handler.js +24 -4
  100. package/services/swap-service/index.js +8 -8
  101. package/services/transaction-service/index.js +23 -3
  102. package/services/transaction-service/types.d.ts +5 -4
  103. package/types/balance/transfer.d.ts +25 -0
  104. package/types/balance/transfer.js +1 -0
  105. package/types/fee/base.d.ts +8 -0
  106. package/types/fee/base.js +1 -0
  107. package/types/fee/evm.d.ts +46 -16
  108. package/types/fee/evm.js +10 -1
  109. package/types/fee/index.d.ts +4 -1
  110. package/types/fee/index.js +4 -1
  111. package/types/fee/option.d.ts +8 -0
  112. package/types/fee/option.js +1 -0
  113. package/types/fee/subscription.d.ts +12 -0
  114. package/types/fee/subscription.js +1 -0
  115. package/types/fee/substrate.d.ts +15 -0
  116. package/types/fee/substrate.js +1 -0
  117. package/types/fee/ton.d.ts +18 -0
  118. package/types/fee/ton.js +1 -0
  119. package/types/transaction/request.d.ts +13 -3
  120. package/utils/fee/combine.d.ts +12 -0
  121. package/utils/fee/combine.js +42 -0
  122. package/utils/fee/index.d.ts +2 -0
  123. package/utils/fee/index.js +5 -0
  124. package/utils/fee/transfer.d.ts +22 -0
  125. package/utils/fee/transfer.js +363 -0
  126. package/utils/index.d.ts +1 -0
  127. package/utils/index.js +1 -0
@@ -926,14 +926,7 @@ class KoniState {
926
926
  }
927
927
  })();
928
928
  promiseList.push(Promise.race([promise, timeoutPromise]).then(result => {
929
- var _result$gasPrice, _result$maxFeePerGas, _result$maxPriorityFe, _result$baseGasFee;
930
- return [slug, result ? {
931
- ...result,
932
- gasPrice: (_result$gasPrice = result.gasPrice) === null || _result$gasPrice === void 0 ? void 0 : _result$gasPrice.toString(),
933
- maxFeePerGas: (_result$maxFeePerGas = result.maxFeePerGas) === null || _result$maxFeePerGas === void 0 ? void 0 : _result$maxFeePerGas.toString(),
934
- maxPriorityFeePerGas: (_result$maxPriorityFe = result.maxPriorityFeePerGas) === null || _result$maxPriorityFe === void 0 ? void 0 : _result$maxPriorityFe.toString(),
935
- baseGasFee: (_result$baseGasFee = result.baseGasFee) === null || _result$baseGasFee === void 0 ? void 0 : _result$baseGasFee.toString()
936
- } : null];
929
+ return [slug, result || null];
937
930
  }));
938
931
  });
939
932
  return Object.fromEntries(await Promise.all(promiseList));
@@ -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.17-0'
16
+ version: '1.3.18-1'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -214,7 +214,7 @@ const subscribeForeignAssetBalance = async _ref2 => {
214
214
  const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
215
215
  try {
216
216
  if ((0, _utils2._isBridgedToken)(tokenInfo)) {
217
- const version = ['statemint', 'statemine'].includes(chainInfo.slug) ? 4 : 3;
217
+ const version = ['statemint', 'statemine', 'westend_assethub'].includes(chainInfo.slug) ? 4 : 3;
218
218
  const params = [{
219
219
  section: 'query',
220
220
  module: foreignAssetsAccountKey.split('_')[1],
@@ -289,6 +289,19 @@ class BalanceService {
289
289
  async getStoredBalance(address) {
290
290
  return await this.state.dbService.stores.balance.getBalanceMapByAddresses(address);
291
291
  }
292
+ async getTokensHasBalance(address, chain, tokenSlug) {
293
+ const balanceItems = await this.state.dbService.stores.balance.getBalanceHasAmount(address, chain);
294
+ const tokenHasBalanceInfoMap = {};
295
+ balanceItems.forEach(balanceItem => {
296
+ tokenHasBalanceInfoMap[balanceItem.tokenSlug] = balanceItem;
297
+ });
298
+ if (tokenSlug) {
299
+ return {
300
+ [tokenSlug]: tokenHasBalanceInfoMap[tokenSlug]
301
+ };
302
+ }
303
+ return tokenHasBalanceInfoMap;
304
+ }
292
305
  async handleResetBalance(forceRefresh) {
293
306
  if (forceRefresh) {
294
307
  this.balanceMap.setData({});
@@ -13,44 +13,63 @@ var _utils = require("@subwallet/extension-base/koni/api/contract-handler/utils"
13
13
  var _wasm = require("@subwallet/extension-base/koni/api/contract-handler/wasm");
14
14
  var _utils2 = require("@subwallet/extension-base/koni/api/contract-handler/wasm/utils");
15
15
  var _constants = require("@subwallet/extension-base/services/chain-service/constants");
16
- var _utils3 = require("@subwallet/extension-base/services/fee-service/utils");
16
+ var _utils3 = require("@subwallet/extension-base/utils");
17
17
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
18
18
  var _i18next = require("i18next");
19
19
  // Copyright 2019-2022 @subwallet/extension-base
20
20
  // SPDX-License-Identifier: Apache-2.0
21
21
 
22
- async function getEVMTransactionObject(chainInfo, from, to, value, transferAll, web3Api) {
23
- var _priority$maxFeePerGa, _priority$maxPriority;
24
- const networkKey = chainInfo.slug;
25
- const priority = await (0, _utils3.calculateGasFeeParams)(web3Api, networkKey);
22
+ async function getEVMTransactionObject(_ref) {
23
+ let {
24
+ chain,
25
+ evmApi,
26
+ feeCustom: _feeCustom,
27
+ feeInfo: _feeInfo,
28
+ feeOption,
29
+ from,
30
+ to,
31
+ transferAll,
32
+ value
33
+ } = _ref;
34
+ const feeCustom = _feeCustom;
35
+ const feeInfo = _feeInfo;
36
+ const feeCombine = (0, _utils3.combineEthFee)(feeInfo, feeOption, feeCustom);
26
37
  const transactionObject = {
27
38
  to: to,
28
39
  value: value,
29
40
  from: from,
30
- gasPrice: priority.gasPrice,
31
- maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
32
- maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
41
+ ...feeCombine
33
42
  };
34
- const gasLimit = await web3Api.api.eth.estimateGas(transactionObject);
43
+ const gasLimit = await evmApi.api.eth.estimateGas(transactionObject);
35
44
  transactionObject.gas = gasLimit;
36
45
  let estimateFee;
37
- if (priority.baseGasFee) {
38
- const maxFee = priority.maxFeePerGas;
46
+ if (feeCombine.maxFeePerGas) {
47
+ const maxFee = new _bignumber.default(feeCombine.maxFeePerGas);
39
48
  estimateFee = maxFee.multipliedBy(gasLimit);
40
49
  } else {
41
- estimateFee = new _bignumber.default(priority.gasPrice).multipliedBy(gasLimit);
50
+ estimateFee = new _bignumber.default(feeCombine.gasPrice || '0').multipliedBy(gasLimit);
42
51
  }
43
52
  transactionObject.value = transferAll ? new _bignumber.default(value).minus(estimateFee).toString() : value;
44
- if (_constants.EVM_REFORMAT_DECIMALS.acala.includes(networkKey)) {
53
+ if (_constants.EVM_REFORMAT_DECIMALS.acala.includes(chain)) {
45
54
  const numberReplace = 18 - 12;
46
55
  transactionObject.value = transactionObject.value.substring(0, transactionObject.value.length - 6) + new Array(numberReplace).fill('0').join('');
47
56
  }
48
57
  return [transactionObject, transactionObject.value.toString()];
49
58
  }
50
- async function getERC20TransactionObject(assetAddress, chainInfo, from, to, value, transferAll, evmApi) {
51
- var _priority$maxFeePerGa2, _priority$maxPriority2;
52
- const networkKey = chainInfo.slug;
59
+ async function getERC20TransactionObject(_ref2) {
60
+ let {
61
+ assetAddress,
62
+ evmApi,
63
+ feeCustom: _feeCustom,
64
+ feeInfo: _feeInfo,
65
+ feeOption,
66
+ from,
67
+ to,
68
+ transferAll,
69
+ value
70
+ } = _ref2;
53
71
  const erc20Contract = (0, _web.getERC20Contract)(assetAddress, evmApi);
72
+ const feeCustom = _feeCustom;
54
73
  let freeAmount = new _bignumber.default(0);
55
74
  let transferValue = value;
56
75
  if (transferAll) {
@@ -64,22 +83,19 @@ async function getERC20TransactionObject(assetAddress, chainInfo, from, to, valu
64
83
  return erc20Contract.methods.transfer(to, transferValue).encodeABI();
65
84
  }
66
85
  const transferData = generateTransferData(to, transferValue);
67
- const [gasLimit, priority] = await Promise.all([
68
86
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
69
- erc20Contract.methods.transfer(to, transferValue).estimateGas({
87
+ const gasLimit = await erc20Contract.methods.transfer(to, transferValue).estimateGas({
70
88
  from
71
- }).catch(() => {
72
- throw Error('Unable to estimate fee for this transaction. Try again or contact support at agent@subwallet.app');
73
- }), (0, _utils3.calculateGasFeeParams)(evmApi, networkKey)]);
89
+ });
90
+ const feeInfo = _feeInfo;
91
+ const feeCombine = (0, _utils3.combineEthFee)(feeInfo, feeOption, feeCustom);
74
92
  const transactionObject = {
75
93
  gas: gasLimit,
76
94
  from,
77
95
  value: '0',
78
96
  to: assetAddress,
79
97
  data: transferData,
80
- gasPrice: priority.gasPrice,
81
- maxFeePerGas: (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
82
- maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString()
98
+ ...feeCombine
83
99
  };
84
100
  if (transferAll) {
85
101
  transferValue = freeAmount.toFixed(0);
@@ -87,18 +103,16 @@ async function getERC20TransactionObject(assetAddress, chainInfo, from, to, valu
87
103
  }
88
104
  return [transactionObject, transferValue];
89
105
  }
90
- async function getERC721Transaction(web3Api, chain, contractAddress, senderAddress, recipientAddress, tokenId) {
91
- var _priority$maxFeePerGa3, _priority$maxPriority3;
106
+ async function getERC721Transaction(web3Api, chain, contractAddress, senderAddress, recipientAddress, tokenId, _feeInfo) {
92
107
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
93
108
  const contract = new web3Api.api.eth.Contract(_utils._ERC721_ABI, contractAddress);
94
109
  let gasLimit;
95
- let priority;
96
110
  try {
97
- [gasLimit, priority] = await Promise.all([
111
+ [gasLimit] = await Promise.all([
98
112
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
99
113
  contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).estimateGas({
100
114
  from: senderAddress
101
- }), (0, _utils3.calculateGasFeeParams)(web3Api, chain)]);
115
+ })]);
102
116
  } catch (e) {
103
117
  const error = e;
104
118
  if (error.message.includes('transfer to non ERC721Receiver implementer')) {
@@ -106,16 +120,16 @@ async function getERC721Transaction(web3Api, chain, contractAddress, senderAddre
106
120
  }
107
121
  throw error;
108
122
  }
123
+ const feeInfo = _feeInfo;
124
+ const feeCombine = (0, _utils3.combineEthFee)(feeInfo);
109
125
  return {
110
126
  from: senderAddress,
111
- gasPrice: priority.gasPrice,
112
- maxFeePerGas: (_priority$maxFeePerGa3 = priority.maxFeePerGas) === null || _priority$maxFeePerGa3 === void 0 ? void 0 : _priority$maxFeePerGa3.toString(),
113
- maxPriorityFeePerGas: (_priority$maxPriority3 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority3 === void 0 ? void 0 : _priority$maxPriority3.toString(),
114
127
  gas: gasLimit,
115
128
  to: contractAddress,
116
129
  value: '0x00',
117
130
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
118
- data: contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).encodeABI()
131
+ data: contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).encodeABI(),
132
+ ...feeCombine
119
133
  };
120
134
  }
121
135
  const mustFormatNumberReg = /^-?[0-9][0-9,.]+$/;
@@ -133,11 +133,12 @@ const getTransferMockTxFee = async (address, chainInfo, tokenInfo, api) => {
133
133
  };
134
134
  const gasLimit = await web3.api.eth.estimateGas(transaction);
135
135
  const priority = await (0, _utils4.calculateGasFeeParams)(web3, chainInfo.slug);
136
- if (priority.baseGasFee) {
137
- const maxFee = priority.maxFeePerGas;
138
- estimatedFee = maxFee.multipliedBy(gasLimit);
136
+ const combinedFee = (0, _utils5.combineEthFee)(priority);
137
+ if (combinedFee.maxFeePerGas) {
138
+ const maxFee = combinedFee.maxFeePerGas;
139
+ estimatedFee = (0, _bignumber.default)(maxFee).multipliedBy(gasLimit);
139
140
  } else {
140
- estimatedFee = new _bignumber.default(priority.gasPrice).multipliedBy(gasLimit);
141
+ estimatedFee = new _bignumber.default(combinedFee.gasPrice).multipliedBy(gasLimit);
141
142
  }
142
143
  } else if ((0, _utils3._isChainTonCompatible)(chainInfo) && (0, _utils3._isTokenTransferredByTon)(tokenInfo)) {
143
144
  const mockWalletContract = _uiKeyring.keyring.getPair(address).ton.currentContract;
@@ -12,8 +12,8 @@ exports.isAvailChainBridge = isAvailChainBridge;
12
12
  var _chainList = require("@subwallet/chain-list");
13
13
  var _web = require("@subwallet/extension-base/koni/api/contract-handler/evm/web3");
14
14
  var _utils = require("@subwallet/extension-base/koni/api/contract-handler/utils");
15
- var _utils2 = require("@subwallet/extension-base/services/fee-service/utils");
16
- var _utils3 = require("@subwallet/extension-base/services/inapp-notification-service/utils");
15
+ var _utils2 = require("@subwallet/extension-base/services/inapp-notification-service/utils");
16
+ var _utils3 = require("@subwallet/extension-base/utils");
17
17
  var _keyring = require("@subwallet/keyring");
18
18
  var _util = require("@polkadot/util");
19
19
  // Copyright 2019-2022 @subwallet/extension-base
@@ -26,8 +26,7 @@ const AvailBridgeConfig = {
26
26
  AVAIL_DOMAIN: 1
27
27
  };
28
28
  exports.AvailBridgeConfig = AvailBridgeConfig;
29
- async function getAvailBridgeTxFromEth(originChainInfo, sender, recipient, value, evmApi) {
30
- var _priority$maxFeePerGa, _priority$maxPriority;
29
+ async function getAvailBridgeTxFromEth(originChainInfo, sender, recipient, value, evmApi, fee, feeCustom, feeOption) {
31
30
  const availBridgeContractAddress = (0, _utils.getAvailBridgeGatewayContract)(originChainInfo.slug);
32
31
  const ABI = getAvailBridgeAbi(originChainInfo.slug);
33
32
  const availBridgeContract = (0, _web.getWeb3Contract)(availBridgeContractAddress, evmApi, ABI);
@@ -35,19 +34,19 @@ async function getAvailBridgeTxFromEth(originChainInfo, sender, recipient, value
35
34
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
36
35
  const sendAvail = availBridgeContract.methods.sendAVAIL(_address, value);
37
36
  const transferData = sendAvail.encodeABI();
38
- const priority = await (0, _utils2.calculateGasFeeParams)(evmApi, evmApi.chainSlug);
39
37
  const gasLimit = await sendAvail.estimateGas({
40
38
  from: sender
41
39
  });
40
+ const _feeCustom = feeCustom;
41
+ const feeInfo = fee;
42
+ const feeCombine = (0, _utils3.combineEthFee)(feeInfo, feeOption, _feeCustom);
42
43
  return {
43
44
  from: sender,
44
45
  to: availBridgeContractAddress,
45
46
  value: '0',
46
47
  data: transferData,
47
- gasPrice: priority.gasPrice,
48
- maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
49
- maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString(),
50
- gas: gasLimit
48
+ gas: gasLimit,
49
+ ...feeCombine
51
50
  };
52
51
  }
53
52
  async function getAvailBridgeExtrinsicFromAvail(recipient, sendingValue, substrateApi) {
@@ -118,12 +117,11 @@ async function getClaimProofOnEthereum(chainSlug, blockHash, transactionIndex) {
118
117
  function getAvailBridgeApi(chainSlug) {
119
118
  if (chainSlug === 'avail_mainnet' || chainSlug === _chainList.COMMON_CHAIN_SLUGS.ETHEREUM) {
120
119
  // todo: add COMMON_CHAIN_SLUGS for AVAIL, AVAIL TURING
121
- return _utils3.AVAIL_BRIDGE_API.AVAIL_MAINNET;
120
+ return _utils2.AVAIL_BRIDGE_API.AVAIL_MAINNET;
122
121
  }
123
- return _utils3.AVAIL_BRIDGE_API.AVAIL_TESTNET;
122
+ return _utils2.AVAIL_BRIDGE_API.AVAIL_TESTNET;
124
123
  }
125
- async function getClaimTxOnEthereum(chainSlug, notification, evmApi) {
126
- var _priority$maxFeePerGa2, _priority$maxPriority2;
124
+ async function getClaimTxOnEthereum(chainSlug, notification, evmApi, feeInfo) {
127
125
  const availBridgeContractAddress = (0, _utils.getAvailBridgeGatewayContract)(chainSlug);
128
126
  const ABI = getAvailBridgeAbi(chainSlug);
129
127
  const availBridgeContract = (0, _web.getWeb3Contract)(availBridgeContractAddress, evmApi, ABI);
@@ -159,16 +157,14 @@ async function getClaimTxOnEthereum(chainSlug, notification, evmApi) {
159
157
  const gasLimit = await transfer.estimateGas({
160
158
  from: metadata.receiverAddress
161
159
  });
162
- const priority = await (0, _utils2.calculateGasFeeParams)(evmApi, evmApi.chainSlug);
160
+ const feeCombine = (0, _utils3.combineEthFee)(feeInfo);
163
161
  return {
164
162
  from: metadata.receiverAddress,
165
163
  to: availBridgeContractAddress,
166
164
  value: '0',
167
165
  data: transferData,
168
- gasPrice: priority.gasPrice,
169
- maxFeePerGas: (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
170
- maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString(),
171
- gas: gasLimit
166
+ gas: gasLimit,
167
+ ...feeCombine
172
168
  };
173
169
  }
174
170
  function getAddressMessage(notification) {
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
- exports.getXcmMockTxFee = exports.createXcmExtrinsic = exports.createSnowBridgeExtrinsic = exports.createPolygonBridgeExtrinsic = exports.createAvailBridgeTxFromEth = exports.createAvailBridgeExtrinsicFromAvail = void 0;
6
+ exports.createXcmExtrinsic = exports.createSnowBridgeExtrinsic = exports.createPolygonBridgeExtrinsic = exports.createAvailBridgeTxFromEth = exports.createAvailBridgeExtrinsicFromAvail = void 0;
8
7
  var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
9
8
  var _availBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge");
10
9
  var _polkadotXcm = require("@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm");
@@ -14,26 +13,25 @@ var _xcmPallet = require("@subwallet/extension-base/services/balance-service/tra
14
13
  var _xTokens = require("@subwallet/extension-base/services/balance-service/transfer/xcm/xTokens");
15
14
  var _constants = require("@subwallet/extension-base/services/chain-service/constants");
16
15
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
17
- var _bignumber = _interopRequireDefault(require("bignumber.js"));
18
- var _util = require("@polkadot/util");
19
- var _utilCrypto = require("@polkadot/util-crypto");
20
16
  var _posBridge = require("./posBridge");
21
17
  // Copyright 2019-2022 @subwallet/extension-base
22
18
  // SPDX-License-Identifier: Apache-2.0
23
19
 
20
+ // SnowBridge
24
21
  const createSnowBridgeExtrinsic = async _ref => {
25
22
  let {
26
- chainInfoMap,
27
- destinationTokenInfo,
23
+ destinationChain,
28
24
  evmApi,
25
+ feeCustom,
26
+ feeInfo,
27
+ feeOption,
28
+ originChain,
29
29
  originTokenInfo,
30
30
  recipient,
31
31
  sender,
32
32
  sendingValue
33
33
  } = _ref;
34
- const originChainInfo = chainInfoMap[originTokenInfo.originChain];
35
- const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
36
- if (!(0, _xcmParser._isSnowBridgeXcm)(originChainInfo, destinationChainInfo)) {
34
+ if (!(0, _xcmParser._isSnowBridgeXcm)(originChain, destinationChain)) {
37
35
  throw new Error('This is not a valid SnowBridge transfer');
38
36
  }
39
37
  if (!evmApi) {
@@ -42,52 +40,51 @@ const createSnowBridgeExtrinsic = async _ref => {
42
40
  if (!sender) {
43
41
  throw Error('Sender is required');
44
42
  }
45
- return (0, _snowBridge.getSnowBridgeEvmTransfer)(originTokenInfo, originChainInfo, destinationChainInfo, sender, recipient, sendingValue, evmApi);
43
+ return (0, _snowBridge.getSnowBridgeEvmTransfer)(originTokenInfo, originChain, destinationChain, sender, recipient, sendingValue, evmApi, feeInfo, feeCustom, feeOption);
46
44
  };
47
45
  exports.createSnowBridgeExtrinsic = createSnowBridgeExtrinsic;
48
46
  const createXcmExtrinsic = async _ref2 => {
49
47
  let {
50
- chainInfoMap,
51
- destinationTokenInfo,
48
+ destinationChain,
49
+ originChain,
52
50
  originTokenInfo,
53
51
  recipient,
54
52
  sendingValue,
55
53
  substrateApi
56
54
  } = _ref2;
57
- const originChainInfo = chainInfoMap[originTokenInfo.originChain];
58
- const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
59
55
  if (!substrateApi) {
60
56
  throw Error('Substrate API is not available');
61
57
  }
62
58
  const chainApi = await substrateApi.isReady;
63
59
  const api = chainApi.api;
64
- const polkadotXcmSpecialCases = _constants._XCM_CHAIN_GROUP.polkadotXcmSpecialCases.includes(originChainInfo.slug) && (0, _utils._isNativeToken)(originTokenInfo);
60
+ const polkadotXcmSpecialCases = _constants._XCM_CHAIN_GROUP.polkadotXcmSpecialCases.includes(originChain.slug) && (0, _utils._isNativeToken)(originTokenInfo);
65
61
  if (_constants._XCM_CHAIN_GROUP.polkadotXcm.includes(originTokenInfo.originChain) || polkadotXcmSpecialCases) {
66
- return (0, _polkadotXcm.getExtrinsicByPolkadotXcmPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
62
+ return (0, _polkadotXcm.getExtrinsicByPolkadotXcmPallet)(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
67
63
  }
68
64
  if (_constants._XCM_CHAIN_GROUP.xcmPallet.includes(originTokenInfo.originChain)) {
69
- return (0, _xcmPallet.getExtrinsicByXcmPalletPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
65
+ return (0, _xcmPallet.getExtrinsicByXcmPalletPallet)(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
70
66
  }
71
- return (0, _xTokens.getExtrinsicByXtokensPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
67
+ return (0, _xTokens.getExtrinsicByXtokensPallet)(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
72
68
  };
73
69
  exports.createXcmExtrinsic = createXcmExtrinsic;
74
70
  const createAvailBridgeTxFromEth = _ref3 => {
75
71
  let {
76
- chainInfoMap,
77
72
  evmApi,
78
- originTokenInfo,
73
+ feeCustom,
74
+ feeInfo,
75
+ feeOption,
76
+ originChain,
79
77
  recipient,
80
78
  sender,
81
79
  sendingValue
82
80
  } = _ref3;
83
- const originChainInfo = chainInfoMap[originTokenInfo.originChain];
84
81
  if (!evmApi) {
85
82
  throw Error('Evm API is not available');
86
83
  }
87
84
  if (!sender) {
88
85
  throw Error('Sender is required');
89
86
  }
90
- return (0, _availBridge.getAvailBridgeTxFromEth)(originChainInfo, sender, recipient, sendingValue, evmApi);
87
+ return (0, _availBridge.getAvailBridgeTxFromEth)(originChain, sender, recipient, sendingValue, evmApi, feeInfo, feeCustom, feeOption);
91
88
  };
92
89
  exports.createAvailBridgeTxFromEth = createAvailBridgeTxFromEth;
93
90
  const createAvailBridgeExtrinsicFromAvail = async _ref4 => {
@@ -104,18 +101,19 @@ const createAvailBridgeExtrinsicFromAvail = async _ref4 => {
104
101
  exports.createAvailBridgeExtrinsicFromAvail = createAvailBridgeExtrinsicFromAvail;
105
102
  const createPolygonBridgeExtrinsic = async _ref5 => {
106
103
  let {
107
- chainInfoMap,
108
- destinationTokenInfo,
104
+ destinationChain,
109
105
  evmApi,
106
+ feeCustom,
107
+ feeInfo,
108
+ feeOption,
109
+ originChain,
110
110
  originTokenInfo,
111
111
  recipient,
112
112
  sender,
113
113
  sendingValue
114
114
  } = _ref5;
115
- const originChainInfo = chainInfoMap[originTokenInfo.originChain];
116
- const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
117
- const isPolygonBridgeXcm = (0, _xcmParser._isPolygonBridgeXcm)(originChainInfo, destinationChainInfo);
118
- const isValidBridge = isPolygonBridgeXcm || (0, _xcmParser._isPosBridgeXcm)(originChainInfo, destinationChainInfo);
115
+ const isPolygonBridgeXcm = (0, _xcmParser._isPolygonBridgeXcm)(originChain, destinationChain);
116
+ const isValidBridge = isPolygonBridgeXcm || (0, _xcmParser._isPosBridgeXcm)(originChain, destinationChain);
119
117
  if (!isValidBridge) {
120
118
  throw new Error('This is not a valid PolygonBridge transfer');
121
119
  }
@@ -125,37 +123,8 @@ const createPolygonBridgeExtrinsic = async _ref5 => {
125
123
  if (!sender) {
126
124
  throw Error('Sender is required');
127
125
  }
128
- const sourceChain = originChainInfo.slug;
126
+ const sourceChain = originChain.slug;
129
127
  const createExtrinsic = isPolygonBridgeXcm ? sourceChain === 'polygonzkEvm_cardona' || sourceChain === 'polygonZkEvm' ? _polygonBridge._createPolygonBridgeL2toL1Extrinsic : _polygonBridge._createPolygonBridgeL1toL2Extrinsic : sourceChain === 'polygon_amoy' || sourceChain === 'polygon' ? _posBridge._createPosBridgeL2toL1Extrinsic : _posBridge._createPosBridgeL1toL2Extrinsic;
130
- return createExtrinsic(originTokenInfo, originChainInfo, sender, recipient, sendingValue, evmApi);
131
- };
132
- exports.createPolygonBridgeExtrinsic = createPolygonBridgeExtrinsic;
133
- const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo) => {
134
- try {
135
- var _paymentInfo$partialF;
136
- const destChainInfo = chainInfoMap[destinationTokenInfo.originChain];
137
- const originChainInfo = chainInfoMap[originTokenInfo.originChain];
138
- const fakeAddress = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap'; // todo: move this
139
- const substrateAddress = fakeAddress; // todo: move this
140
- const evmAddress = (0, _util.u8aToHex)((0, _utilCrypto.addressToEvm)(fakeAddress)); // todo: move this
141
-
142
- // mock receiving account from sender
143
- const sender = (0, _utils._isChainEvmCompatible)(originChainInfo) ? evmAddress : substrateAddress;
144
- const recipient = (0, _utils._isChainEvmCompatible)(destChainInfo) ? evmAddress : substrateAddress;
145
- const mockTx = await createXcmExtrinsic({
146
- chainInfoMap,
147
- destinationTokenInfo,
148
- originTokenInfo,
149
- sender,
150
- recipient,
151
- sendingValue: '1000000000000000000',
152
- substrateApi
153
- });
154
- const paymentInfo = await mockTx.paymentInfo(fakeAddress);
155
- return new _bignumber.default((paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0');
156
- } catch (e) {
157
- console.error('error mocking xcm tx fee', e);
158
- return new _bignumber.default(0);
159
- }
128
+ return createExtrinsic(originTokenInfo, originChain, sender, recipient, sendingValue, evmApi, feeInfo, feeCustom, feeOption);
160
129
  };
161
- exports.getXcmMockTxFee = getXcmMockTxFee;
130
+ exports.createPolygonBridgeExtrinsic = createPolygonBridgeExtrinsic;
@@ -13,7 +13,7 @@ var _chainList = require("@subwallet/chain-list");
13
13
  var _web = require("@subwallet/extension-base/koni/api/contract-handler/evm/web3");
14
14
  var _utils = require("@subwallet/extension-base/koni/api/contract-handler/utils");
15
15
  var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
16
- var _utils3 = require("@subwallet/extension-base/services/fee-service/utils");
16
+ var _utils3 = require("@subwallet/extension-base/utils");
17
17
  // Copyright 2019-2022 @subwallet/extension-base
18
18
  // SPDX-License-Identifier: Apache-2.0
19
19
 
@@ -27,8 +27,7 @@ const POLYGON_GAS_INDEXER = {
27
27
  TESTNET: 'https://gasstation.polygon.technology/zkevm/cardona'
28
28
  };
29
29
  exports.POLYGON_GAS_INDEXER = POLYGON_GAS_INDEXER;
30
- async function createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, destinationNetwork, evmApi) {
31
- var _priority$maxFeePerGa, _priority$maxPriority;
30
+ async function createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, destinationNetwork, evmApi, _feeInfo, feeCustom, feeOption) {
32
31
  const polygonBridgeContractAddress = (0, _utils.getPolygonBridgeContract)(originChainInfo.slug);
33
32
  const polygonBridgeContract = (0, _web.getWeb3Contract)(polygonBridgeContractAddress, evmApi, _utils._POLYGON_BRIDGE_ABI);
34
33
  const tokenContract = (0, _utils2._getContractAddressOfToken)(tokenInfo) || '0x0000000000000000000000000000000000000000'; // FOR Ethereum: use null address
@@ -40,28 +39,27 @@ async function createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender
40
39
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
41
40
  const transferCall = polygonBridgeContract.methods.bridgeAsset(destinationNetwork, recipientAddress, value, tokenContract, true, '0x');
42
41
  const transferEncodedCall = transferCall.encodeABI();
43
- const priority = await (0, _utils3.calculateGasFeeParams)(evmApi, evmApi.chainSlug);
42
+ const feeInfo = _feeInfo;
43
+ const feeCombine = (0, _utils3.combineEthFee)(feeInfo, feeOption, feeCustom);
44
44
  const transactionConfig = {
45
45
  from: sender,
46
46
  to: polygonBridgeContractAddress,
47
47
  value: value,
48
48
  data: transferEncodedCall,
49
- gasPrice: priority.gasPrice,
50
- maxFeePerGas: priority === null || priority === void 0 ? void 0 : (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
51
- maxPriorityFeePerGas: priority === null || priority === void 0 ? void 0 : (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
49
+ ...feeCombine
52
50
  };
53
51
  const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
54
52
  transactionConfig.gas = gasLimit.toString();
55
53
  return transactionConfig;
56
54
  }
57
- async function _createPolygonBridgeL1toL2Extrinsic(tokenInfo, originChainInfo, sender, recipientAddress, value, evmApi) {
58
- return createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, 1, evmApi);
55
+ async function _createPolygonBridgeL1toL2Extrinsic(tokenInfo, originChainInfo, sender, recipientAddress, value, evmApi, feeInfo, feeCustom, feeOption) {
56
+ return createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, 1, evmApi, feeInfo, feeCustom, feeOption);
59
57
  }
60
- async function _createPolygonBridgeL2toL1Extrinsic(tokenInfo, originChainInfo, sender, recipientAddress, value, evmApi) {
61
- return createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, 0, evmApi);
58
+ async function _createPolygonBridgeL2toL1Extrinsic(tokenInfo, originChainInfo, sender, recipientAddress, value, evmApi, feeInfo, feeCustom, feeOption) {
59
+ return createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, 0, evmApi, feeInfo, feeCustom, feeOption);
62
60
  }
63
- async function getClaimPolygonBridge(chainSlug, notification, evmApi) {
64
- var _metadata$sourceNetwo, _metadata$counter, _priority$maxFeePerGa2, _priority$maxPriority2;
61
+ async function getClaimPolygonBridge(chainSlug, notification, evmApi, feeInfo) {
62
+ var _metadata$sourceNetwo, _metadata$counter;
65
63
  const polygonBridgeContractAddress = (0, _utils.getPolygonBridgeContract)(chainSlug);
66
64
  const polygonBridgeContract = (0, _web.getWeb3Contract)(polygonBridgeContractAddress, evmApi, _utils._POLYGON_BRIDGE_ABI);
67
65
  const metadata = notification.metadata;
@@ -73,15 +71,13 @@ async function getClaimPolygonBridge(chainSlug, notification, evmApi) {
73
71
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
74
72
  const transferCall = polygonBridgeContract.methods.claimAsset(proof.merkle_proof, proof.rollup_merkle_proof, metadata.counter, proof.main_exit_root, proof.rollup_exit_root, metadata.originTokenNetwork, metadata.originTokenAddress, metadata.destinationNetwork, metadata.receiver, metadata.amounts[0], '0x');
75
73
  const transferEncodedCall = transferCall.encodeABI();
76
- const priority = await (0, _utils3.calculateGasFeeParams)(evmApi, evmApi.chainSlug);
74
+ const feeCombine = (0, _utils3.combineEthFee)(feeInfo);
77
75
  const transactionConfig = {
78
76
  from: metadata.userAddress,
79
77
  to: polygonBridgeContractAddress,
80
78
  value: '0',
81
79
  data: transferEncodedCall,
82
- gasPrice: priority.gasPrice,
83
- maxFeePerGas: (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
84
- maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString()
80
+ ...feeCombine
85
81
  };
86
82
  const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
87
83
  transactionConfig.gas = gasLimit.toString();