@subwallet/extension-base 1.3.39-0 → 1.3.41-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 (55) hide show
  1. package/cjs/constants/environment.js +4 -2
  2. package/cjs/koni/background/handlers/Extension.js +114 -105
  3. package/cjs/packageInfo.js +1 -1
  4. package/cjs/services/balance-service/helpers/subscribe/evm.js +6 -1
  5. package/cjs/services/balance-service/transfer/xcm/index.js +26 -29
  6. package/cjs/services/balance-service/transfer/xcm/utils.js +52 -56
  7. package/cjs/services/chain-service/constants.js +6 -5
  8. package/cjs/services/chain-service/handler/CardanoApi.js +25 -35
  9. package/cjs/services/chain-service/index.js +4 -0
  10. package/cjs/services/chain-service/utils/patch.js +1 -1
  11. package/cjs/services/earning-service/handlers/native-staking/tao.js +4 -38
  12. package/cjs/services/earning-service/handlers/special.js +28 -36
  13. package/cjs/services/swap-service/handler/base-handler.js +58 -53
  14. package/cjs/services/swap-service/handler/chainflip-handler.js +29 -18
  15. package/cjs/services/swap-service/handler/kyber-handler.js +46 -34
  16. package/cjs/services/swap-service/handler/simpleswap-handler.js +79 -43
  17. package/cjs/services/swap-service/handler/uniswap-handler.js +5 -12
  18. package/cjs/services/swap-service/utils.js +48 -37
  19. package/cjs/types/environment.js +19 -0
  20. package/cjs/utils/environment.js +30 -2
  21. package/cjs/utils/fee/transfer.js +41 -33
  22. package/constants/environment.d.ts +1 -0
  23. package/constants/environment.js +2 -1
  24. package/koni/background/handlers/Extension.js +52 -43
  25. package/package.json +12 -7
  26. package/packageInfo.js +1 -1
  27. package/services/balance-service/helpers/subscribe/evm.js +6 -1
  28. package/services/balance-service/transfer/xcm/index.d.ts +1 -2
  29. package/services/balance-service/transfer/xcm/index.js +23 -26
  30. package/services/balance-service/transfer/xcm/utils.d.ts +38 -6
  31. package/services/balance-service/transfer/xcm/utils.js +51 -55
  32. package/services/chain-service/constants.d.ts +1 -0
  33. package/services/chain-service/constants.js +6 -5
  34. package/services/chain-service/handler/CardanoApi.d.ts +1 -5
  35. package/services/chain-service/handler/CardanoApi.js +26 -34
  36. package/services/chain-service/index.js +4 -0
  37. package/services/chain-service/utils/patch.js +1 -1
  38. package/services/earning-service/handlers/native-staking/tao.d.ts +0 -11
  39. package/services/earning-service/handlers/native-staking/tao.js +4 -24
  40. package/services/earning-service/handlers/special.js +12 -20
  41. package/services/swap-service/handler/base-handler.js +11 -6
  42. package/services/swap-service/handler/chainflip-handler.d.ts +0 -2
  43. package/services/swap-service/handler/chainflip-handler.js +25 -13
  44. package/services/swap-service/handler/kyber-handler.d.ts +0 -1
  45. package/services/swap-service/handler/kyber-handler.js +46 -33
  46. package/services/swap-service/handler/simpleswap-handler.d.ts +0 -1
  47. package/services/swap-service/handler/simpleswap-handler.js +80 -43
  48. package/services/swap-service/handler/uniswap-handler.js +6 -13
  49. package/services/swap-service/utils.d.ts +0 -13
  50. package/services/swap-service/utils.js +48 -34
  51. package/types/environment.d.ts +9 -0
  52. package/types/environment.js +13 -0
  53. package/utils/environment.d.ts +2 -0
  54. package/utils/environment.js +27 -1
  55. package/utils/fee/transfer.js +11 -3
@@ -6,52 +6,65 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
6
6
  import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
7
7
  import { estimateTxFee, getERC20Allowance, getERC20SpendingApprovalTx } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
8
8
  import { BasicTxErrorType, CommonStepType, DynamicSwapType, SwapErrorType, SwapFeeType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types';
9
- import { _reformatAddressWithChain, combineEthFee } from '@subwallet/extension-base/utils';
9
+ import { ProxyServiceRoute } from '@subwallet/extension-base/types/environment';
10
+ import { _reformatAddressWithChain, combineEthFee, fetchFromProxyService } from '@subwallet/extension-base/utils';
10
11
  import { getId } from '@subwallet/extension-base/utils/getId';
11
12
  import BigNumber from 'bignumber.js';
12
13
  import { _getChainNativeTokenSlug, _getContractAddressOfToken, _isNativeToken } from "../../chain-service/utils/index.js";
13
14
  import { calculateGasFeeParams } from "../../fee-service/utils/index.js";
14
15
  import { SwapBaseHandler } from "./base-handler.js";
15
- export const KYBER_CLIENT_ID = process.env.KYBER_CLIENT_ID || '';
16
- const kyberUrl = 'https://aggregator-api.kyberswap.com';
17
- async function buildTxForSwap(params, chain) {
16
+ async function buildTxForKyberSwap(params, chain) {
18
17
  const {
19
18
  recipient,
20
19
  sender,
21
20
  slippageTolerance
22
21
  } = params;
23
22
  let routeSummary = params.routeSummary;
23
+ console.log('routeSummary1', routeSummary);
24
24
  if (!routeSummary || !routeSummary.tokenIn || !routeSummary.tokenOut || !routeSummary.amountIn) {
25
- const queryParams = new URLSearchParams({
26
- tokenIn: routeSummary.tokenIn,
27
- tokenOut: routeSummary.tokenOut,
28
- amountIn: routeSummary.amountIn,
29
- gasInclude: 'true'
30
- });
31
- const url = `${kyberUrl}/${chain}/api/v1/routes?${queryParams.toString()}`;
32
- try {
33
- var _routeData$data;
34
- const res = await fetch(url, {
35
- method: 'GET',
36
- headers: {
37
- 'Content-Type': 'application/json',
38
- 'x-client-id': KYBER_CLIENT_ID,
39
- accept: 'application/json'
40
- }
41
- });
42
- const routeData = await res.json();
43
- if (!routeData.success || !((_routeData$data = routeData.data) !== null && _routeData$data !== void 0 && _routeData$data.routeSummary)) {
44
- return {
45
- error: new TransactionError(BasicTxErrorType.INTERNAL_ERROR, routeData.message)
46
- };
25
+ return {
26
+ error: new TransactionError(BasicTxErrorType.INTERNAL_ERROR, 'Invalid Route Summary')
27
+ };
28
+ }
29
+ const {
30
+ amountIn,
31
+ tokenIn,
32
+ tokenOut
33
+ } = routeSummary;
34
+ const queryParams = new URLSearchParams({
35
+ tokenIn,
36
+ tokenOut,
37
+ amountIn,
38
+ gasInclude: 'true'
39
+ });
40
+ const path = `/${chain}/api/v1/routes?${queryParams.toString()}`;
41
+ try {
42
+ var _routeData$data;
43
+ const res = await fetchFromProxyService(ProxyServiceRoute.KYBER, path, {
44
+ method: 'GET',
45
+ headers: {
46
+ 'Content-Type': 'application/json',
47
+ accept: 'application/json'
47
48
  }
48
- routeSummary = routeData.data.routeSummary;
49
- } catch (error) {
50
- console.error('Error:', error);
49
+ });
50
+ if (!res.ok) {
51
+ const errorText = await res.text();
51
52
  return {
52
- error: new TransactionError(BasicTxErrorType.INTERNAL_ERROR)
53
+ error: new TransactionError(BasicTxErrorType.INTERNAL_ERROR, `Fetch Kyber routes failed: ${errorText}`)
53
54
  };
54
55
  }
56
+ const routeData = await res.json();
57
+ if (!((_routeData$data = routeData.data) !== null && _routeData$data !== void 0 && _routeData$data.routeSummary)) {
58
+ return {
59
+ error: new TransactionError(BasicTxErrorType.INTERNAL_ERROR, routeData.message)
60
+ };
61
+ }
62
+ routeSummary = routeData.data.routeSummary;
63
+ } catch (error) {
64
+ console.error('Error:', error);
65
+ return {
66
+ error: new TransactionError(BasicTxErrorType.INTERNAL_ERROR, 'Unable to build Kyber swap transaction')
67
+ };
55
68
  }
56
69
  const body = {
57
70
  routeSummary,
@@ -61,12 +74,12 @@ async function buildTxForSwap(params, chain) {
61
74
  ignoreCappedSlippage: true,
62
75
  enableGasEstimation: true
63
76
  };
77
+ console.log('routeSummary2', routeSummary);
64
78
  try {
65
- const res = await fetch(`${kyberUrl}/${chain}/api/v1/route/build`, {
79
+ const res = await fetchFromProxyService(ProxyServiceRoute.KYBER, `/${chain}/api/v1/route/build`, {
66
80
  method: 'POST',
67
81
  headers: {
68
82
  'Content-Type': 'application/json',
69
- 'x-client-id': KYBER_CLIENT_ID,
70
83
  accept: 'application/json'
71
84
  },
72
85
  body: JSON.stringify(body)
@@ -272,7 +285,7 @@ export class KyberHandler {
272
285
  const recipient = _reformatAddressWithChain((_params$recipient = params.recipient) !== null && _params$recipient !== void 0 ? _params$recipient : sender, toChainInfo);
273
286
  const metadata = params.quote.metadata;
274
287
  const slippageTolerance = params.slippage * 10000;
275
- const rawTx = await buildTxForSwap({
288
+ const rawTx = await buildTxForKyberSwap({
276
289
  routeSummary: metadata.routeSummary,
277
290
  sender: params.address,
278
291
  recipient,
@@ -4,7 +4,6 @@ import { BaseStepDetail, CommonOptimalSwapPath, CommonStepFeeInfo, OptimalSwapPa
4
4
  import { BalanceService } from '../../balance-service';
5
5
  import { ChainService } from '../../chain-service';
6
6
  import { SwapBaseInterface } from './base-handler';
7
- export declare const simpleSwapApiKey: string;
8
7
  export declare class SimpleSwapHandler implements SwapBaseInterface {
9
8
  private swapBaseHandler;
10
9
  providerSlug: SwapProviderId;
@@ -4,50 +4,81 @@
4
4
  import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
5
5
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
6
6
  import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
7
- import { _getAssetDecimals, _getContractAddressOfToken, _isChainSubstrateCompatible, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
7
+ import { _getAssetDecimals, _getAssetSymbol, _getContractAddressOfToken, _isChainSubstrateCompatible, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
8
8
  import { BasicTxErrorType, CommonStepType, DynamicSwapType, SwapErrorType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types';
9
- import { _reformatAddressWithChain, formatNumber } from '@subwallet/extension-base/utils';
9
+ import { ProxyServiceRoute } from '@subwallet/extension-base/types/environment';
10
+ import { _reformatAddressWithChain, fetchFromProxyService, formatNumber } from '@subwallet/extension-base/utils';
10
11
  import { getId } from '@subwallet/extension-base/utils/getId';
11
12
  import BigN, { BigNumber } from 'bignumber.js';
12
13
  import { getERC20TransactionObject, getEVMTransactionObject } from "../../balance-service/transfer/smart-contract.js";
13
14
  import { createSubstrateExtrinsic } from "../../balance-service/transfer/token.js";
14
- import { SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING } from "../utils.js";
15
15
  import { SwapBaseHandler } from "./base-handler.js";
16
- const apiUrl = 'https://api.simpleswap.io';
17
- export const simpleSwapApiKey = process.env.SIMPLE_SWAP_API_KEY || '';
18
16
  const toBNString = (input, decimal) => {
19
17
  const raw = new BigNumber(input);
20
18
  return raw.shiftedBy(decimal).integerValue(BigNumber.ROUND_CEIL).toFixed();
21
19
  };
22
- const createSwapRequest = async params => {
23
- const fromDecimals = _getAssetDecimals(params.fromAsset);
24
- const toDecimals = _getAssetDecimals(params.toAsset);
25
- const formatedAmount = formatNumber(params.fromAmount, fromDecimals, s => s);
26
- const requestBody = {
27
- fixed: false,
28
- currency_from: params.fromSymbol,
29
- currency_to: params.toSymbol,
30
- amount: formatedAmount,
31
- // Convert to small number due to require of api
32
- address_to: params.receiver,
33
- extra_id_to: '',
34
- user_refund_address: params.sender,
35
- user_refund_extra_id: ''
36
- };
37
- const response = await fetch(`${apiUrl}/create_exchange?api_key=${simpleSwapApiKey}`, {
38
- method: 'POST',
39
- headers: {
40
- 'Content-Type': 'application/json',
41
- Accept: 'application/json'
42
- },
43
- body: JSON.stringify(requestBody)
44
- });
45
- const depositAddressResponse = await response.json();
46
- return {
47
- id: depositAddressResponse.id,
48
- addressFrom: depositAddressResponse.address_from,
49
- amountTo: toBNString(depositAddressResponse.amount_to, toDecimals)
50
- };
20
+ const buildTxForSimpleSwap = async params => {
21
+ try {
22
+ const {
23
+ fromAmount,
24
+ fromAsset,
25
+ fromSymbol,
26
+ metadata,
27
+ receiver,
28
+ sender,
29
+ toAsset,
30
+ toSymbol
31
+ } = params;
32
+ const fromDecimals = _getAssetDecimals(fromAsset);
33
+ const toDecimals = _getAssetDecimals(toAsset);
34
+ const formattedAmount = formatNumber(fromAmount, fromDecimals, s => s);
35
+ const requestBody = {
36
+ fixed: false,
37
+ tickerFrom: fromSymbol,
38
+ tickerTo: toSymbol,
39
+ amount: formattedAmount,
40
+ networkFrom: metadata.fromChainSymbol,
41
+ networkTo: metadata.toChainSymbol,
42
+ addressTo: receiver,
43
+ extraIdTo: '',
44
+ userRefundAddress: sender,
45
+ userRefundExtraId: ''
46
+ };
47
+ const response = await fetchFromProxyService(ProxyServiceRoute.SIMPLESWAP, '/exchanges', {
48
+ method: 'POST',
49
+ headers: {
50
+ 'Content-Type': 'application/json',
51
+ accept: 'application/json'
52
+ },
53
+ body: JSON.stringify(requestBody)
54
+ });
55
+ if (!response.ok) {
56
+ const errorText = await response.text();
57
+ return {
58
+ error: new TransactionError(BasicTxErrorType.INTERNAL_ERROR, `Unable to create simpleswap transaction: ${errorText}`)
59
+ };
60
+ }
61
+ const depositAddressResponse = await response.json();
62
+ const result = depositAddressResponse.result;
63
+ console.log('simpleswapID', result.id);
64
+ if (!(result !== null && result !== void 0 && result.id) || !result.addressFrom || !result.amountTo) {
65
+ return {
66
+ error: new TransactionError(BasicTxErrorType.INTERNAL_ERROR)
67
+ };
68
+ }
69
+ return {
70
+ data: {
71
+ id: result.id,
72
+ addressFrom: result.addressFrom,
73
+ amountTo: toBNString(result.amountTo, toDecimals)
74
+ }
75
+ };
76
+ } catch (err) {
77
+ console.error('Error:', err);
78
+ return {
79
+ error: new TransactionError(BasicTxErrorType.INTERNAL_ERROR)
80
+ };
81
+ }
51
82
  };
52
83
  export class SimpleSwapHandler {
53
84
  constructor(chainService, balanceService, feeService) {
@@ -131,25 +162,31 @@ export class SimpleSwapHandler {
131
162
  const chainType = _isChainSubstrateCompatible(chainInfo) ? ChainType.SUBSTRATE : ChainType.EVM;
132
163
  const sender = _reformatAddressWithChain(address, chainInfo);
133
164
  const receiver = _reformatAddressWithChain(recipient !== null && recipient !== void 0 ? recipient : sender, toChainInfo);
134
- const fromSymbol = SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING[fromAsset.slug];
135
- const toSymbol = SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING[toAsset.slug];
165
+ const fromSymbol = _getAssetSymbol(fromAsset).toLowerCase();
166
+ const toSymbol = _getAssetSymbol(toAsset).toLowerCase();
167
+ const metadata = quote.metadata;
136
168
  const {
137
169
  fromAmount
138
170
  } = quote;
139
- const {
140
- addressFrom,
141
- amountTo,
142
- id
143
- } = await createSwapRequest({
171
+ const result = await buildTxForSimpleSwap({
144
172
  fromSymbol,
145
173
  toSymbol,
146
174
  fromAmount,
147
175
  fromAsset,
148
176
  receiver,
149
177
  sender,
150
- toAsset
178
+ toAsset,
179
+ metadata
151
180
  });
152
- console.log('simpleswap data', id, addressFrom);
181
+ if (result.error) {
182
+ console.error('Simple swap error:', result.error);
183
+ throw result.error;
184
+ }
185
+ const {
186
+ addressFrom,
187
+ amountTo,
188
+ id
189
+ } = result.data;
153
190
  if (!id || id.length === 0 || !addressFrom || addressFrom.length === 0) {
154
191
  throw new SwapError(SwapErrorType.UNKNOWN);
155
192
  }
@@ -9,16 +9,13 @@ import { createAcrossBridgeExtrinsic } from '@subwallet/extension-base/services/
9
9
  import { getAcrossQuote } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
10
10
  import { DEFAULT_EXCESS_AMOUNT_WEIGHT, FEE_RATE_MULTIPLIER } from '@subwallet/extension-base/services/swap-service/utils';
11
11
  import { BasicTxErrorType, CommonStepType, DynamicSwapType, FeeOptionKey, SwapFeeType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types';
12
- import { _reformatAddressWithChain } from '@subwallet/extension-base/utils';
12
+ import { ProxyServiceRoute } from '@subwallet/extension-base/types/environment';
13
+ import { _reformatAddressWithChain, fetchFromProxyService } from '@subwallet/extension-base/utils';
13
14
  import { getId } from '@subwallet/extension-base/utils/getId';
14
15
  import BigNumber from 'bignumber.js';
15
16
  import { _getAssetOriginChain, _getChainNativeTokenSlug, _getContractAddressOfToken, _getEvmChainId, _isNativeToken } from "../../chain-service/utils/index.js";
16
17
  import { calculateGasFeeParams } from "../../fee-service/utils/index.js";
17
18
  import { SwapBaseHandler } from "./base-handler.js";
18
- const API_URL = 'https://trade-api.gateway.uniswap.org/v1';
19
- const headers = {
20
- 'x-api-key': process.env.UNISWAP_API_KEY || ''
21
- };
22
19
  async function fetchCheckApproval(request) {
23
20
  const {
24
21
  address,
@@ -49,10 +46,9 @@ async function fetchCheckApproval(request) {
49
46
  } else {
50
47
  return undefined;
51
48
  }
52
- const response = await fetch(`${API_URL}/check_approval`, {
49
+ const response = await fetchFromProxyService(ProxyServiceRoute.UNISWAP, '/check_approval', {
53
50
  method: 'POST',
54
51
  headers: {
55
- ...headers,
56
52
  'Content-Type': 'application/json'
57
53
  },
58
54
  body: JSON.stringify({
@@ -617,10 +613,9 @@ export class UniswapHandler {
617
613
  if (permitData) {
618
614
  body.permitData = permitData;
619
615
  }
620
- postTransactionResponse = await fetch(`${API_URL}/swap`, {
616
+ postTransactionResponse = await fetchFromProxyService(ProxyServiceRoute.UNISWAP, '/swap', {
621
617
  method: 'POST',
622
618
  headers: {
623
- ...headers,
624
619
  'Content-Type': 'application/json'
625
620
  },
626
621
  body: JSON.stringify(body)
@@ -631,10 +626,9 @@ export class UniswapHandler {
631
626
  const dutchQuote = quote;
632
627
  const submitSwapOrder = async () => {
633
628
  try {
634
- const res = await fetch(`${API_URL}/order`, {
629
+ const res = await fetchFromProxyService(ProxyServiceRoute.UNISWAP, '/order', {
635
630
  method: 'POST',
636
631
  headers: {
637
- ...headers,
638
632
  'Content-Type': 'application/json'
639
633
  },
640
634
  body: JSON.stringify({
@@ -675,10 +669,9 @@ export class UniswapHandler {
675
669
  const swapper = dutchQuote.orderInfo.swapper;
676
670
  return retryGetUniswapTx(async () => {
677
671
  try {
678
- const response = await fetch(`${API_URL}/orders?orderId=${orderId}&swapper=${swapper}`, {
672
+ const response = await fetchFromProxyService(ProxyServiceRoute.UNISWAP, `/orders?orderId=${orderId}&swapper=${swapper}`, {
679
673
  method: 'GET',
680
674
  headers: {
681
- ...headers,
682
675
  'Content-Type': 'application/json'
683
676
  }
684
677
  });
@@ -13,19 +13,6 @@ export declare function getSwapAlternativeAsset(swapPair: SwapPair): string | un
13
13
  export declare function getSwapAltToken(chainAsset: _ChainAsset): string | undefined;
14
14
  export declare function calculateSwapRate(fromAmount: string, toAmount: string, fromAsset: _ChainAsset, toAsset: _ChainAsset): number;
15
15
  export declare function convertSwapRate(rate: string, fromAsset: _ChainAsset, toAsset: _ChainAsset): number;
16
- export declare function getChainflipOptions(isTestnet: boolean): {
17
- network: string;
18
- broker?: undefined;
19
- } | {
20
- network: string;
21
- broker: {
22
- url: string;
23
- };
24
- };
25
- export declare function getChainflipBroker(isTestnet: boolean): {
26
- url: string;
27
- };
28
- export declare function getChainflipSwap(isTestnet: boolean): string;
29
16
  export declare function getBridgeStep(from: string, to: string): DynamicSwapAction;
30
17
  export declare function getSwapStep(from: string, to: string): DynamicSwapAction;
31
18
  export declare function findBridgeTransitDestination(assetRefMap: Record<string, _AssetRef>, fromToken: _ChainAsset, toToken: _ChainAsset): string | undefined;
@@ -4,13 +4,14 @@
4
4
  import { COMMON_ASSETS, COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
5
5
  import { _AssetRefPath } from '@subwallet/chain-list/types';
6
6
  import { _getAssetDecimals, _getAssetOriginChain, _getOriginChainOfAsset, _parseAssetRefKey } from '@subwallet/extension-base/services/chain-service/utils';
7
- import { CHAINFLIP_BROKER_API } from '@subwallet/extension-base/services/swap-service/handler/chainflip-handler';
8
7
  import { CommonStepType, DynamicSwapType, SwapStepType } from '@subwallet/extension-base/types';
9
8
  import { SwapProviderId } from '@subwallet/extension-base/types/swap';
10
9
  import BigN from 'bignumber.js';
11
10
  export const CHAIN_FLIP_TESTNET_EXPLORER = 'https://blocks-perseverance.chainflip.io';
12
11
  export const CHAIN_FLIP_MAINNET_EXPLORER = 'https://scan.chainflip.io';
13
12
  export const SIMPLE_SWAP_EXPLORER = 'https://simpleswap.io';
13
+
14
+ // Deprecated
14
15
  export const SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING = {
15
16
  'bittensor-NATIVE-TAO': 'tao',
16
17
  [COMMON_ASSETS.ETH]: 'eth',
@@ -68,39 +69,52 @@ export function convertSwapRate(rate, fromAsset, toAsset) {
68
69
  const bnRate = BigN(rate);
69
70
  return bnRate.times(10 ** decimalDiff).pow(-1).toNumber();
70
71
  }
71
- export function getChainflipOptions(isTestnet) {
72
- if (isTestnet) {
73
- return {
74
- network: getChainflipNetwork(isTestnet)
75
- };
76
- }
77
- return {
78
- network: getChainflipNetwork(isTestnet),
79
- broker: getChainflipBroker(isTestnet)
80
- };
81
- }
82
- function getChainflipNetwork(isTestnet) {
83
- return isTestnet ? 'perseverance' : 'mainnet';
84
- }
85
- export function getChainflipBroker(isTestnet) {
86
- // noted: currently not use testnet broker
87
- if (isTestnet) {
88
- return {
89
- url: `https://perseverance.chainflip-broker.io/rpc/${CHAINFLIP_BROKER_API}`
90
- };
91
- } else {
92
- return {
93
- url: `https://chainflip-broker.io/rpc/${CHAINFLIP_BROKER_API}`
94
- };
95
- }
96
- }
97
- export function getChainflipSwap(isTestnet) {
98
- if (isTestnet) {
99
- return `https://perseverance.chainflip-broker.io/swap?apikey=${CHAINFLIP_BROKER_API}`;
100
- } else {
101
- return `https://chainflip-broker.io/swap?apikey=${CHAINFLIP_BROKER_API}`;
102
- }
103
- }
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
+
104
118
  export function getBridgeStep(from, to) {
105
119
  return {
106
120
  action: DynamicSwapType.BRIDGE,
@@ -0,0 +1,9 @@
1
+ export declare enum ProxyServiceRoute {
2
+ BITTENSOR = "/bittensor",
3
+ CHAINFLIP = "/chainflip",
4
+ KYBER = "/kyber",
5
+ SIMPLESWAP = "/simpleswap",
6
+ UNISWAP = "/uniswap",
7
+ CARDANO = "/cardano",
8
+ PARASPELL = "/paraspell"
9
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export let ProxyServiceRoute;
5
+ (function (ProxyServiceRoute) {
6
+ ProxyServiceRoute["BITTENSOR"] = "/bittensor";
7
+ ProxyServiceRoute["CHAINFLIP"] = "/chainflip";
8
+ ProxyServiceRoute["KYBER"] = "/kyber";
9
+ ProxyServiceRoute["SIMPLESWAP"] = "/simpleswap";
10
+ ProxyServiceRoute["UNISWAP"] = "/uniswap";
11
+ ProxyServiceRoute["CARDANO"] = "/cardano";
12
+ ProxyServiceRoute["PARASPELL"] = "/paraspell";
13
+ })(ProxyServiceRoute || (ProxyServiceRoute = {}));
@@ -1,5 +1,6 @@
1
1
  import Bowser from 'bowser';
2
2
  import { EnvironmentSupport, RuntimeEnvironmentInfo, TargetEnvironment } from '../background/KoniTypes';
3
+ import { ProxyServiceRoute } from '../types/environment';
3
4
  export declare const RuntimeInfo: RuntimeEnvironmentInfo;
4
5
  export declare const BowserParser: Bowser.Parser.Parser;
5
6
  export declare const isBrave: boolean;
@@ -16,3 +17,4 @@ export declare const targetIsExtension: boolean;
16
17
  export declare const targetIsWeb: boolean;
17
18
  export declare const targetIsMobile: boolean;
18
19
  export declare const MODULE_SUPPORT: EnvironmentSupport;
20
+ export declare function fetchFromProxyService(service: ProxyServiceRoute, path: string, options: RequestInit, isTestnet?: boolean): Promise<Response>;
@@ -5,6 +5,7 @@ var _navigator3;
5
5
  import { isSupportWindow } from '@subwallet/extension-base/utils/mv3';
6
6
  import Bowser from 'bowser';
7
7
  import { RuntimeEnvironment } from "../background/KoniTypes.js";
8
+ import { SW_EXTERNAL_SERVICES_API } from "../constants/index.js";
8
9
  function detectRuntimeEnvironment() {
9
10
  if (isSupportWindow && typeof document !== 'undefined') {
10
11
  var _navigator, _window$location, _window$location2;
@@ -84,4 +85,29 @@ export const targetIsWeb = TARGET_ENV === 'webapp';
84
85
  export const targetIsMobile = TARGET_ENV === 'mobile';
85
86
  export const MODULE_SUPPORT = {
86
87
  MANTA_ZK: false
87
- };
88
+ };
89
+ var HEADERS;
90
+ (function (HEADERS) {
91
+ HEADERS["PLATFORM"] = "Platform";
92
+ })(HEADERS || (HEADERS = {}));
93
+ function formatExternalServiceApi(url, isTestnet) {
94
+ if (isTestnet === true) {
95
+ return `${url}/testnet`;
96
+ }
97
+ if (isTestnet === false) {
98
+ return `${url}/mainnet`;
99
+ }
100
+ return url;
101
+ }
102
+ export async function fetchFromProxyService(service, path, options, isTestnet) {
103
+ const baseUrl = formatExternalServiceApi(`${SW_EXTERNAL_SERVICES_API}${service}`, isTestnet);
104
+ const url = `${baseUrl}${path}`;
105
+ const headers = {
106
+ [HEADERS.PLATFORM]: TARGET_ENV,
107
+ ...(options.headers || {})
108
+ };
109
+ return fetch(url, {
110
+ ...options,
111
+ headers
112
+ });
113
+ }
@@ -8,11 +8,12 @@ import { createCardanoTransaction } from '@subwallet/extension-base/services/bal
8
8
  import { getERC20TransactionObject, getEVMTransactionObject } from '@subwallet/extension-base/services/balance-service/transfer/smart-contract';
9
9
  import { createSubstrateExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
10
10
  import { createTonTransaction } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
11
- import { createAcrossBridgeExtrinsic, createAvailBridgeExtrinsicFromAvail, createAvailBridgeTxFromEth, createPolygonBridgeExtrinsic, createSnowBridgeExtrinsic, createXcmExtrinsicV2, dryRunXcmExtrinsicV2 } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
11
+ import { createAcrossBridgeExtrinsic, createAvailBridgeExtrinsicFromAvail, createAvailBridgeTxFromEth, createPolygonBridgeExtrinsic, createSnowBridgeExtrinsic, createXcmExtrinsicV2 } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
12
12
  import { _isAcrossChainBridge, _isAcrossTestnetBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
13
13
  import { isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
14
14
  import { _isPolygonChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
15
15
  import { _isPosChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
16
+ import { estimateXcmFee } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
16
17
  import { _getAssetDecimals, _getContractAddressOfToken, _isChainCardanoCompatible, _isChainEvmCompatible, _isChainTonCompatible, _isLocalToken, _isNativeToken, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByCardano, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
17
18
  import { calculateToAmountByReservePool, FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE } from '@subwallet/extension-base/services/fee-service/utils';
18
19
  import { getHydrationRate } from '@subwallet/extension-base/services/fee-service/utils/tokenPayFee';
@@ -369,8 +370,15 @@ export const calculateXcmMaxTransferable = async (id, request, freeBalance, fee)
369
370
  } else if (feeChainType === 'substrate') {
370
371
  // Calculate fee for substrate transaction
371
372
  if (isSubstrateXcm) {
372
- const estimatedFeeByDryRun = await dryRunXcmExtrinsicV2(params);
373
- estimatedFee = estimatedFeeByDryRun.fee || '0';
373
+ const xcmFeeInfo = await estimateXcmFee({
374
+ fromChainInfo: params.originChain,
375
+ fromTokenInfo: params.originTokenInfo,
376
+ toChainInfo: params.destinationChain,
377
+ recipient: params.recipient,
378
+ sender: params.sender,
379
+ value: params.sendingValue
380
+ });
381
+ estimatedFee = (xcmFeeInfo === null || xcmFeeInfo === void 0 ? void 0 : xcmFeeInfo.origin.fee) || '0';
374
382
  } else {
375
383
  try {
376
384
  var _paymentInfo$partialF2;