@subwallet/extension-base 1.3.17-0 → 1.3.18-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 (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 +21 -6
  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 +2 -0
  30. package/cjs/services/swap-service/handler/chainflip-handler.js +25 -4
  31. package/cjs/services/swap-service/handler/hydradx-handler.js +20 -6
  32. package/cjs/services/swap-service/handler/simpleswap-handler.js +23 -3
  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 +21 -6
  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 +2 -0
  94. package/services/swap-service/handler/chainflip-handler.d.ts +2 -1
  95. package/services/swap-service/handler/chainflip-handler.js +24 -3
  96. package/services/swap-service/handler/hydradx-handler.d.ts +2 -1
  97. package/services/swap-service/handler/hydradx-handler.js +19 -5
  98. package/services/swap-service/handler/simpleswap-handler.d.ts +2 -1
  99. package/services/swap-service/handler/simpleswap-handler.js +23 -3
  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
@@ -8,7 +8,6 @@ exports.default = void 0;
8
8
  exports.isJsonPayload = isJsonPayload;
9
9
  var _common = require("@ethereumjs/common");
10
10
  var _tx = require("@ethereumjs/tx");
11
- var _chainList = require("@subwallet/chain-list");
12
11
  var _types = require("@subwallet/chain-list/types");
13
12
  var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
14
13
  var _helpers = require("@subwallet/extension-base/background/handlers/helpers");
@@ -39,25 +38,28 @@ var _posBridge = require("@subwallet/extension-base/services/balance-service/tra
39
38
  var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
40
39
  var _types2 = require("@subwallet/extension-base/services/chain-service/types");
41
40
  var _utils4 = require("@subwallet/extension-base/services/chain-service/utils");
41
+ var _utils5 = require("@subwallet/extension-base/services/fee-service/utils");
42
42
  var _constants3 = require("@subwallet/extension-base/services/request-service/constants");
43
43
  var _constants4 = require("@subwallet/extension-base/services/setting-service/constants");
44
+ var _utils6 = require("@subwallet/extension-base/services/swap-service/handler/asset-hub/utils");
44
45
  var _helpers2 = require("@subwallet/extension-base/services/wallet-connect-service/helpers");
45
46
  var _storage = require("@subwallet/extension-base/storage");
46
47
  var _stores = require("@subwallet/extension-base/stores");
47
48
  var _types3 = require("@subwallet/extension-base/types");
48
- var _utils5 = require("@subwallet/extension-base/utils");
49
+ var _utils7 = require("@subwallet/extension-base/utils");
49
50
  var _parseTransaction2 = require("@subwallet/extension-base/utils/eth/parseTransaction");
51
+ var _getId = require("@subwallet/extension-base/utils/getId");
50
52
  var _keyring = require("@subwallet/keyring");
51
53
  var _types4 = require("@subwallet/keyring/types");
52
54
  var _uiKeyring = require("@subwallet/ui-keyring");
53
- var _utils6 = require("@walletconnect/utils");
55
+ var _utils8 = require("@walletconnect/utils");
54
56
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
55
57
  var _i18next = require("i18next");
56
58
  var _rxjs = require("rxjs");
57
59
  var _types5 = require("@polkadot/types");
58
60
  var _util = require("@polkadot/util");
59
61
  var _utilCrypto = require("@polkadot/util-crypto");
60
- var _utils7 = require("../utils");
62
+ var _utils9 = require("../utils");
61
63
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
62
64
  // SPDX-License-Identifier: Apache-2.0
63
65
 
@@ -272,7 +274,7 @@ class KoniExtension {
272
274
  const accounts = keyringService.context.accounts;
273
275
  const transformedAccounts = Object.values(accounts);
274
276
  const responseData = {
275
- accounts: transformedAccounts !== null && transformedAccounts !== void 0 && transformedAccounts.length ? [(0, _utils5.combineAllAccountProxy)(transformedAccounts), ...transformedAccounts] : [],
277
+ accounts: transformedAccounts !== null && transformedAccounts !== void 0 && transformedAccounts.length ? [(0, _utils7.combineAllAccountProxy)(transformedAccounts), ...transformedAccounts] : [],
276
278
  currentAccountProxy: currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.proxyId
277
279
  };
278
280
  const accountProxyMapObservable = keyringService.context.observable.accounts;
@@ -286,7 +288,7 @@ class KoniExtension {
286
288
  currentAccount
287
289
  } = _ref7;
288
290
  const transformedAccounts = Object.values(accountProxies);
289
- responseData.accounts = transformedAccounts !== null && transformedAccounts !== void 0 && transformedAccounts.length ? [(0, _utils5.combineAllAccountProxy)(transformedAccounts), ...transformedAccounts] : [];
291
+ responseData.accounts = transformedAccounts !== null && transformedAccounts !== void 0 && transformedAccounts.length ? [(0, _utils7.combineAllAccountProxy)(transformedAccounts), ...transformedAccounts] : [];
290
292
  responseData.currentAccountProxy = currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.proxyId;
291
293
  console.debug('subscriptionAccountGroups', responseData);
292
294
  cb(responseData);
@@ -307,10 +309,10 @@ class KoniExtension {
307
309
  const cb = (0, _subscriptions.createSubscription)(id, port);
308
310
  const combineFunction = async (chainInfoMap, accountProxyMap, _contacts) => {
309
311
  const accountProxies = Object.values(accountProxyMap);
310
- const contacts = (0, _utils5.transformAddresses)(_contacts);
312
+ const contacts = (0, _utils7.transformAddresses)(_contacts);
311
313
  const chainInfo = chainInfoMap[chain];
312
314
  const substrateApi = this.#koniState.chainService.getSubstrateApi(chain);
313
- const rs = await (0, _utils5._analyzeAddress)(data, accountProxies, contacts, chainInfo, substrateApi);
315
+ const rs = await (0, _utils7._analyzeAddress)(data, accountProxies, contacts, chainInfo, substrateApi);
314
316
  return {
315
317
  id,
316
318
  ...rs
@@ -350,7 +352,7 @@ class KoniExtension {
350
352
  const _cb = (0, _subscriptions.createSubscription)(id, port);
351
353
  let old = '';
352
354
  const subscription = this.#koniState.keyringService.context.observable.contacts.subscribe(subjectInfo => {
353
- const addresses = (0, _utils5.transformAddresses)(subjectInfo);
355
+ const addresses = (0, _utils7.transformAddresses)(subjectInfo);
354
356
  const _new = JSON.stringify(addresses);
355
357
  if (old !== _new) {
356
358
  _cb({
@@ -367,7 +369,7 @@ class KoniExtension {
367
369
  });
368
370
  const subjectInfo = this.#koniState.keyringService.context.contacts;
369
371
  return {
370
- addresses: (0, _utils5.transformAccounts)(subjectInfo)
372
+ addresses: (0, _utils7.transformAccounts)(subjectInfo)
371
373
  };
372
374
  }
373
375
 
@@ -380,7 +382,7 @@ class KoniExtension {
380
382
  chain
381
383
  } = _ref9;
382
384
  if ((0, _keyring.isAddress)(accountId)) {
383
- const address = (0, _utils5.reformatAddress)(accountId);
385
+ const address = (0, _utils7.reformatAddress)(accountId);
384
386
  const account = _uiKeyring.keyring.getAccount(address);
385
387
  const contact = _uiKeyring.keyring.getAddress(address, 'address');
386
388
  if (account) {
@@ -426,7 +428,7 @@ class KoniExtension {
426
428
  meta
427
429
  } = _ref10;
428
430
  if ((0, _keyring.isAddress)(address)) {
429
- const _address = (0, _utils5.reformatAddress)(address);
431
+ const _address = (0, _utils7.reformatAddress)(address);
430
432
  _uiKeyring.keyring.saveAddress(_address, meta);
431
433
  return true;
432
434
  } else {
@@ -442,7 +444,7 @@ class KoniExtension {
442
444
  address
443
445
  } = _ref11;
444
446
  if ((0, _keyring.isAddress)(address)) {
445
- const _address = (0, _utils5.reformatAddress)(address);
447
+ const _address = (0, _utils7.reformatAddress)(address);
446
448
  _uiKeyring.keyring.forgetAddress(_address);
447
449
  return true;
448
450
  } else {
@@ -571,7 +573,7 @@ class KoniExtension {
571
573
  }
572
574
  getPairs() {
573
575
  const storedAccounts = this.#koniState.keyringService.context.pairs;
574
- return (0, _utils5.transformAccounts)(storedAccounts);
576
+ return (0, _utils7.transformAccounts)(storedAccounts);
575
577
  }
576
578
  isAddressValidWithAuthType(address, accountAuthTypes) {
577
579
  const type = (0, _keyring.getKeypairTypeByAddress)(address);
@@ -1080,7 +1082,7 @@ class KoniExtension {
1080
1082
  const addresses = _uiKeyring.keyring.getAccounts().map(a => a.address);
1081
1083
 
1082
1084
  // Re-filter
1083
- cb(histories.filter(item => addresses.some(address => (0, _utils5.isSameAddress)(item.address, address))));
1085
+ cb(histories.filter(item => addresses.some(address => (0, _utils7.isSameAddress)(item.address, address))));
1084
1086
  });
1085
1087
  this.createUnsubscriptionHandle(id, subscription.unsubscribe);
1086
1088
  port.onDisconnect.addListener(() => {
@@ -1089,7 +1091,7 @@ class KoniExtension {
1089
1091
  const addresses = _uiKeyring.keyring.getAccounts().map(a => a.address);
1090
1092
 
1091
1093
  // Re-filter
1092
- return historySubject.getValue().filter(item => addresses.some(address => (0, _utils5.isSameAddress)(item.address, address)));
1094
+ return historySubject.getValue().filter(item => addresses.some(address => (0, _utils7.isSameAddress)(item.address, address)));
1093
1095
  }
1094
1096
  subscribeHistoryByChainAndAddress(_ref26, id, port) {
1095
1097
  let {
@@ -1141,8 +1143,11 @@ class KoniExtension {
1141
1143
  }
1142
1144
  async makeTransfer(inputData) {
1143
1145
  const {
1146
+ chain,
1147
+ feeCustom,
1148
+ feeOption,
1144
1149
  from,
1145
- networkKey,
1150
+ nonNativeTokenPayFeeSlug,
1146
1151
  to,
1147
1152
  tokenSlug,
1148
1153
  transferAll,
@@ -1150,12 +1155,13 @@ class KoniExtension {
1150
1155
  value
1151
1156
  } = inputData;
1152
1157
  const transferTokenInfo = this.#koniState.chainService.getAssetBySlug(tokenSlug);
1153
- const [errors,,] = (0, _transfer.validateTransferRequest)(transferTokenInfo, from, to, value, transferAll);
1158
+ const errors = (0, _transfer.validateTransferRequest)(transferTokenInfo, from, to, value, transferAll);
1154
1159
  const warnings = [];
1155
- const chainInfo = this.#koniState.getChainInfo(networkKey);
1156
- const nativeTokenInfo = this.#koniState.getNativeTokenInfo(networkKey);
1160
+ const chainInfo = this.#koniState.getChainInfo(chain);
1161
+ const nativeTokenInfo = this.#koniState.getNativeTokenInfo(chain);
1157
1162
  const nativeTokenSlug = nativeTokenInfo.slug;
1158
1163
  const isTransferNativeToken = nativeTokenSlug === tokenSlug;
1164
+ const isTransferLocalTokenAndPayThatTokenAsFee = !isTransferNativeToken && nonNativeTokenPayFeeSlug === tokenSlug;
1159
1165
  const extrinsicType = isTransferNativeToken ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.TRANSFER_TOKEN;
1160
1166
  let chainType = _KoniTypes.ChainType.SUBSTRATE;
1161
1167
  const transferAmount = {
@@ -1166,7 +1172,7 @@ class KoniExtension {
1166
1172
  let transaction;
1167
1173
  const transferTokenAvailable = await this.getAddressTransferableBalance({
1168
1174
  address: from,
1169
- networkKey,
1175
+ networkKey: chain,
1170
1176
  token: tokenSlug,
1171
1177
  extrinsicType
1172
1178
  });
@@ -1174,38 +1180,60 @@ class KoniExtension {
1174
1180
  if ((0, _utilCrypto.isEthereumAddress)(from) && (0, _utilCrypto.isEthereumAddress)(to) && (0, _utils4._isTokenTransferredByEvm)(transferTokenInfo)) {
1175
1181
  chainType = _KoniTypes.ChainType.EVM;
1176
1182
  const txVal = transferAll ? transferTokenAvailable.value : value || '0';
1177
- const evmApi = this.#koniState.getEvmApi(networkKey);
1183
+ const evmApi = this.#koniState.getEvmApi(chain);
1184
+ const feeInfo = await this.#koniState.feeService.subscribeChainFee((0, _getId.getId)(), chain, 'evm');
1178
1185
 
1179
1186
  // todo: refactor: merge getERC20TransactionObject & getEVMTransactionObject
1180
1187
  // Estimate with EVM API
1181
1188
  if ((0, _utils4._isTokenEvmSmartContract)(transferTokenInfo) || (0, _utils4._isLocalToken)(transferTokenInfo)) {
1182
- [transaction, transferAmount.value] = await (0, _smartContract.getERC20TransactionObject)((0, _utils4._getContractAddressOfToken)(transferTokenInfo), chainInfo, from, to, txVal, !!transferAll, evmApi);
1189
+ [transaction, transferAmount.value] = await (0, _smartContract.getERC20TransactionObject)({
1190
+ assetAddress: (0, _utils4._getContractAddressOfToken)(transferTokenInfo),
1191
+ chain,
1192
+ evmApi,
1193
+ feeCustom,
1194
+ feeInfo,
1195
+ feeOption,
1196
+ from,
1197
+ to,
1198
+ transferAll,
1199
+ value: txVal
1200
+ });
1183
1201
  } else {
1184
- [transaction, transferAmount.value] = await (0, _smartContract.getEVMTransactionObject)(chainInfo, from, to, txVal, !!transferAll, evmApi);
1202
+ [transaction, transferAmount.value] = await (0, _smartContract.getEVMTransactionObject)({
1203
+ chain,
1204
+ evmApi,
1205
+ feeCustom,
1206
+ feeInfo,
1207
+ feeOption,
1208
+ from,
1209
+ to,
1210
+ transferAll,
1211
+ value: txVal
1212
+ });
1185
1213
  }
1186
1214
  } else if ((0, _utils4._isMantaZkAsset)(transferTokenInfo)) {
1187
1215
  transaction = undefined;
1188
1216
  transferAmount.value = '0';
1189
1217
  } else if ((0, _keyring.isTonAddress)(from) && (0, _keyring.isTonAddress)(to) && (0, _utils4._isTokenTransferredByTon)(transferTokenInfo)) {
1190
1218
  chainType = _KoniTypes.ChainType.TON;
1191
- const tonApi = this.#koniState.getTonApi(networkKey);
1219
+ const tonApi = this.#koniState.getTonApi(chain);
1192
1220
  [transaction, transferAmount.value] = await (0, _tonTransfer.createTonTransaction)({
1193
1221
  tokenInfo: transferTokenInfo,
1194
1222
  from,
1195
1223
  to,
1196
- networkKey,
1224
+ networkKey: chain,
1197
1225
  value: value || '0',
1198
1226
  transferAll: !!transferAll,
1199
1227
  // currently not used
1200
1228
  tonApi
1201
1229
  });
1202
1230
  } else {
1203
- const substrateApi = this.#koniState.getSubstrateApi(networkKey);
1231
+ const substrateApi = this.#koniState.getSubstrateApi(chain);
1204
1232
  [transaction, transferAmount.value] = await (0, _token.createTransferExtrinsic)({
1205
1233
  transferAll: !!transferAll,
1206
1234
  value: value || '0',
1207
1235
  from: from,
1208
- networkKey,
1236
+ networkKey: chain,
1209
1237
  tokenInfo: transferTokenInfo,
1210
1238
  to: to,
1211
1239
  substrateApi
@@ -1226,16 +1254,27 @@ class KoniExtension {
1226
1254
  return undefined;
1227
1255
  }
1228
1256
 
1257
+ // Check enough free local to pay fee local
1258
+ if (nonNativeTokenPayFeeSlug) {
1259
+ var _inputTransaction$est;
1260
+ const nonNativeFee = BigInt(((_inputTransaction$est = inputTransaction.estimateFee) === null || _inputTransaction$est === void 0 ? void 0 : _inputTransaction$est.value) || '0'); // todo: estimateFee should be must-have, need to refactor interface
1261
+ const nonNativeTokenPayFeeInfo = await this.#koniState.balanceService.getTokensHasBalance((0, _utils7.reformatAddress)(from), chain, nonNativeTokenPayFeeSlug);
1262
+ const nonNativeTokenPayFeeBalance = BigInt(nonNativeTokenPayFeeInfo[nonNativeTokenPayFeeSlug].free);
1263
+ if (nonNativeFee > nonNativeTokenPayFeeBalance) {
1264
+ inputTransaction.errors.push(new _TransactionError.TransactionError(_types3.BasicTxErrorType.NOT_ENOUGH_BALANCE));
1265
+ }
1266
+ }
1267
+
1229
1268
  // Check ed for sender
1230
1269
  if (!isTransferNativeToken) {
1231
1270
  const [_senderSendingTokenTransferable, _receiverNativeTotal] = await Promise.all([this.getAddressTransferableBalance({
1232
1271
  address: from,
1233
- networkKey,
1272
+ networkKey: chain,
1234
1273
  token: tokenSlug,
1235
1274
  extrinsicType
1236
1275
  }), this.getAddressTotalBalance({
1237
1276
  address: to,
1238
- networkKey,
1277
+ networkKey: chain,
1239
1278
  token: nativeTokenSlug,
1240
1279
  extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_BALANCE
1241
1280
  })]);
@@ -1246,13 +1285,13 @@ class KoniExtension {
1246
1285
  value: _receiverSendingTokenKeepAliveBalance
1247
1286
  } = await this.getAddressTotalBalance({
1248
1287
  address: to,
1249
- networkKey,
1288
+ networkKey: chain,
1250
1289
  token: tokenSlug,
1251
1290
  extrinsicType
1252
1291
  }); // todo: shouldn't be just transferable, locked also counts
1253
1292
  const receiverSendingTokenKeepAliveBalance = BigInt(_receiverSendingTokenKeepAliveBalance);
1254
1293
  const amount = BigInt(transferAmount.value);
1255
- const substrateApi = this.#koniState.getSubstrateApi(networkKey);
1294
+ const substrateApi = this.#koniState.getSubstrateApi(chain);
1256
1295
  const isSendingTokenSufficient = await this.isSufficientToken(transferTokenInfo, substrateApi);
1257
1296
  const [warnings, errors] = (0, _transfer.additionalValidateTransferForRecipient)(transferTokenInfo, nativeTokenInfo, extrinsicType, receiverSendingTokenKeepAliveBalance, amount, senderSendingTokenTransferable, receiverSystemAccountInfo, isSendingTokenSufficient);
1258
1297
  warnings.length && inputTransaction.warnings.push(...warnings);
@@ -1269,7 +1308,10 @@ class KoniExtension {
1269
1308
  errors,
1270
1309
  warnings,
1271
1310
  address: from,
1272
- chain: networkKey,
1311
+ chain,
1312
+ feeCustom,
1313
+ feeOption,
1314
+ nonNativeTokenPayFeeSlug,
1273
1315
  chainType,
1274
1316
  transferNativeAmount,
1275
1317
  transaction,
@@ -1277,6 +1319,7 @@ class KoniExtension {
1277
1319
  extrinsicType,
1278
1320
  ignoreWarnings,
1279
1321
  isTransferAll: isTransferNativeToken ? transferAll : false,
1322
+ isTransferLocalTokenAndPayThatTokenAsFee,
1280
1323
  edAsWarning: isTransferNativeToken,
1281
1324
  additionalValidator: additionalValidator
1282
1325
  });
@@ -1284,7 +1327,10 @@ class KoniExtension {
1284
1327
  async makeCrossChainTransfer(inputData) {
1285
1328
  const {
1286
1329
  destinationNetworkKey,
1330
+ feeCustom,
1331
+ feeOption,
1287
1332
  from,
1333
+ nonNativeTokenPayFeeSlug,
1288
1334
  originNetworkKey,
1289
1335
  to,
1290
1336
  tokenSlug,
@@ -1305,33 +1351,46 @@ class KoniExtension {
1305
1351
  const isSnowBridgeEvmTransfer = (0, _utils4._isPureEvmChain)(chainInfoMap[originNetworkKey]) && (0, _xcmParser._isSnowBridgeXcm)(chainInfoMap[originNetworkKey], chainInfoMap[destinationNetworkKey]) && !isAvailBridgeFromEvm;
1306
1352
  const isPolygonBridgeTransfer = (0, _polygonBridge._isPolygonChainBridge)(originNetworkKey, destinationNetworkKey);
1307
1353
  const isPosBridgeTransfer = (0, _posBridge._isPosChainBridge)(originNetworkKey, destinationNetworkKey);
1354
+ const isTransferNative = this.#koniState.getNativeTokenInfo(originNetworkKey).slug === tokenSlug;
1355
+ const isTransferLocalTokenAndPayThatTokenAsFee = !isTransferNative && tokenSlug === nonNativeTokenPayFeeSlug;
1308
1356
  let additionalValidator;
1309
1357
  let eventsHandler;
1310
1358
  if (fromKeyPair && destinationTokenInfo) {
1311
1359
  const evmApi = this.#koniState.getEvmApi(originNetworkKey);
1312
1360
  const substrateApi = this.#koniState.getSubstrateApi(originNetworkKey);
1313
- const params = {
1314
- destinationTokenInfo,
1315
- originTokenInfo,
1316
- sendingValue: value,
1317
- sender: from,
1318
- recipient: to,
1319
- chainInfoMap,
1320
- substrateApi,
1321
- evmApi
1322
- };
1323
1361
  let funcCreateExtrinsic;
1362
+ let type;
1324
1363
  if (isPosBridgeTransfer || isPolygonBridgeTransfer) {
1325
1364
  funcCreateExtrinsic = _xcm.createPolygonBridgeExtrinsic;
1365
+ type = 'evm';
1326
1366
  } else if (isSnowBridgeEvmTransfer) {
1327
1367
  funcCreateExtrinsic = _xcm.createSnowBridgeExtrinsic;
1368
+ type = 'evm';
1328
1369
  } else if (isAvailBridgeFromEvm) {
1329
1370
  funcCreateExtrinsic = _xcm.createAvailBridgeTxFromEth;
1371
+ type = 'evm';
1330
1372
  } else if (isAvailBridgeFromAvail) {
1331
1373
  funcCreateExtrinsic = _xcm.createAvailBridgeExtrinsicFromAvail;
1374
+ type = 'substrate';
1332
1375
  } else {
1333
1376
  funcCreateExtrinsic = _xcm.createXcmExtrinsic;
1377
+ type = 'substrate';
1334
1378
  }
1379
+ const feeInfo = await this.#koniState.feeService.subscribeChainFee((0, _getId.getId)(), originNetworkKey, type);
1380
+ const params = {
1381
+ destinationTokenInfo,
1382
+ originTokenInfo,
1383
+ sendingValue: value,
1384
+ sender: from,
1385
+ recipient: to,
1386
+ destinationChain: chainInfoMap[destinationTokenInfo.originChain],
1387
+ originChain: chainInfoMap[originTokenInfo.originChain],
1388
+ substrateApi,
1389
+ evmApi,
1390
+ feeCustom,
1391
+ feeOption,
1392
+ feeInfo
1393
+ };
1335
1394
  extrinsic = await funcCreateExtrinsic(params);
1336
1395
  additionalValidator = async inputTransaction => {
1337
1396
  const {
@@ -1391,12 +1450,77 @@ class KoniExtension {
1391
1450
  chainType: !isSnowBridgeEvmTransfer && !isAvailBridgeFromEvm && !isPolygonBridgeTransfer && !isPosBridgeTransfer ? _KoniTypes.ChainType.SUBSTRATE : _KoniTypes.ChainType.EVM,
1392
1451
  transferNativeAmount: (0, _utils4._isNativeToken)(originTokenInfo) ? value : '0',
1393
1452
  ignoreWarnings,
1453
+ nonNativeTokenPayFeeSlug,
1394
1454
  isTransferAll: transferAll,
1455
+ isTransferLocalTokenAndPayThatTokenAsFee,
1395
1456
  errors,
1396
1457
  additionalValidator: additionalValidator,
1397
1458
  eventsHandler: eventsHandler
1398
1459
  });
1399
1460
  }
1461
+ async getTokensCanPayFee(request) {
1462
+ var _tokensHasBalanceInfo;
1463
+ const {
1464
+ address: _address,
1465
+ chain,
1466
+ feeAmount
1467
+ } = request;
1468
+ const chainService = this.#koniState.chainService;
1469
+ const substrateApi = this.#koniState.getSubstrateApi(chain);
1470
+ const address = (0, _utils7.reformatAddress)(_address);
1471
+
1472
+ // ensure nativeTokenInfo and localTokenInfo have multi-location metadata beforehand to improve performance.
1473
+ const tokensHasBalanceInfoMap = await this.#koniState.balanceService.getTokensHasBalance(address, chain);
1474
+ const tokensHasBalanceSlug = Object.keys(tokensHasBalanceInfoMap);
1475
+ const tokenInfos = tokensHasBalanceSlug.map(tokenSlug => chainService.getAssetBySlug(tokenSlug)).filter(token => token.originChain === chain && token.assetType !== _types._AssetType.NATIVE && token.metadata && token.metadata.multilocation);
1476
+ const nativeTokenInfo = chainService.getNativeTokenInfo(chain);
1477
+ const nativeTokenBalanceInfo = {
1478
+ slug: nativeTokenInfo.slug,
1479
+ free: ((_tokensHasBalanceInfo = tokensHasBalanceInfoMap[nativeTokenInfo.slug]) === null || _tokensHasBalanceInfo === void 0 ? void 0 : _tokensHasBalanceInfo.free) || '0',
1480
+ rate: '1'
1481
+ };
1482
+ const tokensCanPayFee = [nativeTokenBalanceInfo];
1483
+ if (!_constants.ASSET_HUB_CHAIN_SLUGS.includes(chain) || !nativeTokenInfo.metadata || !nativeTokenInfo.metadata.multilocation) {
1484
+ return tokensCanPayFee;
1485
+ }
1486
+ await Promise.all(tokenInfos.map(async tokenInfo => {
1487
+ const tokenSlug = tokenInfo.slug;
1488
+ const reserve = await (0, _utils6.getReserveForPool)(substrateApi.api, nativeTokenInfo, tokenInfo);
1489
+ if (!reserve || !reserve[0] || !reserve[1] || reserve[0] === '0' || reserve[1] === '0') {
1490
+ return;
1491
+ }
1492
+ const rate = new _bignumber.default(reserve[1]).div(reserve[0]).toFixed();
1493
+ const tokenCanPayFee = {
1494
+ slug: tokenSlug,
1495
+ free: tokensHasBalanceInfoMap[tokenSlug].free,
1496
+ rate
1497
+ };
1498
+ if (feeAmount === undefined) {
1499
+ tokensCanPayFee.push(tokenCanPayFee);
1500
+ } else {
1501
+ const amount = (0, _utils6.estimateTokensForPool)(feeAmount, reserve);
1502
+ const liquidityError = (0, _utils6.checkLiquidityForPool)(amount, reserve[0], reserve[1]);
1503
+ if (!liquidityError) {
1504
+ tokensCanPayFee.push(tokenCanPayFee);
1505
+ }
1506
+ }
1507
+ }));
1508
+ return tokensCanPayFee;
1509
+ }
1510
+ async getAmountForPair(request) {
1511
+ const {
1512
+ nativeTokenFeeAmount,
1513
+ nativeTokenSlug,
1514
+ toTokenSlug
1515
+ } = request;
1516
+ if (nativeTokenSlug === toTokenSlug) {
1517
+ return nativeTokenFeeAmount;
1518
+ }
1519
+ const nativeTokenInfo = this.#koniState.chainService.getAssetBySlug(nativeTokenSlug);
1520
+ const toTokenInfo = this.#koniState.chainService.getAssetBySlug(toTokenSlug);
1521
+ const substrateApi = this.#koniState.chainService.getSubstrateApi(nativeTokenInfo.originChain);
1522
+ return await (0, _utils5.calculateToAmountByReservePool)(substrateApi.api, nativeTokenInfo, toTokenInfo, nativeTokenFeeAmount);
1523
+ }
1400
1524
  async evmNftSubmitTransaction(inputData) {
1401
1525
  const {
1402
1526
  networkKey,
@@ -1417,7 +1541,8 @@ class KoniExtension {
1417
1541
  url: _constants3.EXTENSION_REQUEST_URL
1418
1542
  });
1419
1543
  }
1420
- const transaction = await (0, _smartContract.getERC721Transaction)(this.#koniState.getEvmApi(networkKey), networkKey, contractAddress, senderAddress, recipientAddress, tokenId);
1544
+ const feeInfo = await this.#koniState.feeService.subscribeChainFee((0, _getId.getId)(), networkKey, 'evm');
1545
+ const transaction = await (0, _smartContract.getERC721Transaction)(this.#koniState.getEvmApi(networkKey), networkKey, contractAddress, senderAddress, recipientAddress, tokenId, feeInfo);
1421
1546
 
1422
1547
  // this.addContact(recipientAddress);
1423
1548
 
@@ -1574,73 +1699,88 @@ class KoniExtension {
1574
1699
  } = _ref30;
1575
1700
  return await this.#koniState.balanceService.getTotalBalance(address, networkKey, token, extrinsicType);
1576
1701
  }
1577
- async getMaxTransferable(_ref31) {
1578
- let {
1702
+ async subscribeMaxTransferable(request, id, port) {
1703
+ const {
1579
1704
  address,
1580
- destChain,
1581
- isXcmTransfer,
1582
- networkKey,
1705
+ chain,
1706
+ destChain: _destChain,
1707
+ feeCustom,
1708
+ feeOption,
1709
+ nonNativeTokenPayFeeSlug,
1583
1710
  token
1584
- } = _ref31;
1585
- const tokenInfo = token ? this.#koniState.chainService.getAssetBySlug(token) : this.#koniState.chainService.getNativeTokenInfo(networkKey);
1586
- if (!(0, _utils4._isNativeToken)(tokenInfo)) {
1587
- return await this.getAddressTransferableBalance({
1588
- extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_TOKEN,
1589
- address,
1590
- networkKey,
1591
- token
1592
- });
1593
- } else {
1594
- let maxTransferable;
1595
- if (isXcmTransfer) {
1596
- maxTransferable = await this.getXcmMaxTransferable(tokenInfo, destChain, address);
1597
- } else {
1598
- // regular transfer with native token
1599
- maxTransferable = await this.getNativeTokenMaxTransferable(tokenInfo, networkKey, address);
1600
- }
1601
- return {
1602
- value: maxTransferable.gt(_utils5.BN_ZERO) ? maxTransferable.toFixed(0) || '0' : '0',
1603
- decimals: tokenInfo.decimals,
1604
- symbol: tokenInfo.symbol
1605
- };
1606
- }
1607
- }
1608
- async getXcmMaxTransferable(originTokenInfo, destChain, address) {
1609
- const substrateApi = this.#koniState.chainService.getSubstrateApi(originTokenInfo.originChain);
1610
- const chainInfoMap = this.#koniState.chainService.getChainInfoMap();
1611
- const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destChain, originTokenInfo.slug);
1612
-
1613
- // todo: improve this case. Currently set 1 AVAIL for covering fee as default.
1614
- const isSpecialBridgeFromAvail = originTokenInfo.slug === 'avail_mainnet-NATIVE-AVAIL' && destChain === _chainList.COMMON_CHAIN_SLUGS.ETHEREUM;
1615
- const specialBridgeFromAvailFee = new _bignumber.default((0, _utils5.toBNString)(1, (0, _utils4._getAssetDecimals)(originTokenInfo))).minus(new _bignumber.default((0, _utils4._getTokenMinAmount)(originTokenInfo)));
1616
- if (destinationTokenInfo) {
1617
- const [bnMockExecutionFee, {
1618
- value
1619
- }] = await Promise.all([(0, _xcm.getXcmMockTxFee)(substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo), this.getAddressTransferableBalance({
1620
- extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
1621
- address,
1622
- networkKey: originTokenInfo.originChain,
1623
- token: originTokenInfo.slug
1624
- })]);
1625
- const bnMaxTransferable = new _bignumber.default(value);
1626
- const txFee = isSpecialBridgeFromAvail ? specialBridgeFromAvailFee : bnMockExecutionFee.multipliedBy(_constants.XCM_FEE_RATIO);
1627
- return bnMaxTransferable.minus(txFee);
1711
+ } = request;
1712
+ const cb = (0, _subscriptions.createSubscription)(id, port);
1713
+ const transferTokenInfo = this.#koniState.chainService.getAssetBySlug(token);
1714
+ const isTransferLocalTokenAndPayThatTokenAsFee = !(0, _utils4._isNativeToken)(transferTokenInfo) && !!nonNativeTokenPayFeeSlug && nonNativeTokenPayFeeSlug === token;
1715
+ const isTransferNativeTokenAndPayLocalTokenAsFee = (0, _utils4._isNativeToken)(transferTokenInfo) && !!nonNativeTokenPayFeeSlug;
1716
+ const srcToken = token ? this.#koniState.chainService.getAssetBySlug(token) : this.#koniState.chainService.getNativeTokenInfo(chain);
1717
+ const destToken = _destChain !== chain ? this.#koniState.getXcmEqualAssetByChain(_destChain, srcToken.slug) : srcToken;
1718
+ const srcChain = this.#koniState.chainService.getChainInfoByKey(chain);
1719
+ const destChain = this.#koniState.chainService.getChainInfoByKey(_destChain);
1720
+ const nativeToken = this.#koniState.chainService.getNativeTokenInfo(chain);
1721
+ const extrinsicType = srcChain.slug !== destChain.slug ? _KoniTypes.ExtrinsicType.TRANSFER_XCM : _KoniTypes.ExtrinsicType.TRANSFER_BALANCE;
1722
+ const freeBalanceSubject = new _rxjs.Subject();
1723
+ const feeSubject = new _rxjs.Subject();
1724
+ const feeChainType = (0, _utils7.detectTransferTxType)(srcToken, srcChain, destChain);
1725
+ if (!destToken) {
1726
+ throw new Error('Destination token not found');
1628
1727
  }
1629
- return new _bignumber.default(0);
1630
- }
1631
- async getNativeTokenMaxTransferable(tokenInfo, networkKey, address) {
1632
- const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey);
1633
- const api = (0, _utils4._isChainEvmCompatible)(chainInfo) && (0, _utils4._isTokenTransferredByEvm)(tokenInfo) ? this.#koniState.chainService.getEvmApi(networkKey) : (0, _utils4._isChainTonCompatible)(chainInfo) && (0, _utils4._isTokenTransferredByTon)(tokenInfo) ? this.#koniState.chainService.getTonApi(networkKey) : this.#koniState.chainService.getSubstrateApi(networkKey);
1634
- const [mockTxFee, {
1635
- value
1636
- }] = await Promise.all([(0, _token.getTransferMockTxFee)(address, chainInfo, tokenInfo, api), this.getAddressTransferableBalance({
1637
- extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_BALANCE,
1638
- address,
1639
- networkKey,
1640
- token: tokenInfo.slug
1641
- })]);
1642
- const bnMaxTransferable = new _bignumber.default(value);
1643
- return bnMaxTransferable.minus(mockTxFee);
1728
+ const _request = {
1729
+ address: address,
1730
+ destChain,
1731
+ destToken,
1732
+ evmApi: this.#koniState.chainService.getEvmApi(chain),
1733
+ feeCustom,
1734
+ feeOption,
1735
+ srcChain,
1736
+ srcToken,
1737
+ substrateApi: this.#koniState.chainService.getSubstrateApi(chain),
1738
+ tonApi: this.#koniState.chainService.getTonApi(chain),
1739
+ isTransferLocalTokenAndPayThatTokenAsFee,
1740
+ isTransferNativeTokenAndPayLocalTokenAsFee,
1741
+ nativeToken
1742
+ };
1743
+ const subscription = (0, _rxjs.combineLatest)({
1744
+ freeBalance: freeBalanceSubject,
1745
+ fee: feeSubject
1746
+ }).subscribe({
1747
+ next: _ref31 => {
1748
+ let {
1749
+ fee,
1750
+ freeBalance
1751
+ } = _ref31;
1752
+ (0, _utils7.calculateMaxTransferable)(id, _request, freeBalance, fee).then(cb).catch(console.error);
1753
+ }
1754
+ });
1755
+ const [unsubBalance, freeBalance] = await (async () => {
1756
+ try {
1757
+ return await this.#koniState.balanceService.subscribeBalance(address, chain, token, 'transferable', extrinsicType, data => {
1758
+ freeBalanceSubject.next(data); // Must be called after subscription
1759
+ });
1760
+ } catch (e) {
1761
+ const fallBackValue = {
1762
+ value: '0',
1763
+ decimals: srcToken.decimals || 0,
1764
+ symbol: srcToken.symbol
1765
+ };
1766
+ freeBalanceSubject.next(fallBackValue);
1767
+ return [_util.noop, fallBackValue];
1768
+ }
1769
+ })();
1770
+ const fee = await this.#koniState.feeService.subscribeChainFee(id, chain, feeChainType, data => {
1771
+ feeSubject.next(data); // Must be called after subscription
1772
+ });
1773
+
1774
+ const unsub = () => {
1775
+ subscription.unsubscribe();
1776
+ unsubBalance();
1777
+ this.#koniState.feeService.unsubscribeChainFee(id, chain, feeChainType);
1778
+ };
1779
+ this.createUnsubscriptionHandle(id, unsub);
1780
+ port.onDisconnect.addListener(() => {
1781
+ this.cancelSubscription(id);
1782
+ });
1783
+ return (0, _utils7.calculateMaxTransferable)(id, _request, freeBalance, fee);
1644
1784
  }
1645
1785
  async subscribeAddressTransferableBalance(_ref32, id, port) {
1646
1786
  let {
@@ -1893,7 +2033,7 @@ class KoniExtension {
1893
2033
  signed = await pair.evm.signMessage(data, 'personal_sign');
1894
2034
  } else {
1895
2035
  var _signedTranaction$r, _signedTranaction$s, _signedTranaction$v;
1896
- const tx = (0, _utils5.createTransactionFromRLP)(message);
2036
+ const tx = (0, _utils7.createTransactionFromRLP)(message);
1897
2037
  if (!tx) {
1898
2038
  throw new Error((0, _i18next.t)('Failed to decode data. Please use a valid QR code'));
1899
2039
  }
@@ -1918,7 +2058,7 @@ class KoniExtension {
1918
2058
  common
1919
2059
  });
1920
2060
  const signedTranaction = _tx.LegacyTransaction.fromSerializedTx((0, _util.hexToU8a)(pair.evm.signTransaction(transaction)));
1921
- signed = (0, _utils5.signatureToHex)({
2061
+ signed = (0, _utils7.signatureToHex)({
1922
2062
  r: ((_signedTranaction$r = signedTranaction.r) === null || _signedTranaction$r === void 0 ? void 0 : _signedTranaction$r.toString(16)) || '',
1923
2063
  s: ((_signedTranaction$s = signedTranaction.s) === null || _signedTranaction$s === void 0 ? void 0 : _signedTranaction$s.toString(16)) || '',
1924
2064
  v: ((_signedTranaction$v = signedTranaction.v) === null || _signedTranaction$v === void 0 ? void 0 : _signedTranaction$v.toString(16)) || ''
@@ -2352,11 +2492,11 @@ class KoniExtension {
2352
2492
  let registry = new _types5.TypeRegistry();
2353
2493
  if (isJsonPayload(payload)) {
2354
2494
  const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
2355
- const allRegistry = [(0, _utils7.setupApiRegistry)(chainInfo, this.#koniState), (0, _utils7.setupDatabaseRegistry)(await this.#koniState.chainService.getMetadataByHash(payload.genesisHash), chainInfo, payload), (0, _utils7.setupDappRegistry)(this.#koniState.knownMetadata.find(meta => meta.genesisHash === payload.genesisHash), payload)].filter(item => item !== null && item.registry !== undefined);
2495
+ const allRegistry = [(0, _utils9.setupApiRegistry)(chainInfo, this.#koniState), (0, _utils9.setupDatabaseRegistry)(await this.#koniState.chainService.getMetadataByHash(payload.genesisHash), chainInfo, payload), (0, _utils9.setupDappRegistry)(this.#koniState.knownMetadata.find(meta => meta.genesisHash === payload.genesisHash), payload)].filter(item => item !== null && item.registry !== undefined);
2356
2496
  if (allRegistry.length === 0) {
2357
2497
  registry.setSignedExtensions(payload.signedExtensions);
2358
2498
  } else {
2359
- registry = (0, _utils7.getSuitableRegistry)(allRegistry, payload);
2499
+ registry = (0, _utils9.getSuitableRegistry)(allRegistry, payload);
2360
2500
  }
2361
2501
  }
2362
2502
  const result = request.sign(registry, pair);
@@ -2635,12 +2775,12 @@ class KoniExtension {
2635
2775
  if (namespace.chains) {
2636
2776
  const unSupportChains = namespace.chains.filter(chain => !(0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap));
2637
2777
  if (unSupportChains.length) {
2638
- throw new Error((0, _utils6.getSdkError)('UNSUPPORTED_CHAINS').message + ' ' + unSupportChains.toString());
2778
+ throw new Error((0, _utils8.getSdkError)('UNSUPPORTED_CHAINS').message + ' ' + unSupportChains.toString());
2639
2779
  }
2640
2780
  availableNamespaces[key] = namespace;
2641
2781
  }
2642
2782
  } else {
2643
- throw new Error((0, _utils6.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
2783
+ throw new Error((0, _utils8.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
2644
2784
  }
2645
2785
  });
2646
2786
  Object.entries(optionalNamespaces).forEach(_ref51 => {
@@ -2675,7 +2815,7 @@ class KoniExtension {
2675
2815
  const [_namespace] = address.split(':');
2676
2816
  return _namespace === key;
2677
2817
  });
2678
- const chains = (0, _utils5.uniqueStringArray)(namespace.chains);
2818
+ const chains = (0, _utils7.uniqueStringArray)(namespace.chains);
2679
2819
  namespaces[key] = {
2680
2820
  accounts,
2681
2821
  methods: namespace.methods,
@@ -2814,7 +2954,7 @@ class KoniExtension {
2814
2954
  }
2815
2955
  async initSyncMantaPay(address) {
2816
2956
  var _this$koniState$chain3, _this$koniState$chain4, _this$koniState$chain5, _this$koniState$chain6;
2817
- if ((_this$koniState$chain3 = this.#koniState.chainService) !== null && _this$koniState$chain3 !== void 0 && (_this$koniState$chain4 = _this$koniState$chain3.mantaPay) !== null && _this$koniState$chain4 !== void 0 && _this$koniState$chain4.getSyncState().isSyncing || !_utils5.MODULE_SUPPORT.MANTA_ZK) {
2957
+ if ((_this$koniState$chain3 = this.#koniState.chainService) !== null && _this$koniState$chain3 !== void 0 && (_this$koniState$chain4 = _this$koniState$chain3.mantaPay) !== null && _this$koniState$chain4 !== void 0 && _this$koniState$chain4.getSyncState().isSyncing || !_utils7.MODULE_SUPPORT.MANTA_ZK) {
2818
2958
  return;
2819
2959
  }
2820
2960
  this.#skipAutoLock = true;
@@ -3408,6 +3548,7 @@ class KoniExtension {
3408
3548
  // skipFeeValidation: chosenFeeToken && allowSkipValidation
3409
3549
  });
3410
3550
  }
3551
+
3411
3552
  /* Swap service */
3412
3553
 
3413
3554
  /* Notification service */
@@ -3439,6 +3580,7 @@ class KoniExtension {
3439
3580
  }
3440
3581
  return result;
3441
3582
  }
3583
+
3442
3584
  /* Notification service */
3443
3585
 
3444
3586
  async submitClaimAvailBridge(data) {
@@ -3456,7 +3598,8 @@ class KoniExtension {
3456
3598
  chainType = _KoniTypes.ChainType.SUBSTRATE;
3457
3599
  } else {
3458
3600
  const evmApi = this.#koniState.getEvmApi(chain);
3459
- transaction = await (0, _availBridge.getClaimTxOnEthereum)(chain, notification, evmApi);
3601
+ const feeInfo = await this.#koniState.feeService.subscribeChainFee((0, _getId.getId)(), chain, 'evm');
3602
+ transaction = await (0, _availBridge.getClaimTxOnEthereum)(chain, notification, evmApi, feeInfo);
3460
3603
  chainType = _KoniTypes.ChainType.EVM;
3461
3604
  }
3462
3605
  return await this.#koniState.transactionService.handleTransaction({
@@ -3484,10 +3627,11 @@ class KoniExtension {
3484
3627
  let transaction = null;
3485
3628
  const evmApi = this.#koniState.getEvmApi(chain);
3486
3629
  const metadata = notification.metadata;
3630
+ const feeInfo = await this.#koniState.feeService.subscribeChainFee((0, _getId.getId)(), chain, 'evm');
3487
3631
  if (metadata.bridgeType === 'POS') {
3488
- transaction = await (0, _posBridge.getClaimPosBridge)(chain, notification, evmApi);
3632
+ transaction = await (0, _posBridge.getClaimPosBridge)(chain, notification, evmApi, feeInfo);
3489
3633
  } else {
3490
- transaction = await (0, _polygonBridge.getClaimPolygonBridge)(chain, notification, evmApi);
3634
+ transaction = await (0, _polygonBridge.getClaimPolygonBridge)(chain, notification, evmApi, feeInfo);
3491
3635
  }
3492
3636
  const chainType = _KoniTypes.ChainType.EVM;
3493
3637
  return await this.#koniState.transactionService.handleTransaction({
@@ -3839,8 +3983,8 @@ class KoniExtension {
3839
3983
  return this.subscribeAssetSetting(id, port);
3840
3984
  case 'pri(assetSetting.update)':
3841
3985
  return await this.updateAssetSetting(request);
3842
- case 'pri(transfer.getMaxTransferable)':
3843
- return this.getMaxTransferable(request);
3986
+ case 'pri(transfer.subscribe)':
3987
+ return this.subscribeMaxTransferable(request, id, port);
3844
3988
  case 'pri(freeBalance.get)':
3845
3989
  return this.getAddressTransferableBalance(request);
3846
3990
  case 'pri(freeBalance.subscribe)':
@@ -3865,6 +4009,10 @@ class KoniExtension {
3865
4009
  return await this.getOptimalTransferProcess(request);
3866
4010
  case 'pri(accounts.approveSpending)':
3867
4011
  return await this.approveSpending(request);
4012
+ case 'pri(customFee.getTokensCanPayFee)':
4013
+ return this.getTokensCanPayFee(request);
4014
+ case 'pri(customFee.getAmountForPair)':
4015
+ return this.getAmountForPair(request);
3868
4016
 
3869
4017
  /// Sign QR
3870
4018
  case 'pri(qr.transaction.parse.substrate)':
@@ -4110,10 +4258,8 @@ class KoniExtension {
4110
4258
  /* Avail Bridge */
4111
4259
 
4112
4260
  /* Polygon Bridge */
4113
-
4114
4261
  case 'pri(polygonBridge.submitClaimPolygonBridge)':
4115
4262
  return this.submitClaimPolygonBridge(request);
4116
-
4117
4263
  /* Polygon Bridge */
4118
4264
 
4119
4265
  /* Ledger */