@subwallet/extension-base 1.3.61-0 → 1.3.63-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 (73) hide show
  1. package/cjs/koni/api/staking/bonding/utils.js +1 -1
  2. package/cjs/packageInfo.js +1 -1
  3. package/cjs/services/balance-service/transfer/smart-contract.js +14 -10
  4. package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +0 -6
  5. package/cjs/services/balance-service/transfer/xcm/utils.js +2 -0
  6. package/cjs/services/chain-service/constants.js +16 -0
  7. package/cjs/services/chain-service/utils/index.js +24 -4
  8. package/cjs/services/chain-service/utils/patch.js +2 -2
  9. package/cjs/services/earning-service/constants/chains.js +8 -3
  10. package/cjs/services/earning-service/handlers/native-staking/base-para.js +6 -3
  11. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +4 -1
  12. package/cjs/services/earning-service/handlers/native-staking/tanssi.js +496 -0
  13. package/cjs/services/earning-service/service.js +4 -0
  14. package/cjs/services/earning-service/utils/index.js +2 -0
  15. package/cjs/services/fee-service/utils/tokenPayFee.js +25 -2
  16. package/cjs/services/migration-service/scripts/DeleteEarningData20251010.js +21 -0
  17. package/cjs/services/migration-service/scripts/index.js +3 -1
  18. package/cjs/services/swap-service/handler/base-handler.js +4 -1
  19. package/cjs/services/swap-service/handler/chainflip-handler.js +1 -17
  20. package/cjs/services/swap-service/handler/optimex-handler.js +421 -0
  21. package/cjs/services/swap-service/handler/simpleswap-handler.js +4 -2
  22. package/cjs/services/swap-service/index.js +38 -140
  23. package/cjs/services/swap-service/utils.js +16 -157
  24. package/cjs/services/transaction-service/helpers/index.js +2 -1
  25. package/cjs/types/service-base.js +0 -1
  26. package/cjs/types/swap/index.js +5 -8
  27. package/cjs/utils/account/common.js +1 -2
  28. package/cjs/utils/fee/transfer.js +9 -1
  29. package/koni/api/staking/bonding/utils.js +2 -2
  30. package/package.json +21 -6
  31. package/packageInfo.js +1 -1
  32. package/services/balance-service/transfer/smart-contract.d.ts +3 -2
  33. package/services/balance-service/transfer/smart-contract.js +35 -29
  34. package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +0 -4
  35. package/services/balance-service/transfer/xcm/acrossBridge/index.js +0 -4
  36. package/services/balance-service/transfer/xcm/utils.js +2 -0
  37. package/services/chain-service/constants.js +16 -0
  38. package/services/chain-service/utils/index.d.ts +3 -2
  39. package/services/chain-service/utils/index.js +20 -1
  40. package/services/chain-service/utils/patch.d.ts +1 -1
  41. package/services/chain-service/utils/patch.js +2 -2
  42. package/services/earning-service/constants/chains.d.ts +2 -0
  43. package/services/earning-service/constants/chains.js +6 -2
  44. package/services/earning-service/handlers/native-staking/base-para.js +6 -3
  45. package/services/earning-service/handlers/native-staking/relay-chain.js +4 -1
  46. package/services/earning-service/handlers/native-staking/tanssi.d.ts +16 -0
  47. package/services/earning-service/handlers/native-staking/tanssi.js +478 -0
  48. package/services/earning-service/service.js +4 -0
  49. package/services/earning-service/utils/index.js +2 -0
  50. package/services/fee-service/utils/tokenPayFee.js +25 -2
  51. package/services/migration-service/scripts/DeleteEarningData20251010.d.ts +4 -0
  52. package/services/migration-service/scripts/DeleteEarningData20251010.js +13 -0
  53. package/services/migration-service/scripts/index.js +3 -1
  54. package/services/swap-service/handler/base-handler.js +6 -3
  55. package/services/swap-service/handler/chainflip-handler.d.ts +0 -2
  56. package/services/swap-service/handler/chainflip-handler.js +2 -18
  57. package/services/swap-service/handler/optimex-handler.d.ts +43 -0
  58. package/services/swap-service/handler/optimex-handler.js +410 -0
  59. package/services/swap-service/handler/simpleswap-handler.js +5 -3
  60. package/services/swap-service/index.d.ts +0 -1
  61. package/services/swap-service/index.js +21 -123
  62. package/services/swap-service/utils.d.ts +6 -12
  63. package/services/swap-service/utils.js +8 -138
  64. package/services/transaction-service/helpers/index.js +2 -1
  65. package/types/balance/transfer.d.ts +1 -0
  66. package/types/service-base.d.ts +3 -4
  67. package/types/service-base.js +0 -2
  68. package/types/swap/index.d.ts +3 -1
  69. package/types/swap/index.js +7 -6
  70. package/types/yield/info/account/info.d.ts +5 -0
  71. package/utils/account/common.js +2 -3
  72. package/utils/fee/transfer.js +9 -1
  73. package/utils/staticData/assetHubStaking.json +6 -1
@@ -1,22 +1,21 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
5
- import { _AssetRefPath } from '@subwallet/chain-list/types';
6
4
  import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
7
5
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
8
6
  import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
9
7
  import { fetchBlockedConfigObjects, fetchLatestBlockedActionsAndFeatures, getPassConfigId } from '@subwallet/extension-base/constants';
10
8
  import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
11
- import { _getAssetOriginChain, _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
9
+ import { _getAssetOriginChain } from '@subwallet/extension-base/services/chain-service/utils';
12
10
  import { AssetHubSwapHandler } from '@subwallet/extension-base/services/swap-service/handler/asset-hub';
13
11
  import { ChainflipSwapHandler } from '@subwallet/extension-base/services/swap-service/handler/chainflip-handler';
14
12
  import { HydradxHandler } from '@subwallet/extension-base/services/swap-service/handler/hydradx-handler';
15
- import { findAllBridgeDestinations, findBridgeTransitDestination, findSwapTransitDestination, getBridgeStep, getSupportedSwapChains, getSwapAltToken, getSwapStep, getTokenPairFromStep, isChainsHasSameProvider, processStepsToPathActions, SWAP_QUOTE_TIMEOUT_MAP } from '@subwallet/extension-base/services/swap-service/utils';
13
+ import { OptimexHandler } from '@subwallet/extension-base/services/swap-service/handler/optimex-handler';
14
+ import { getSwapAltToken, getTokenPairFromStep, processStepsToPathActions, SWAP_QUOTE_TIMEOUT_MAP } from '@subwallet/extension-base/services/swap-service/utils';
16
15
  import { BasicTxErrorType, DynamicSwapType } from '@subwallet/extension-base/types';
17
16
  import { DEFAULT_FIRST_STEP, MOCK_STEP_FEE } from '@subwallet/extension-base/types/service-base';
18
17
  import { _SUPPORTED_SWAP_PROVIDERS, SwapErrorType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
19
- import { _reformatAddressWithChain, createPromiseHandler, reformatAddress } from '@subwallet/extension-base/utils';
18
+ import { _reformatAddressWithChain, createPromiseHandler } from '@subwallet/extension-base/utils';
20
19
  import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
21
20
  import BigN from 'bignumber.js';
22
21
  import { t } from 'i18next';
@@ -107,6 +106,7 @@ export class SwapService {
107
106
  const providerId = ((_params$request$curre = params.request.currentQuote) === null || _params$request$curre === void 0 ? void 0 : _params$request$curre.id) || params.selectedQuote.provider.id;
108
107
  const handler = this.handlers[providerId];
109
108
  if (handler) {
109
+ // todo: handle error response from generateOptimalProcess
110
110
  return handler.generateOptimalProcessV2(params);
111
111
  } else {
112
112
  return this.getDefaultProcessV2(params);
@@ -144,6 +144,12 @@ export class SwapService {
144
144
  } catch (e) {
145
145
  throw new Error(e.message);
146
146
  }
147
+
148
+ // override fee for quote because some cases need estimate network fee on Extension (i.e. Optimex)
149
+ if (swapQuoteResponse.optimalQuote) {
150
+ const swapIndex = optimalProcess.steps.findIndex(step => step.type === SwapStepType.SWAP);
151
+ swapQuoteResponse.optimalQuote.feeInfo.feeComponent = optimalProcess.totalFee[swapIndex].feeComponent;
152
+ }
147
153
  if (swapQuoteResponse.error) {
148
154
  return {
149
155
  process: optimalProcess,
@@ -160,115 +166,6 @@ export class SwapService {
160
166
  quote: swapQuoteResponse
161
167
  };
162
168
  }
163
-
164
- // todo: rewrite this function
165
- getAvailablePath(request) {
166
- const {
167
- address,
168
- pair
169
- } = request;
170
- // todo: control provider tighter
171
- const supportSwapChains = getSupportedSwapChains();
172
- const fromToken = this.chainService.getAssetBySlug(pair.from);
173
- const toToken = this.chainService.getAssetBySlug(pair.to);
174
- const fromChain = _getAssetOriginChain(fromToken);
175
- const toChain = _getAssetOriginChain(toToken);
176
- const toChainInfo = this.chainService.getChainInfoByKey(toChain);
177
- const assetRefMap = this.chainService.getAssetRefMap();
178
- let process = [];
179
- if (!fromToken || !toToken) {
180
- throw Error('Token not found');
181
- }
182
- if (!fromChain || !toChain) {
183
- throw Error('Token metadata error');
184
- }
185
- const directXcmRef = Object.values(assetRefMap).find(assetRef => assetRef.path === _AssetRefPath.XCM && assetRef.srcAsset === fromToken.slug && assetRef.destAsset === toToken.slug);
186
- if (directXcmRef) {
187
- return [[], undefined];
188
- }
189
-
190
- // SWAP: 2 tokens in the same chain and chain has dex
191
- if (isChainsHasSameProvider(fromChain, toChain)) {
192
- // there's a dex that can support direct swapping
193
- process.push(getSwapStep(fromToken.slug, toToken.slug));
194
- return [process, request];
195
- }
196
-
197
- // ------------------------
198
- // BRIDGE -> SWAP: Try to find a token in dest chain that can bridge from fromToken
199
- const bridgeTransit = findBridgeTransitDestination(assetRefMap, fromToken, toToken);
200
- if (bridgeTransit && supportSwapChains.includes(toChain)) {
201
- const swapStep = getSwapStep(bridgeTransit, toToken.slug);
202
- process.push(getBridgeStep(fromToken.slug, bridgeTransit));
203
- process.push(swapStep);
204
- return [process, {
205
- ...request,
206
- address: reformatAddress(address, _getChainSubstrateAddressPrefix(toChainInfo)),
207
- pair: swapStep.pair
208
- }];
209
- }
210
-
211
- // ------------------------
212
- // SWAP -> BRIDGE: Try to find a token in from chain that can bridge to toToken
213
- const swapTransit = findSwapTransitDestination(assetRefMap, fromToken, toToken);
214
- if (swapTransit && supportSwapChains.includes(fromChain)) {
215
- const swapStep = getSwapStep(fromToken.slug, swapTransit);
216
- process.push(swapStep);
217
- process.push(getBridgeStep(swapTransit, toToken.slug));
218
- return [process, {
219
- ...request,
220
- pair: swapStep.pair
221
- }];
222
- }
223
-
224
- // ------------------------
225
- // BRIDGE -> SWAP -> BRIDGE: Try to find a tri-step path to swap
226
- const processList = [];
227
- const swapPairList = [];
228
- const allBridgeDestinations = findAllBridgeDestinations(assetRefMap, fromToken);
229
-
230
- // currently find first path. Todo: return all paths or best path.
231
- for (const bridgeTransit of allBridgeDestinations) {
232
- process = [];
233
- const bridgeDestinationInfo = this.chainService.getAssetBySlug(bridgeTransit);
234
- const swapTransit = findSwapTransitDestination(assetRefMap, bridgeDestinationInfo, toToken);
235
- if (bridgeTransit === swapTransit) {
236
- continue;
237
- }
238
- if (swapTransit && supportSwapChains.includes(bridgeDestinationInfo.originChain)) {
239
- const swapStep = getSwapStep(bridgeTransit, swapTransit);
240
- process.push(getBridgeStep(fromToken.slug, bridgeTransit));
241
- process.push(swapStep);
242
- process.push(getBridgeStep(swapTransit, toToken.slug));
243
-
244
- // set the highest priority to hydration provider
245
- if (bridgeDestinationInfo.originChain === COMMON_CHAIN_SLUGS.HYDRADX) {
246
- return [process, {
247
- ...request,
248
- address: _reformatAddressWithChain(address, this.chainService.getChainInfoByKey(COMMON_CHAIN_SLUGS.HYDRADX)),
249
- pair: swapStep.pair
250
- }];
251
- }
252
- processList.push(process);
253
- swapPairList.push(swapStep.pair);
254
- }
255
- }
256
-
257
- // get first process
258
- if (processList.length && swapPairList.length) {
259
- const [firstProcess, firstSwapPair] = [processList[0], swapPairList[0]];
260
- const chainSwap = this.chainService.getAssetBySlug(firstSwapPair.from).originChain;
261
- return [firstProcess, {
262
- ...request,
263
- address: _reformatAddressWithChain(address, this.chainService.getChainInfoByKey(chainSwap)),
264
- pair: firstSwapPair
265
- }];
266
- }
267
-
268
- // todo: encapsulate each route type to function
269
-
270
- return [[], undefined];
271
- }
272
169
  async getLatestQuoteFromSwapRequest(request) {
273
170
  let availablePath;
274
171
  try {
@@ -368,9 +265,6 @@ export class SwapService {
368
265
  case SwapProviderId.CHAIN_FLIP_MAINNET:
369
266
  this.handlers[providerId] = new ChainflipSwapHandler(this.chainService, this.state.balanceService, this.state.feeService, false);
370
267
  break;
371
- case SwapProviderId.HYDRADX_TESTNET:
372
- this.handlers[providerId] = new HydradxHandler(this.chainService, this.state.balanceService, this.state.feeService);
373
- break;
374
268
  case SwapProviderId.HYDRADX_MAINNET:
375
269
  this.handlers[providerId] = new HydradxHandler(this.chainService, this.state.balanceService, this.state.feeService, false);
376
270
  break;
@@ -380,12 +274,6 @@ export class SwapService {
380
274
  case SwapProviderId.KUSAMA_ASSET_HUB:
381
275
  this.handlers[providerId] = new AssetHubSwapHandler(this.chainService, this.state.balanceService, this.state.feeService, 'statemine');
382
276
  break;
383
- // case SwapProviderId.ROCOCO_ASSET_HUB:
384
- // this.handlers[providerId] = new AssetHubSwapHandler(this.chainService, this.state.balanceService, this.state.feeService, 'rococo_assethub');
385
- // break;
386
- case SwapProviderId.WESTEND_ASSET_HUB:
387
- this.handlers[providerId] = new AssetHubSwapHandler(this.chainService, this.state.balanceService, this.state.feeService, 'westend_assethub');
388
- break;
389
277
  case SwapProviderId.SIMPLE_SWAP:
390
278
  this.handlers[providerId] = new SimpleSwapHandler(this.chainService, this.state.balanceService, this.state.feeService);
391
279
  break;
@@ -395,6 +283,12 @@ export class SwapService {
395
283
  case SwapProviderId.KYBER:
396
284
  this.handlers[providerId] = new KyberHandler(this.chainService, this.state.balanceService, this.state.transactionService, this.state.feeService);
397
285
  break;
286
+ case SwapProviderId.OPTIMEX:
287
+ this.handlers[providerId] = new OptimexHandler(this.chainService, this.state.balanceService, this.state.feeService, false);
288
+ break;
289
+ case SwapProviderId.OPTIMEX_TESTNET:
290
+ this.handlers[providerId] = new OptimexHandler(this.chainService, this.state.balanceService, this.state.feeService, true);
291
+ break;
398
292
  default:
399
293
  throw new Error('Unsupported provider');
400
294
  }
@@ -445,6 +339,8 @@ export class SwapService {
445
339
  waitForStopped() {
446
340
  return this.stopPromiseHandler.promise;
447
341
  }
342
+
343
+ // todo: deprecated
448
344
  getSwapPairs() {
449
345
  return Object.entries(this.chainService.swapRefMap).map(([slug, assetRef]) => {
450
346
  const fromAsset = this.chainService.getAssetBySlug(assetRef.srcAsset);
@@ -499,6 +395,8 @@ export class SwapService {
499
395
  return Promise.reject(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
500
396
  }
501
397
  }
398
+
399
+ // todo: deprecated
502
400
  subscribeSwapPairs(callback) {
503
401
  return this.chainService.subscribeSwapRefMap().subscribe(refMap => {
504
402
  const latestData = Object.entries(refMap).map(([slug, assetRef]) => {
@@ -1,25 +1,14 @@
1
- import { _AssetRef, _ChainAsset } from '@subwallet/chain-list/types';
1
+ import { _ChainAsset } from '@subwallet/chain-list/types';
2
2
  import { CommonStepDetail, DynamicSwapAction, DynamicSwapType } from '@subwallet/extension-base/types';
3
3
  import { SwapPair } from '@subwallet/extension-base/types/swap';
4
4
  export declare const CHAIN_FLIP_TESTNET_EXPLORER = "https://blocks-perseverance.chainflip.io";
5
5
  export declare const CHAIN_FLIP_MAINNET_EXPLORER = "https://scan.chainflip.io";
6
6
  export declare const SIMPLE_SWAP_EXPLORER = "https://simpleswap.io";
7
- export declare const SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING: Record<string, string>;
8
7
  export declare const SWAP_QUOTE_TIMEOUT_MAP: Record<string, number>;
9
- export declare const _PROVIDER_TO_SUPPORTED_PAIR_MAP: Record<string, string[]>;
10
8
  export declare const FEE_RATE_MULTIPLIER: Record<string, number>;
11
- export declare function getSupportedSwapChains(): string[];
12
9
  export declare function getSwapAlternativeAsset(swapPair: SwapPair): string | undefined;
13
10
  export declare function getSwapAltToken(chainAsset: _ChainAsset): string | undefined;
14
- export declare function calculateSwapRate(fromAmount: string, toAmount: string, fromAsset: _ChainAsset, toAsset: _ChainAsset): number;
15
- export declare function convertSwapRate(rate: string, fromAsset: _ChainAsset, toAsset: _ChainAsset): number;
16
- export declare function getBridgeStep(from: string, to: string): DynamicSwapAction;
17
- export declare function getSwapStep(from: string, to: string): DynamicSwapAction;
18
- export declare function findBridgeTransitDestination(assetRefMap: Record<string, _AssetRef>, fromToken: _ChainAsset, toToken: _ChainAsset): string | undefined;
19
- export declare function findSwapTransitDestination(assetRefMap: Record<string, _AssetRef>, fromToken: _ChainAsset, toToken: _ChainAsset): string | undefined;
20
- export declare function findAllBridgeDestinations(assetRefMap: Record<string, _AssetRef>, fromToken: _ChainAsset): string[];
21
11
  export declare function getAmountAfterSlippage(amount: string, slippage: number): string;
22
- export declare function isChainsHasSameProvider(fromChain: string, toChain: string): boolean;
23
12
  export declare function getLastAmountFromSteps(steps: CommonStepDetail[]): string | undefined;
24
13
  export declare function getFirstAmountFromSteps(steps: CommonStepDetail[]): string | undefined;
25
14
  export declare function getChainRouteFromSteps(steps: CommonStepDetail[]): string[];
@@ -27,3 +16,8 @@ export declare function getTokenPairFromStep(steps: CommonStepDetail[]): SwapPai
27
16
  export declare function getSwapChainsFromPath(path: DynamicSwapAction[]): string[];
28
17
  export declare function processStepsToPathActions(steps: CommonStepDetail[]): DynamicSwapType[];
29
18
  export declare const DEFAULT_EXCESS_AMOUNT_WEIGHT = 1.04;
19
+ export declare const DetectedGenOptimalProcessErrMsg: {
20
+ AMOUNT_TOO_LOW: string;
21
+ AMOUNT_TOO_HIGH: string;
22
+ NOT_ENOUGHT_BITCOIN: string;
23
+ };
@@ -1,24 +1,13 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { COMMON_ASSETS, COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
5
- import { _AssetRefPath } from '@subwallet/chain-list/types';
6
- import { _getAssetDecimals, _getAssetOriginChain, _getOriginChainOfAsset, _parseAssetRefKey } from '@subwallet/extension-base/services/chain-service/utils';
4
+ import { _getOriginChainOfAsset, _parseAssetRefKey } from '@subwallet/extension-base/services/chain-service/utils';
7
5
  import { CommonStepType, DynamicSwapType, SwapStepType } from '@subwallet/extension-base/types';
8
6
  import { SwapProviderId } from '@subwallet/extension-base/types/swap';
9
7
  import BigN from 'bignumber.js';
10
8
  export const CHAIN_FLIP_TESTNET_EXPLORER = 'https://blocks-perseverance.chainflip.io';
11
9
  export const CHAIN_FLIP_MAINNET_EXPLORER = 'https://scan.chainflip.io';
12
10
  export const SIMPLE_SWAP_EXPLORER = 'https://simpleswap.io';
13
-
14
- // Deprecated
15
- export const SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING = {
16
- 'bittensor-NATIVE-TAO': 'tao',
17
- [COMMON_ASSETS.ETH]: 'eth',
18
- [COMMON_ASSETS.DOT]: 'dot',
19
- [COMMON_ASSETS.USDC_ETHEREUM]: 'usdc',
20
- [COMMON_ASSETS.USDT_ETHEREUM]: 'usdterc20'
21
- };
22
11
  export const SWAP_QUOTE_TIMEOUT_MAP = {
23
12
  // in milliseconds
24
13
  default: 90000,
@@ -26,29 +15,11 @@ export const SWAP_QUOTE_TIMEOUT_MAP = {
26
15
  [SwapProviderId.CHAIN_FLIP_MAINNET]: 30000,
27
16
  error: 10000
28
17
  };
29
-
30
- // deprecated
31
- export const _PROVIDER_TO_SUPPORTED_PAIR_MAP = {
32
- [SwapProviderId.HYDRADX_MAINNET]: [COMMON_CHAIN_SLUGS.HYDRADX],
33
- [SwapProviderId.CHAIN_FLIP_MAINNET]: [COMMON_CHAIN_SLUGS.POLKADOT, COMMON_CHAIN_SLUGS.ETHEREUM, COMMON_CHAIN_SLUGS.ARBITRUM],
34
- [SwapProviderId.POLKADOT_ASSET_HUB]: [COMMON_CHAIN_SLUGS.POLKADOT_ASSET_HUB],
35
- [SwapProviderId.KUSAMA_ASSET_HUB]: [COMMON_CHAIN_SLUGS.KUSAMA_ASSET_HUB],
36
- [SwapProviderId.SIMPLE_SWAP]: ['bittensor', COMMON_CHAIN_SLUGS.ETHEREUM, COMMON_CHAIN_SLUGS.POLKADOT],
37
- [SwapProviderId.UNISWAP]: [COMMON_CHAIN_SLUGS.ETHEREUM, COMMON_CHAIN_SLUGS.ARBITRUM],
38
- // testnet
39
- [SwapProviderId.CHAIN_FLIP_TESTNET]: [COMMON_CHAIN_SLUGS.CHAINFLIP_POLKADOT, COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA],
40
- [SwapProviderId.HYDRADX_TESTNET]: [COMMON_CHAIN_SLUGS.HYDRADX_TESTNET],
41
- [SwapProviderId.ROCOCO_ASSET_HUB]: [COMMON_CHAIN_SLUGS.ROCOCO_ASSET_HUB],
42
- [SwapProviderId.WESTEND_ASSET_HUB]: ['westend_assethub']
43
- };
44
18
  export const FEE_RATE_MULTIPLIER = {
45
19
  default: 1,
46
20
  medium: 1.2,
47
21
  high: 2
48
22
  };
49
- export function getSupportedSwapChains() {
50
- return [...new Set(Object.values(_PROVIDER_TO_SUPPORTED_PAIR_MAP).flat())];
51
- }
52
23
  export function getSwapAlternativeAsset(swapPair) {
53
24
  var _swapPair$metadata;
54
25
  return swapPair === null || swapPair === void 0 ? void 0 : (_swapPair$metadata = swapPair.metadata) === null || _swapPair$metadata === void 0 ? void 0 : _swapPair$metadata.alternativeAsset;
@@ -57,116 +28,9 @@ export function getSwapAltToken(chainAsset) {
57
28
  var _chainAsset$metadata;
58
29
  return (_chainAsset$metadata = chainAsset.metadata) === null || _chainAsset$metadata === void 0 ? void 0 : _chainAsset$metadata.alternativeSwapAsset;
59
30
  }
60
- export function calculateSwapRate(fromAmount, toAmount, fromAsset, toAsset) {
61
- const bnFromAmount = BigN(fromAmount);
62
- const bnToAmount = BigN(toAmount);
63
- const decimalDiff = _getAssetDecimals(toAsset) - _getAssetDecimals(fromAsset);
64
- const bnRate = bnFromAmount.div(bnToAmount);
65
- return 1 / bnRate.times(10 ** decimalDiff).toNumber();
66
- }
67
- export function convertSwapRate(rate, fromAsset, toAsset) {
68
- const decimalDiff = _getAssetDecimals(toAsset) - _getAssetDecimals(fromAsset);
69
- const bnRate = BigN(rate);
70
- return bnRate.times(10 ** decimalDiff).pow(-1).toNumber();
71
- }
72
-
73
- // export function getChainflipOptions (isTestnet: boolean) {
74
- // if (isTestnet) {
75
- // return {
76
- // network: getChainflipNetwork(isTestnet)
77
- // };
78
- // }
79
-
80
- // return {
81
- // network: getChainflipNetwork(isTestnet),
82
- // broker: getChainflipBroker(isTestnet)
83
- // };
84
- // }
85
-
86
- // function getChainflipNetwork (isTestnet: boolean) {
87
- // return isTestnet ? 'perseverance' : 'mainnet';
88
- // }
89
-
90
- // export function getChainflipBroker (isTestnet: boolean) { // noted: currently not use testnet broker
91
- // if (isTestnet) {
92
- // return {
93
- // url: `https://perseverance.chainflip-broker.io/rpc/${CHAINFLIP_BROKER_API}`
94
- // };
95
- // } else {
96
- // return {
97
- // url: `https://chainflip-broker.io/rpc/${CHAINFLIP_BROKER_API}`
98
- // };
99
- // }
100
- // }
101
-
102
- // export function getChainflipSwap (isTestnet: boolean) {
103
- // if (isTestnet) {
104
- // return `https://perseverance.chainflip-broker.io/swap?apikey=${CHAINFLIP_BROKER_API}`;
105
- // } else {
106
- // return `https://chainflip-broker.io/swap?apikey=${CHAINFLIP_BROKER_API}`;
107
- // }
108
- // }
109
-
110
- // export function getAssetsUrl (isTestnet: boolean) {
111
- // if (isTestnet) {
112
- // return 'https://perseverance.chainflip-broker.io/assets';
113
- // } else {
114
- // return 'https://chainflip-broker.io/assets';
115
- // }
116
- // }
117
-
118
- export function getBridgeStep(from, to) {
119
- return {
120
- action: DynamicSwapType.BRIDGE,
121
- pair: {
122
- slug: `${from}___${to}`,
123
- // todo: recheck with assetRef format from chain list
124
- from,
125
- to
126
- }
127
- };
128
- }
129
- export function getSwapStep(from, to) {
130
- return {
131
- action: DynamicSwapType.SWAP,
132
- pair: {
133
- slug: `${from}___${to}`,
134
- // todo: recheck with assetRef format from chain list
135
- from,
136
- to
137
- }
138
- };
139
- }
140
- export function findBridgeTransitDestination(assetRefMap, fromToken, toToken) {
141
- const foundAssetRef = Object.values(assetRefMap).find(assetRef => assetRef.srcAsset === fromToken.slug && assetRef.destChain === _getAssetOriginChain(toToken) && assetRef.path === _AssetRefPath.XCM);
142
- if (foundAssetRef) {
143
- return foundAssetRef.destAsset;
144
- }
145
- return undefined;
146
- }
147
- export function findSwapTransitDestination(assetRefMap, fromToken, toToken) {
148
- const foundAssetRef = Object.values(assetRefMap).find(assetRef => assetRef.destAsset === toToken.slug && assetRef.srcChain === _getAssetOriginChain(fromToken) && assetRef.path === _AssetRefPath.XCM);
149
- if (foundAssetRef) {
150
- return foundAssetRef.srcAsset;
151
- }
152
- return undefined;
153
- }
154
- export function findAllBridgeDestinations(assetRefMap, fromToken) {
155
- const foundAssetRefs = Object.values(assetRefMap).filter(assetRef => assetRef.srcAsset === fromToken.slug && assetRef.path === _AssetRefPath.XCM);
156
- return foundAssetRefs.map(assetRef => assetRef.destAsset);
157
- }
158
31
  export function getAmountAfterSlippage(amount, slippage) {
159
32
  return BigN(amount).multipliedBy(BigN(1).minus(BigN(slippage))).integerValue(BigN.ROUND_DOWN).toString();
160
33
  }
161
- export function isChainsHasSameProvider(fromChain, toChain) {
162
- // todo: a provider may support multiple chains but not cross-chain swaps
163
- for (const group of Object.values(_PROVIDER_TO_SUPPORTED_PAIR_MAP)) {
164
- if (group.includes(fromChain) && group.includes(toChain)) {
165
- return true;
166
- }
167
- }
168
- return false;
169
- }
170
34
  export function getLastAmountFromSteps(steps) {
171
35
  var _lastStep$metadata;
172
36
  const lastStep = steps[steps.length - 1]; // last step
@@ -265,4 +129,10 @@ export function processStepsToPathActions(steps) {
265
129
  }
266
130
  return path;
267
131
  }
268
- export const DEFAULT_EXCESS_AMOUNT_WEIGHT = 1.04; // add 2%
132
+ export const DEFAULT_EXCESS_AMOUNT_WEIGHT = 1.04; // add 2%
133
+
134
+ export const DetectedGenOptimalProcessErrMsg = {
135
+ AMOUNT_TOO_LOW: 'amount too low',
136
+ AMOUNT_TOO_HIGH: 'amount too high',
137
+ NOT_ENOUGHT_BITCOIN: 'for the transaction. lower your btc amount and try again' // todo: improve handle msg error
138
+ };
@@ -24,7 +24,8 @@ export const isCardanoTransaction = tx => {
24
24
 
25
25
  // TODO: [Review] this function
26
26
  export const isBitcoinTransaction = tx => {
27
- return 'data' in tx && Array.isArray(tx.data.inputs);
27
+ var _data;
28
+ return 'data' in tx && Array.isArray((_data = tx.data) === null || _data === void 0 ? void 0 : _data.inputs);
28
29
  };
29
30
  const typeName = type => {
30
31
  switch (type) {
@@ -17,6 +17,7 @@ export interface ResponseSubscribeTransfer {
17
17
  feeType: FeeChainType;
18
18
  feePercentageSpecialCase?: number;
19
19
  error?: string;
20
+ isEvmRpcError?: boolean;
20
21
  }
21
22
  export interface RequestSubmitTransferWithId extends RequestSubmitTransfer {
22
23
  id?: string;
@@ -1,7 +1,5 @@
1
- import { DynamicSwapAction, OptimalSwapPathParamsV2, SwapFeeType, SwapStepType } from '@subwallet/extension-base/types/swap';
2
- import { OptimalYieldPath, OptimalYieldPathParams, YieldStepType } from '@subwallet/extension-base/types/yield';
3
- export declare type OptimalProcessParams = OptimalYieldPathParams | OptimalSwapPathParamsV2;
4
- export declare type OptimalProcessResult = OptimalYieldPath | CommonOptimalSwapPath;
1
+ import { DynamicSwapAction, SwapFeeType, SwapStepType } from '@subwallet/extension-base/types/swap';
2
+ import { YieldStepType } from '@subwallet/extension-base/types/yield';
5
3
  export declare enum CommonStepType {
6
4
  DEFAULT = "DEFAULT",
7
5
  XCM = "XCM",
@@ -21,6 +19,7 @@ export interface CommonFeeComponent {
21
19
  amount: string;
22
20
  tokenSlug: string;
23
21
  percentage?: number;
22
+ metadata?: any;
24
23
  }
25
24
  export interface CommonStepFeeInfo {
26
25
  feeComponent: CommonFeeComponent[];
@@ -1,8 +1,6 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- /* ServiceWithProcess */
5
-
6
4
  export let CommonStepType;
7
5
  (function (CommonStepType) {
8
6
  CommonStepType["DEFAULT"] = "DEFAULT";
@@ -63,7 +63,9 @@ export declare enum SwapProviderId {
63
63
  WESTEND_ASSET_HUB = "WESTEND_ASSET_HUB",
64
64
  SIMPLE_SWAP = "SIMPLE_SWAP",
65
65
  UNISWAP = "UNISWAP",
66
- KYBER = "KYBER"
66
+ KYBER = "KYBER",
67
+ OPTIMEX = "OPTIMEX",
68
+ OPTIMEX_TESTNET = "OPTIMEX_TESTNET"
67
69
  }
68
70
  export declare const _SUPPORTED_SWAP_PROVIDERS: SwapProviderId[];
69
71
  export interface SwapProvider {
@@ -19,11 +19,15 @@ export let SwapErrorType;
19
19
  SwapErrorType["NOT_MEET_MIN_EXPECTED"] = "NOT_MEET_MIN_EXPECTED";
20
20
  })(SwapErrorType || (SwapErrorType = {}));
21
21
  export let SwapStepType;
22
+
23
+ // todo: export this to use from sdk
22
24
  (function (SwapStepType) {
23
25
  SwapStepType["SWAP"] = "SWAP";
24
26
  SwapStepType["PERMIT"] = "PERMIT";
25
27
  })(SwapStepType || (SwapStepType = {}));
26
28
  export let SwapProviderId;
29
+
30
+ // todo: export this to use from sdk
27
31
  (function (SwapProviderId) {
28
32
  SwapProviderId["CHAIN_FLIP_TESTNET"] = "CHAIN_FLIP_TESTNET";
29
33
  SwapProviderId["CHAIN_FLIP_MAINNET"] = "CHAIN_FLIP_MAINNET";
@@ -36,13 +40,10 @@ export let SwapProviderId;
36
40
  SwapProviderId["SIMPLE_SWAP"] = "SIMPLE_SWAP";
37
41
  SwapProviderId["UNISWAP"] = "UNISWAP";
38
42
  SwapProviderId["KYBER"] = "KYBER";
43
+ SwapProviderId["OPTIMEX"] = "OPTIMEX";
44
+ SwapProviderId["OPTIMEX_TESTNET"] = "OPTIMEX_TESTNET";
39
45
  })(SwapProviderId || (SwapProviderId = {}));
40
- export const _SUPPORTED_SWAP_PROVIDERS = [SwapProviderId.CHAIN_FLIP_TESTNET, SwapProviderId.CHAIN_FLIP_MAINNET, SwapProviderId.HYDRADX_MAINNET,
41
- // SwapProviderId.HYDRADX_TESTNET,
42
- SwapProviderId.POLKADOT_ASSET_HUB, SwapProviderId.KUSAMA_ASSET_HUB,
43
- // SwapProviderId.ROCOCO_ASSET_HUB,
44
- // SwapProviderId.WESTEND_ASSET_HUB,
45
- SwapProviderId.SIMPLE_SWAP, SwapProviderId.UNISWAP, SwapProviderId.KYBER];
46
+ export const _SUPPORTED_SWAP_PROVIDERS = [SwapProviderId.CHAIN_FLIP_TESTNET, SwapProviderId.CHAIN_FLIP_MAINNET, SwapProviderId.HYDRADX_MAINNET, SwapProviderId.POLKADOT_ASSET_HUB, SwapProviderId.KUSAMA_ASSET_HUB, SwapProviderId.SIMPLE_SWAP, SwapProviderId.UNISWAP, SwapProviderId.KYBER, SwapProviderId.OPTIMEX, SwapProviderId.OPTIMEX_TESTNET];
46
47
  // process handling
47
48
  export let SwapFeeType;
48
49
  (function (SwapFeeType) {
@@ -48,6 +48,11 @@ export interface AbstractYieldPositionInfo extends BaseYieldPositionInfo {
48
48
  subnetShortName: string;
49
49
  originalTotalStake: string;
50
50
  };
51
+ metadata?: {
52
+ pendingStake?: string;
53
+ compoundingStake?: string;
54
+ manualStake?: string;
55
+ };
51
56
  }
52
57
  /**
53
58
  * @interface SpecialYieldPositionInfo
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
5
- import { _chainInfoToChainType, _getChainSubstrateAddressPrefix, _getSubstrateGenesisHash, _isChainBitcoinCompatible, _isChainCardanoCompatible, _isChainEvmCompatible, _isChainTonCompatible, _isSubstrateEvmCompatibleChain } from '@subwallet/extension-base/services/chain-service/utils';
5
+ import { _chainInfoToAccountChainType, _getChainSubstrateAddressPrefix, _getSubstrateGenesisHash, _isChainBitcoinCompatible, _isChainCardanoCompatible, _isChainEvmCompatible, _isChainTonCompatible, _isSubstrateEvmCompatibleChain } from '@subwallet/extension-base/services/chain-service/utils';
6
6
  import { AccountChainType } from '@subwallet/extension-base/types';
7
7
  import { getAccountChainTypeFromKeypairType, pairToAccount } from '@subwallet/extension-base/utils';
8
8
  import { decodeAddress, encodeAddress, getKeypairTypeByAddress, isAddress, isBitcoinAddress, isCardanoAddress, isTonAddress } from '@subwallet/keyring';
@@ -41,8 +41,7 @@ export function reformatAddress(address, networkPrefix = 42, isEthereum = false,
41
41
  }
42
42
  }
43
43
  export const _reformatAddressWithChain = (address, chainInfo) => {
44
- // todo: check for cardano
45
- const chainType = _chainInfoToChainType(chainInfo);
44
+ const chainType = _chainInfoToAccountChainType(chainInfo);
46
45
  if (chainType === AccountChainType.SUBSTRATE) {
47
46
  return reformatAddress(address, _getChainSubstrateAddressPrefix(chainInfo));
48
47
  } else if (chainType === AccountChainType.TON || chainType === AccountChainType.CARDANO) {
@@ -96,6 +96,7 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
96
96
  let feeOptions;
97
97
  let maxTransferable;
98
98
  let error;
99
+ let isEvmRpcError = false;
99
100
  const fakeAddress = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap'; // todo: move this
100
101
  const substrateAddress = fakeAddress; // todo: move this
101
102
  const evmAddress = u8aToHex(addressToEvm(fakeAddress)); // todo: move this
@@ -120,6 +121,9 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
120
121
  value,
121
122
  fallbackFee: true
122
123
  });
124
+ if (error) {
125
+ isEvmRpcError = true;
126
+ }
123
127
  } else {
124
128
  [transaction,, error] = await getEVMTransactionObject({
125
129
  chain: srcChain.slug,
@@ -133,6 +137,9 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
133
137
  value,
134
138
  fallbackFee: true
135
139
  });
140
+ if (error) {
141
+ isEvmRpcError = true;
142
+ }
136
143
  }
137
144
  } else if (isTonAddress(address) && _isTokenTransferredByTon(srcToken)) {
138
145
  [transaction] = await createTonTransaction({
@@ -307,7 +314,8 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
307
314
  feeOptions: feeOptions,
308
315
  feeType: feeChainType,
309
316
  id: id,
310
- error
317
+ error,
318
+ isEvmRpcError: isEvmRpcError
311
319
  };
312
320
  };
313
321
  export const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
@@ -1 +1,6 @@
1
- {}
1
+ {
2
+ "westend": "westend_assethub",
3
+ "paseoTest": "paseo_assethub",
4
+ "kusama": "statemine",
5
+ "polkadot": "statemint"
6
+ }