@subwallet/extension-base 1.1.54-0 → 1.1.56-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 (112) hide show
  1. package/background/KoniTypes.d.ts +30 -2
  2. package/background/KoniTypes.js +6 -0
  3. package/background/errors/SwapError.d.ts +6 -0
  4. package/background/errors/SwapError.js +57 -0
  5. package/background/errors/TransactionError.js +9 -0
  6. package/background/types.d.ts +2 -0
  7. package/cjs/background/KoniTypes.js +8 -1
  8. package/cjs/background/errors/SwapError.js +64 -0
  9. package/cjs/background/errors/TransactionError.js +9 -0
  10. package/cjs/koni/api/nft/{statemint_nft → assethub_nft}/index.js +5 -3
  11. package/cjs/koni/api/nft/{statemine_nft → assethub_unique}/index.js +5 -3
  12. package/cjs/koni/api/nft/index.js +13 -13
  13. package/cjs/koni/api/nft/nft.js +1 -1
  14. package/cjs/koni/api/nft/transfer.js +11 -15
  15. package/cjs/koni/api/staking/bonding/utils.js +35 -6
  16. package/cjs/koni/background/handlers/Extension.js +214 -102
  17. package/cjs/koni/background/handlers/State.js +5 -2
  18. package/cjs/packageInfo.js +1 -1
  19. package/cjs/services/balance-service/index.js +6 -3
  20. package/cjs/services/chain-service/constants.js +18 -4
  21. package/cjs/services/chain-service/index.js +39 -18
  22. package/cjs/services/chain-service/utils/index.js +15 -4
  23. package/cjs/services/chain-service/utils/patch.js +1 -1
  24. package/cjs/services/earning-service/constants/chains.js +4 -2
  25. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +7 -9
  26. package/cjs/services/earning-service/handlers/native-staking/astar.js +4 -3
  27. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +11 -8
  28. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +22 -3
  29. package/cjs/services/earning-service/handlers/nomination-pool/index.js +19 -5
  30. package/cjs/services/earning-service/service.js +0 -1
  31. package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +4 -17
  32. package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +4 -17
  33. package/cjs/services/migration-service/scripts/index.js +3 -3
  34. package/cjs/services/swap-service/handler/base-handler.js +189 -0
  35. package/cjs/services/swap-service/handler/chainflip-handler.js +407 -0
  36. package/cjs/services/swap-service/handler/hydradx-handler.js +531 -0
  37. package/cjs/services/swap-service/index.js +250 -0
  38. package/cjs/services/swap-service/utils.js +126 -0
  39. package/cjs/services/transaction-service/index.js +20 -0
  40. package/cjs/services/transaction-service/utils.js +6 -0
  41. package/cjs/types/fee/evm.js +1 -0
  42. package/cjs/types/fee/fee.js +70 -0
  43. package/cjs/types/fee/index.js +27 -1
  44. package/cjs/types/service-base.js +1 -0
  45. package/cjs/types/swap/index.js +50 -0
  46. package/cjs/utils/index.js +12 -0
  47. package/cjs/utils/swap.js +78 -0
  48. package/koni/api/nft/{statemint_nft → assethub_nft}/index.d.ts +1 -1
  49. package/koni/api/nft/{statemint_nft → assethub_nft}/index.js +4 -2
  50. package/koni/api/nft/{statemine_nft → assethub_unique}/index.d.ts +1 -1
  51. package/koni/api/nft/{statemine_nft → assethub_unique}/index.js +4 -2
  52. package/koni/api/nft/index.js +13 -13
  53. package/koni/api/nft/nft.js +1 -1
  54. package/koni/api/nft/transfer.d.ts +1 -2
  55. package/koni/api/nft/transfer.js +10 -13
  56. package/koni/api/staking/bonding/utils.d.ts +3 -1
  57. package/koni/api/staking/bonding/utils.js +32 -6
  58. package/koni/background/handlers/Extension.d.ts +6 -0
  59. package/koni/background/handlers/Extension.js +111 -0
  60. package/koni/background/handlers/State.d.ts +2 -0
  61. package/koni/background/handlers/State.js +5 -2
  62. package/package.json +85 -28
  63. package/packageInfo.js +1 -1
  64. package/services/balance-service/index.js +6 -3
  65. package/services/base/types.d.ts +4 -0
  66. package/services/chain-service/constants.js +18 -4
  67. package/services/chain-service/index.d.ts +4 -0
  68. package/services/chain-service/index.js +21 -1
  69. package/services/chain-service/utils/index.d.ts +7 -5
  70. package/services/chain-service/utils/index.js +9 -2
  71. package/services/chain-service/utils/patch.js +1 -1
  72. package/services/earning-service/constants/chains.d.ts +1 -0
  73. package/services/earning-service/constants/chains.js +1 -0
  74. package/services/earning-service/handlers/native-staking/amplitude.js +7 -9
  75. package/services/earning-service/handlers/native-staking/astar.js +4 -3
  76. package/services/earning-service/handlers/native-staking/para-chain.js +12 -9
  77. package/services/earning-service/handlers/native-staking/relay-chain.js +24 -5
  78. package/services/earning-service/handlers/nomination-pool/index.js +19 -5
  79. package/services/earning-service/service.js +0 -1
  80. package/services/event-service/types.d.ts +1 -0
  81. package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +4 -17
  82. package/services/migration-service/scripts/databases/MigrateAssetSetting.js +4 -17
  83. package/services/migration-service/scripts/index.js +3 -3
  84. package/services/swap-service/handler/base-handler.d.ts +38 -0
  85. package/services/swap-service/handler/base-handler.js +180 -0
  86. package/services/swap-service/handler/chainflip-handler.d.ts +30 -0
  87. package/services/swap-service/handler/chainflip-handler.js +399 -0
  88. package/services/swap-service/handler/hydradx-handler.d.ts +36 -0
  89. package/services/swap-service/handler/hydradx-handler.js +522 -0
  90. package/services/swap-service/index.d.ts +32 -0
  91. package/services/swap-service/index.js +241 -0
  92. package/services/swap-service/utils.d.ts +18 -0
  93. package/services/swap-service/utils.js +105 -0
  94. package/services/transaction-service/index.js +20 -0
  95. package/services/transaction-service/utils.d.ts +2 -0
  96. package/services/transaction-service/utils.js +6 -2
  97. package/types/fee/evm.d.ts +49 -0
  98. package/types/fee/evm.js +1 -0
  99. package/types/fee/fee.d.ts +32 -0
  100. package/types/fee/fee.js +63 -0
  101. package/types/fee/index.d.ts +2 -49
  102. package/types/fee/index.js +5 -1
  103. package/types/service-base.d.ts +10 -0
  104. package/types/service-base.js +1 -0
  105. package/types/swap/index.d.ts +168 -0
  106. package/types/swap/index.js +41 -0
  107. package/types/yield/info/chain/target.d.ts +2 -0
  108. package/types/yield/info/pallet.d.ts +8 -0
  109. package/utils/index.d.ts +1 -0
  110. package/utils/index.js +2 -1
  111. package/utils/swap.d.ts +3 -0
  112. package/utils/swap.js +70 -0
@@ -1446,6 +1446,27 @@ class KoniExtension {
1446
1446
  throw new Error((0, _i18next.t)('Wrong password'));
1447
1447
  }
1448
1448
  }
1449
+ async batchExportV2(_ref44) {
1450
+ let {
1451
+ addresses,
1452
+ password
1453
+ } = _ref44;
1454
+ try {
1455
+ if (addresses && !addresses.length) {
1456
+ throw new Error((0, _i18next.t)('No accounts found to export'));
1457
+ }
1458
+ return {
1459
+ exportedJson: await _uiKeyring.keyring.backupAccounts(password, addresses)
1460
+ };
1461
+ } catch (e) {
1462
+ const error = e;
1463
+ if (error.message === 'Invalid master password') {
1464
+ throw new Error((0, _i18next.t)('Wrong password'));
1465
+ } else {
1466
+ throw error;
1467
+ }
1468
+ }
1469
+ }
1449
1470
  getNftCollection() {
1450
1471
  return this.#koniState.getNftCollection();
1451
1472
  }
@@ -1532,11 +1553,11 @@ class KoniExtension {
1532
1553
  // Re-filter
1533
1554
  return historySubject.getValue().filter(item => addresses.some(address => (0, _utils4.isSameAddress)(item.address, address)));
1534
1555
  }
1535
- subscribeHistoryByChainAndAddress(_ref44, id, port) {
1556
+ subscribeHistoryByChainAndAddress(_ref45, id, port) {
1536
1557
  let {
1537
1558
  address,
1538
1559
  chain
1539
- } = _ref44;
1560
+ } = _ref45;
1540
1561
  const cb = (0, _subscriptions.createSubscription)(id, port);
1541
1562
  const subscribeHistoriesResponse = this.#koniState.historyService.subscribeHistories(chain, address, cb);
1542
1563
  this.createUnsubscriptionHandle(id, subscribeHistoriesResponse.unsubscribe);
@@ -1852,21 +1873,21 @@ class KoniExtension {
1852
1873
  disableChain(networkKey) {
1853
1874
  return this.#koniState.disableChain(networkKey);
1854
1875
  }
1855
- async enableChain(_ref45) {
1876
+ async enableChain(_ref46) {
1856
1877
  let {
1857
1878
  chainSlug,
1858
1879
  enableTokens
1859
- } = _ref45;
1880
+ } = _ref46;
1860
1881
  return await this.#koniState.enableChain(chainSlug, enableTokens);
1861
1882
  }
1862
1883
  async reconnectChain(chainSlug) {
1863
1884
  return this.#koniState.chainService.reconnectChain(chainSlug);
1864
1885
  }
1865
- async validateNetwork(_ref46) {
1886
+ async validateNetwork(_ref47) {
1866
1887
  let {
1867
1888
  existedChainSlug,
1868
1889
  provider
1869
- } = _ref46;
1890
+ } = _ref47;
1870
1891
  return await this.#koniState.validateCustomChain(provider, existedChainSlug);
1871
1892
  }
1872
1893
  resetDefaultNetwork() {
@@ -1904,12 +1925,12 @@ class KoniExtension {
1904
1925
  async validateCustomAsset(data) {
1905
1926
  return await this.#koniState.validateCustomAsset(data);
1906
1927
  }
1907
- async getAddressFreeBalance(_ref47) {
1928
+ async getAddressFreeBalance(_ref48) {
1908
1929
  let {
1909
1930
  address,
1910
1931
  networkKey,
1911
1932
  token
1912
- } = _ref47;
1933
+ } = _ref48;
1913
1934
  if (token && _constants2._MANTA_ZK_CHAIN_GROUP.includes(networkKey)) {
1914
1935
  const tokenInfo = this.#koniState.chainService.getAssetBySlug(token);
1915
1936
  if (tokenInfo.symbol.startsWith(_constants2._ZK_ASSET_PREFIX)) {
@@ -1918,14 +1939,14 @@ class KoniExtension {
1918
1939
  }
1919
1940
  return await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
1920
1941
  }
1921
- async transferGetMaxTransferable(_ref48) {
1942
+ async transferGetMaxTransferable(_ref49) {
1922
1943
  let {
1923
1944
  address,
1924
1945
  destChain,
1925
1946
  isXcmTransfer,
1926
1947
  networkKey,
1927
1948
  token
1928
- } = _ref48;
1949
+ } = _ref49;
1929
1950
  const freeBalance = await this.getAddressFreeBalance({
1930
1951
  address,
1931
1952
  networkKey,
@@ -2009,12 +2030,12 @@ class KoniExtension {
2009
2030
  };
2010
2031
  }
2011
2032
  }
2012
- async subscribeAddressFreeBalance(_ref49, id, port) {
2033
+ async subscribeAddressFreeBalance(_ref50, id, port) {
2013
2034
  let {
2014
2035
  address,
2015
2036
  networkKey,
2016
2037
  token
2017
- } = _ref49;
2038
+ } = _ref50;
2018
2039
  const cb = (0, _subscriptions.createSubscription)(id, port);
2019
2040
  const convertData = data => {
2020
2041
  return {
@@ -2033,26 +2054,26 @@ class KoniExtension {
2033
2054
  });
2034
2055
  return convertData(currentFreeBalance);
2035
2056
  }
2036
- async transferCheckReferenceCount(_ref50) {
2057
+ async transferCheckReferenceCount(_ref51) {
2037
2058
  let {
2038
2059
  address,
2039
2060
  networkKey
2040
- } = _ref50;
2061
+ } = _ref51;
2041
2062
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
2042
2063
  return await (0, _transfer.checkReferenceCount)(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
2043
2064
  }
2044
- async transferCheckSupporting(_ref51) {
2065
+ async transferCheckSupporting(_ref52) {
2045
2066
  let {
2046
2067
  networkKey,
2047
2068
  tokenSlug
2048
- } = _ref51;
2069
+ } = _ref52;
2049
2070
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
2050
2071
  return await (0, _transfer.checkSupportTransfer)(networkKey, tokenInfo, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
2051
2072
  }
2052
- transferGetExistentialDeposit(_ref52) {
2073
+ transferGetExistentialDeposit(_ref53) {
2053
2074
  let {
2054
2075
  tokenSlug
2055
- } = _ref52;
2076
+ } = _ref53;
2056
2077
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
2057
2078
  return (0, _utils2._getTokenMinAmount)(tokenInfo);
2058
2079
  }
@@ -2088,11 +2109,11 @@ class KoniExtension {
2088
2109
  isSendingSelf
2089
2110
  };
2090
2111
  }
2091
- async enableChains(_ref53) {
2112
+ async enableChains(_ref54) {
2092
2113
  let {
2093
2114
  chainSlugs,
2094
2115
  enableTokens
2095
- } = _ref53;
2116
+ } = _ref54;
2096
2117
  try {
2097
2118
  await Promise.all(chainSlugs.map(chainSlug => this.enableChain({
2098
2119
  chainSlug,
@@ -2103,24 +2124,24 @@ class KoniExtension {
2103
2124
  }
2104
2125
  return true;
2105
2126
  }
2106
- getAccountMeta(_ref54) {
2127
+ getAccountMeta(_ref55) {
2107
2128
  let {
2108
2129
  address
2109
- } = _ref54;
2130
+ } = _ref55;
2110
2131
  const pair = _uiKeyring.keyring.getPair(address);
2111
2132
  (0, _util.assert)(pair, (0, _i18next.t)('Unable to find account'));
2112
2133
  return {
2113
2134
  meta: pair.meta
2114
2135
  };
2115
2136
  }
2116
- accountsTie2(_ref55) {
2137
+ accountsTie2(_ref56) {
2117
2138
  let {
2118
2139
  address,
2119
2140
  genesisHash
2120
- } = _ref55;
2141
+ } = _ref56;
2121
2142
  return this.#koniState.setAccountTie(address, genesisHash);
2122
2143
  }
2123
- async accountsCreateExternalV2(_ref56) {
2144
+ async accountsCreateExternalV2(_ref57) {
2124
2145
  let {
2125
2146
  address,
2126
2147
  genesisHash,
@@ -2128,7 +2149,7 @@ class KoniExtension {
2128
2149
  isEthereum,
2129
2150
  isReadOnly,
2130
2151
  name
2131
- } = _ref56;
2152
+ } = _ref57;
2132
2153
  try {
2133
2154
  let result;
2134
2155
  try {
@@ -2187,7 +2208,7 @@ class KoniExtension {
2187
2208
  }];
2188
2209
  }
2189
2210
  }
2190
- async accountsCreateHardwareV2(_ref57) {
2211
+ async accountsCreateHardwareV2(_ref58) {
2191
2212
  let {
2192
2213
  accountIndex,
2193
2214
  address,
@@ -2196,7 +2217,7 @@ class KoniExtension {
2196
2217
  hardwareType,
2197
2218
  isAllowed,
2198
2219
  name
2199
- } = _ref57;
2220
+ } = _ref58;
2200
2221
  const key = _uiKeyring.keyring.addHardware(address, hardwareType, {
2201
2222
  accountIndex,
2202
2223
  addressOffset,
@@ -2219,10 +2240,10 @@ class KoniExtension {
2219
2240
  });
2220
2241
  return true;
2221
2242
  }
2222
- async accountsCreateHardwareMultiple(_ref58) {
2243
+ async accountsCreateHardwareMultiple(_ref59) {
2223
2244
  let {
2224
2245
  accounts
2225
- } = _ref58;
2246
+ } = _ref59;
2226
2247
  const addresses = [];
2227
2248
  if (!accounts.length) {
2228
2249
  throw new Error((0, _i18next.t)("Can't find an account. Please try again"));
@@ -2300,14 +2321,14 @@ class KoniExtension {
2300
2321
  }
2301
2322
  return true;
2302
2323
  }
2303
- async accountsCreateWithSecret(_ref59) {
2324
+ async accountsCreateWithSecret(_ref60) {
2304
2325
  let {
2305
2326
  isAllow,
2306
2327
  isEthereum,
2307
2328
  name,
2308
2329
  publicKey,
2309
2330
  secretKey
2310
- } = _ref59;
2331
+ } = _ref60;
2311
2332
  try {
2312
2333
  let keyringPair = null;
2313
2334
  if (isEthereum) {
@@ -2453,30 +2474,30 @@ class KoniExtension {
2453
2474
 
2454
2475
  // Parse transaction
2455
2476
 
2456
- parseSubstrateTransaction(_ref60) {
2477
+ parseSubstrateTransaction(_ref61) {
2457
2478
  let {
2458
2479
  data,
2459
2480
  networkKey
2460
- } = _ref60;
2481
+ } = _ref61;
2461
2482
  const apiProps = this.#koniState.getSubstrateApi(networkKey);
2462
2483
  const apiPromise = apiProps.api;
2463
2484
  return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
2464
2485
  }
2465
- async parseEVMRLP(_ref61) {
2486
+ async parseEVMRLP(_ref62) {
2466
2487
  let {
2467
2488
  data
2468
- } = _ref61;
2489
+ } = _ref62;
2469
2490
  return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
2470
2491
  }
2471
2492
 
2472
2493
  // Sign
2473
2494
 
2474
- qrSignSubstrate(_ref62) {
2495
+ qrSignSubstrate(_ref63) {
2475
2496
  let {
2476
2497
  address,
2477
2498
  data,
2478
2499
  networkKey
2479
- } = _ref62;
2500
+ } = _ref63;
2480
2501
  const pair = _uiKeyring.keyring.getPair(address);
2481
2502
  (0, _util.assert)(pair, (0, _i18next.t)('Unable to find account'));
2482
2503
  if (pair.isLocked) {
@@ -2493,13 +2514,13 @@ class KoniExtension {
2493
2514
  signature: signed
2494
2515
  };
2495
2516
  }
2496
- async qrSignEVM(_ref63) {
2517
+ async qrSignEVM(_ref64) {
2497
2518
  let {
2498
2519
  address,
2499
2520
  chainId,
2500
2521
  message,
2501
2522
  type
2502
- } = _ref63;
2523
+ } = _ref64;
2503
2524
  let signed;
2504
2525
  const network = this.getNetworkJsonByChainId(chainId);
2505
2526
  if (!network) {
@@ -2583,11 +2604,11 @@ class KoniExtension {
2583
2604
  });
2584
2605
  return this.#koniState.getNominatorMetadata();
2585
2606
  }
2586
- async getBondingOptions(_ref64) {
2607
+ async getBondingOptions(_ref65) {
2587
2608
  let {
2588
2609
  chain,
2589
2610
  type
2590
- } = _ref64;
2611
+ } = _ref65;
2591
2612
  const apiProps = this.#koniState.getSubstrateApi(chain);
2592
2613
  const chainInfo = this.#koniState.getChainInfo(chain);
2593
2614
  const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
@@ -2777,12 +2798,12 @@ class KoniExtension {
2777
2798
  }
2778
2799
 
2779
2800
  // EVM Transaction
2780
- async parseContractInput(_ref65) {
2801
+ async parseContractInput(_ref66) {
2781
2802
  let {
2782
2803
  chainId,
2783
2804
  contract,
2784
2805
  data
2785
- } = _ref65;
2806
+ } = _ref66;
2786
2807
  const network = this.getNetworkJsonByChainId(chainId);
2787
2808
  return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
2788
2809
  }
@@ -2853,12 +2874,12 @@ class KoniExtension {
2853
2874
 
2854
2875
  // Change master password
2855
2876
 
2856
- keyringChangeMasterPassword(_ref66) {
2877
+ keyringChangeMasterPassword(_ref67) {
2857
2878
  let {
2858
2879
  createNew,
2859
2880
  newPassword,
2860
2881
  oldPassword
2861
- } = _ref66;
2882
+ } = _ref67;
2862
2883
  try {
2863
2884
  // Remove isMasterPassword meta if createNew
2864
2885
  if (createNew && !_uiKeyring.keyring.keyring.hasMasterPassword) {
@@ -2908,11 +2929,11 @@ class KoniExtension {
2908
2929
  }
2909
2930
  }
2910
2931
  }
2911
- keyringMigrateMasterPassword(_ref67) {
2932
+ keyringMigrateMasterPassword(_ref68) {
2912
2933
  let {
2913
2934
  address,
2914
2935
  password
2915
- } = _ref67;
2936
+ } = _ref68;
2916
2937
  try {
2917
2938
  _uiKeyring.keyring.migrateWithMasterPassword(address, password);
2918
2939
  this.checkLockAfterMigrate();
@@ -2931,10 +2952,10 @@ class KoniExtension {
2931
2952
 
2932
2953
  // Unlock wallet
2933
2954
 
2934
- keyringUnlock(_ref68) {
2955
+ keyringUnlock(_ref69) {
2935
2956
  let {
2936
2957
  password
2937
- } = _ref68;
2958
+ } = _ref69;
2938
2959
  try {
2939
2960
  _uiKeyring.keyring.unlockKeyring(password);
2940
2961
  this.#koniState.initMantaPay(password).catch(console.error);
@@ -2960,11 +2981,11 @@ class KoniExtension {
2960
2981
 
2961
2982
  // Export mnemonic
2962
2983
 
2963
- keyringExportMnemonic(_ref69) {
2984
+ keyringExportMnemonic(_ref70) {
2964
2985
  let {
2965
2986
  address,
2966
2987
  password
2967
- } = _ref69;
2988
+ } = _ref70;
2968
2989
  const pair = _uiKeyring.keyring.getPair(address);
2969
2990
  const result = pair.exportMnemonic(password);
2970
2991
  return {
@@ -2974,10 +2995,10 @@ class KoniExtension {
2974
2995
 
2975
2996
  // Reset wallet
2976
2997
 
2977
- async resetWallet(_ref70) {
2998
+ async resetWallet(_ref71) {
2978
2999
  let {
2979
3000
  resetAll
2980
- } = _ref70;
3001
+ } = _ref71;
2981
3002
  try {
2982
3003
  await this.#koniState.resetWallet(resetAll);
2983
3004
  return {
@@ -2993,10 +3014,10 @@ class KoniExtension {
2993
3014
  }
2994
3015
 
2995
3016
  /// Signing substrate request
2996
- signingApprovePasswordV2(_ref71) {
3017
+ signingApprovePasswordV2(_ref72) {
2997
3018
  let {
2998
3019
  id
2999
- } = _ref71;
3020
+ } = _ref72;
3000
3021
  const queued = this.#koniState.getSignRequest(id);
3001
3022
  (0, _util.assert)(queued, (0, _i18next.t)('Unable to proceed. Please try again'));
3002
3023
  const {
@@ -3061,22 +3082,22 @@ class KoniExtension {
3061
3082
 
3062
3083
  /// Derive account
3063
3084
 
3064
- derivationCreateMultiple(_ref72) {
3085
+ derivationCreateMultiple(_ref73) {
3065
3086
  let {
3066
3087
  isAllowed,
3067
3088
  items,
3068
3089
  parentAddress
3069
- } = _ref72;
3090
+ } = _ref73;
3070
3091
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
3071
3092
  const isEvm = parentPair.type === 'ethereum';
3072
3093
  if (parentPair.isLocked) {
3073
3094
  _uiKeyring.keyring.unlockPair(parentPair.address);
3074
3095
  }
3075
- const createChild = _ref73 => {
3096
+ const createChild = _ref74 => {
3076
3097
  let {
3077
3098
  name,
3078
3099
  suri
3079
- } = _ref73;
3100
+ } = _ref74;
3080
3101
  const meta = {
3081
3102
  name: name,
3082
3103
  parentAddress
@@ -3122,10 +3143,10 @@ class KoniExtension {
3122
3143
  }
3123
3144
  return true;
3124
3145
  }
3125
- derivationCreateV3(_ref74) {
3146
+ derivationCreateV3(_ref75) {
3126
3147
  let {
3127
3148
  address: parentAddress
3128
- } = _ref74;
3149
+ } = _ref75;
3129
3150
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
3130
3151
  const isEvm = parentPair.type === 'ethereum';
3131
3152
  if (parentPair.isLocked) {
@@ -3160,11 +3181,11 @@ class KoniExtension {
3160
3181
  }
3161
3182
  return true;
3162
3183
  }
3163
- validateDerivePath(_ref75) {
3184
+ validateDerivePath(_ref76) {
3164
3185
  let {
3165
3186
  parentAddress,
3166
3187
  suri
3167
- } = _ref75;
3188
+ } = _ref76;
3168
3189
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
3169
3190
  const isEvm = parentPair.type === 'ethereum';
3170
3191
  if (parentPair.isLocked) {
@@ -3197,12 +3218,12 @@ class KoniExtension {
3197
3218
  suri: meta.suri
3198
3219
  };
3199
3220
  }
3200
- getListDeriveAccounts(_ref76) {
3221
+ getListDeriveAccounts(_ref77) {
3201
3222
  let {
3202
3223
  limit,
3203
3224
  page,
3204
3225
  parentAddress
3205
- } = _ref76;
3226
+ } = _ref77;
3206
3227
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
3207
3228
  const isEvm = parentPair.type === 'ethereum';
3208
3229
  if (parentPair.isLocked) {
@@ -3312,10 +3333,10 @@ class KoniExtension {
3312
3333
  getSupportedSmartContractTypes() {
3313
3334
  return this.#koniState.getSupportedSmartContractTypes();
3314
3335
  }
3315
- getTransaction(_ref77) {
3336
+ getTransaction(_ref78) {
3316
3337
  let {
3317
3338
  id
3318
- } = _ref77;
3339
+ } = _ref78;
3319
3340
  const {
3320
3341
  transaction,
3321
3342
  ...transactionResult
@@ -3325,8 +3346,8 @@ class KoniExtension {
3325
3346
  subscribeTransactions(id, port) {
3326
3347
  const cb = (0, _subscriptions.createSubscription)(id, port);
3327
3348
  function convertRs(rs) {
3328
- return Object.fromEntries(Object.entries(rs).map(_ref78 => {
3329
- let [key, value] = _ref78;
3349
+ return Object.fromEntries(Object.entries(rs).map(_ref79 => {
3350
+ let [key, value] = _ref79;
3330
3351
  const {
3331
3352
  additionalValidator,
3332
3353
  eventsHandler,
@@ -3358,10 +3379,10 @@ class KoniExtension {
3358
3379
  });
3359
3380
  return notificationSubject.value;
3360
3381
  }
3361
- async reloadCron(_ref79) {
3382
+ async reloadCron(_ref80) {
3362
3383
  let {
3363
3384
  data
3364
- } = _ref79;
3385
+ } = _ref80;
3365
3386
  if (data === 'nft') {
3366
3387
  return await this.#koniState.reloadNft();
3367
3388
  } else if (data === 'staking') {
@@ -3405,20 +3426,20 @@ class KoniExtension {
3405
3426
 
3406
3427
  // Phishing detect
3407
3428
 
3408
- async passPhishingPage(_ref80) {
3429
+ async passPhishingPage(_ref81) {
3409
3430
  let {
3410
3431
  url
3411
- } = _ref80;
3432
+ } = _ref81;
3412
3433
  return await this.#koniState.approvePassPhishingPage(url);
3413
3434
  }
3414
3435
 
3415
3436
  /// Wallet connect
3416
3437
 
3417
3438
  // Connect
3418
- async connectWalletConnect(_ref81) {
3439
+ async connectWalletConnect(_ref82) {
3419
3440
  let {
3420
3441
  uri
3421
- } = _ref81;
3442
+ } = _ref82;
3422
3443
  await this.#koniState.walletConnectService.connect(uri);
3423
3444
  return true;
3424
3445
  }
@@ -3431,11 +3452,11 @@ class KoniExtension {
3431
3452
  });
3432
3453
  return this.#koniState.requestService.allConnectWCRequests;
3433
3454
  }
3434
- async approveWalletConnectSession(_ref82) {
3455
+ async approveWalletConnectSession(_ref83) {
3435
3456
  let {
3436
3457
  accounts: selectedAccounts,
3437
3458
  id
3438
- } = _ref82;
3459
+ } = _ref83;
3439
3460
  const request = this.#koniState.requestService.getConnectWCRequest(id);
3440
3461
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
3441
3462
  throw new Error('The proposal has been expired');
@@ -3447,8 +3468,8 @@ class KoniExtension {
3447
3468
  const availableNamespaces = {};
3448
3469
  const namespaces = {};
3449
3470
  const chainInfoMap = this.#koniState.getChainInfoMap();
3450
- Object.entries(requiredNamespaces).forEach(_ref83 => {
3451
- let [key, namespace] = _ref83;
3471
+ Object.entries(requiredNamespaces).forEach(_ref84 => {
3472
+ let [key, namespace] = _ref84;
3452
3473
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
3453
3474
  if (namespace.chains) {
3454
3475
  const unSupportChains = namespace.chains.filter(chain => !(0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap));
@@ -3461,8 +3482,8 @@ class KoniExtension {
3461
3482
  throw new Error((0, _utils5.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
3462
3483
  }
3463
3484
  });
3464
- Object.entries(optionalNamespaces).forEach(_ref84 => {
3465
- let [key, namespace] = _ref84;
3485
+ Object.entries(optionalNamespaces).forEach(_ref85 => {
3486
+ let [key, namespace] = _ref85;
3466
3487
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
3467
3488
  if (namespace.chains) {
3468
3489
  const supportChains = namespace.chains.filter(chain => (0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap)) || [];
@@ -3486,8 +3507,8 @@ class KoniExtension {
3486
3507
  }
3487
3508
  }
3488
3509
  });
3489
- Object.entries(availableNamespaces).forEach(_ref85 => {
3490
- let [key, namespace] = _ref85;
3510
+ Object.entries(availableNamespaces).forEach(_ref86 => {
3511
+ let [key, namespace] = _ref86;
3491
3512
  if (namespace.chains) {
3492
3513
  const accounts = [];
3493
3514
  const chains = (0, _utils4.uniqueStringArray)(namespace.chains);
@@ -3511,10 +3532,10 @@ class KoniExtension {
3511
3532
  request.resolve();
3512
3533
  return true;
3513
3534
  }
3514
- async rejectWalletConnectSession(_ref86) {
3535
+ async rejectWalletConnectSession(_ref87) {
3515
3536
  let {
3516
3537
  id
3517
- } = _ref86;
3538
+ } = _ref87;
3518
3539
  const request = this.#koniState.requestService.getConnectWCRequest(id);
3519
3540
  const wcId = request.request.id;
3520
3541
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
@@ -3536,10 +3557,10 @@ class KoniExtension {
3536
3557
  });
3537
3558
  return this.#koniState.walletConnectService.sessions;
3538
3559
  }
3539
- async disconnectWalletConnectSession(_ref87) {
3560
+ async disconnectWalletConnectSession(_ref88) {
3540
3561
  let {
3541
3562
  topic
3542
- } = _ref87;
3563
+ } = _ref88;
3543
3564
  await this.#koniState.walletConnectService.disconnect(topic);
3544
3565
  return true;
3545
3566
  }
@@ -3552,18 +3573,18 @@ class KoniExtension {
3552
3573
  });
3553
3574
  return this.#koniState.requestService.allNotSupportWCRequests;
3554
3575
  }
3555
- approveWalletConnectNotSupport(_ref88) {
3576
+ approveWalletConnectNotSupport(_ref89) {
3556
3577
  let {
3557
3578
  id
3558
- } = _ref88;
3579
+ } = _ref89;
3559
3580
  const request = this.#koniState.requestService.getNotSupportWCRequest(id);
3560
3581
  request.resolve();
3561
3582
  return true;
3562
3583
  }
3563
- rejectWalletConnectNotSupport(_ref89) {
3584
+ rejectWalletConnectNotSupport(_ref90) {
3564
3585
  let {
3565
3586
  id
3566
- } = _ref89;
3587
+ } = _ref90;
3567
3588
  const request = this.#koniState.requestService.getNotSupportWCRequest(id);
3568
3589
  request.reject(new Error('USER_REJECTED'));
3569
3590
  return true;
@@ -3571,11 +3592,11 @@ class KoniExtension {
3571
3592
 
3572
3593
  /// Manta
3573
3594
 
3574
- async enableMantaPay(_ref90) {
3595
+ async enableMantaPay(_ref91) {
3575
3596
  let {
3576
3597
  address,
3577
3598
  password
3578
- } = _ref90;
3599
+ } = _ref91;
3579
3600
  // always takes the current account
3580
3601
  function timeout() {
3581
3602
  return new Promise(resolve => setTimeout(resolve, 1500));
@@ -3699,10 +3720,10 @@ class KoniExtension {
3699
3720
 
3700
3721
  /// Metadata
3701
3722
 
3702
- async findRawMetadata(_ref91) {
3723
+ async findRawMetadata(_ref92) {
3703
3724
  let {
3704
3725
  genesisHash
3705
- } = _ref91;
3726
+ } = _ref92;
3706
3727
  const {
3707
3728
  metadata,
3708
3729
  specVersion
@@ -3949,18 +3970,18 @@ class KoniExtension {
3949
3970
 
3950
3971
  /* Campaign */
3951
3972
 
3952
- unlockDotCheckCanMint(_ref92) {
3973
+ unlockDotCheckCanMint(_ref93) {
3953
3974
  let {
3954
3975
  address,
3955
3976
  network,
3956
3977
  slug
3957
- } = _ref92;
3978
+ } = _ref93;
3958
3979
  return this.#koniState.mintCampaignService.unlockDotCampaign.canMint(address, slug, network);
3959
3980
  }
3960
- unlockDotSubscribeMintedData(id, port, _ref93) {
3981
+ unlockDotSubscribeMintedData(id, port, _ref94) {
3961
3982
  let {
3962
3983
  transactionId
3963
- } = _ref93;
3984
+ } = _ref94;
3964
3985
  const cb = (0, _subscriptions.createSubscription)(id, port);
3965
3986
  const subscription = this.#koniState.mintCampaignService.unlockDotCampaign.subscribeMintedNft(transactionId, cb);
3966
3987
  this.createUnsubscriptionHandle(id, subscription.unsubscribe);
@@ -3992,10 +4013,10 @@ class KoniExtension {
3992
4013
  });
3993
4014
  return filterBanner(await this.#koniState.campaignService.getProcessingCampaign());
3994
4015
  }
3995
- async completeCampaignBanner(_ref94) {
4016
+ async completeCampaignBanner(_ref95) {
3996
4017
  let {
3997
4018
  slug
3998
- } = _ref94;
4019
+ } = _ref95;
3999
4020
  const campaign = await this.#koniState.dbService.getCampaign(slug);
4000
4021
  if (campaign) {
4001
4022
  await this.#koniState.dbService.upsertCampaign({
@@ -4047,6 +4068,82 @@ class KoniExtension {
4047
4068
 
4048
4069
  /* Buy service */
4049
4070
 
4071
+ /* Swap service */
4072
+ async subscribeSwapPairs(id, port) {
4073
+ const cb = (0, _subscriptions.createSubscription)(id, port);
4074
+ let ready = false;
4075
+ await this.#koniState.swapService.waitForStarted();
4076
+ const callback = rs => {
4077
+ if (ready) {
4078
+ cb(rs);
4079
+ }
4080
+ };
4081
+ const subscription = this.#koniState.swapService.subscribeSwapPairs(callback);
4082
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
4083
+ port.onDisconnect.addListener(() => {
4084
+ this.cancelSubscription(id);
4085
+ });
4086
+ ready = true;
4087
+ return this.#koniState.swapService.getSwapPairs();
4088
+ }
4089
+ async handleSwapRequest(request) {
4090
+ return this.#koniState.swapService.handleSwapRequest(request);
4091
+ }
4092
+ async getLatestSwapQuote(swapRequest) {
4093
+ return this.#koniState.swapService.getLatestQuotes(swapRequest);
4094
+ }
4095
+ async validateSwapProcess(params) {
4096
+ return this.#koniState.swapService.validateSwapProcess(params);
4097
+ }
4098
+ async handleSwapStep(inputData) {
4099
+ const {
4100
+ address,
4101
+ process,
4102
+ quote,
4103
+ recipient
4104
+ } = inputData;
4105
+ if (!quote || !address || !process) {
4106
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)]);
4107
+ }
4108
+ const isLastStep = inputData.currentStep + 1 === process.steps.length;
4109
+ const swapValidations = await this.#koniState.swapService.validateSwapProcess({
4110
+ address,
4111
+ process,
4112
+ selectedQuote: quote,
4113
+ recipient
4114
+ });
4115
+ if (swapValidations.length > 0) {
4116
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors(swapValidations);
4117
+ }
4118
+
4119
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
4120
+ const {
4121
+ chainType,
4122
+ extrinsic,
4123
+ extrinsicType,
4124
+ transferNativeAmount,
4125
+ txChain,
4126
+ txData
4127
+ } = await this.#koniState.swapService.handleSwapProcess(inputData);
4128
+ // const chosenFeeToken = process.steps.findIndex((step) => step.type === SwapStepType.SET_FEE_TOKEN) > -1;
4129
+ // const allowSkipValidation = [ExtrinsicType.SET_FEE_TOKEN, ExtrinsicType.SWAP].includes(extrinsicType);
4130
+
4131
+ return await this.#koniState.transactionService.handleTransaction({
4132
+ address,
4133
+ chain: txChain,
4134
+ transaction: extrinsic,
4135
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
4136
+ data: txData,
4137
+ extrinsicType,
4138
+ // change this depends on step
4139
+ chainType,
4140
+ resolveOnDone: !isLastStep,
4141
+ transferNativeAmount
4142
+ // skipFeeValidation: chosenFeeToken && allowSkipValidation
4143
+ });
4144
+ }
4145
+ /* Swap service */
4146
+
4050
4147
  // --------------------------------------------------------------
4051
4148
  // eslint-disable-next-line @typescript-eslint/require-await
4052
4149
  async handle(id, type, request, port) {
@@ -4178,6 +4275,8 @@ class KoniExtension {
4178
4275
  return this.subscribeCrowdloan(id, port);
4179
4276
  case 'pri(derivation.createV2)':
4180
4277
  return this.derivationCreateV2(request);
4278
+ case 'pri(accounts.batchExportV2)':
4279
+ return this.batchExportV2(request);
4181
4280
  case 'pri(json.restoreV2)':
4182
4281
  return this.jsonRestoreV2(request);
4183
4282
  case 'pri(json.batchRestoreV2)':
@@ -4576,6 +4675,19 @@ class KoniExtension {
4576
4675
  case 'pri(database.exportJson)':
4577
4676
  return this.#koniState.dbService.getExportJson();
4578
4677
  /* Database */
4678
+
4679
+ /* Swap service */
4680
+ case 'pri(swapService.subscribePairs)':
4681
+ return this.subscribeSwapPairs(id, port);
4682
+ case 'pri(swapService.handleSwapRequest)':
4683
+ return this.handleSwapRequest(request);
4684
+ case 'pri(swapService.getLatestQuote)':
4685
+ return this.getLatestSwapQuote(request);
4686
+ case 'pri(swapService.validateSwapProcess)':
4687
+ return this.validateSwapProcess(request);
4688
+ case 'pri(swapService.handleSwapStep)':
4689
+ return this.handleSwapStep(request);
4690
+ /* Swap service */
4579
4691
  // Default
4580
4692
  default:
4581
4693
  throw new Error(`Unable to handle message of type ${type}`);