@subwallet/extension-base 1.3.10-0 → 1.3.11-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.
- package/background/errors/SwapError.js +5 -0
- package/cjs/background/errors/SwapError.js +5 -0
- package/cjs/core/logic-validation/swap.js +27 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/swap-service/handler/chainflip-handler.js +0 -1
- package/cjs/services/swap-service/handler/simpleswap-handler.js +444 -0
- package/cjs/services/swap-service/index.js +15 -3
- package/cjs/services/swap-service/utils.js +13 -2
- package/cjs/services/transaction-service/index.js +14 -10
- package/cjs/services/transaction-service/utils.js +9 -1
- package/cjs/types/swap/index.js +7 -3
- package/cjs/utils/number.js +11 -6
- package/core/logic-validation/swap.d.ts +2 -1
- package/core/logic-validation/swap.js +26 -0
- package/package.json +11 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/utils/patch.js +1 -1
- package/services/swap-service/handler/chainflip-handler.js +0 -1
- package/services/swap-service/handler/simpleswap-handler.d.ts +24 -0
- package/services/swap-service/handler/simpleswap-handler.js +434 -0
- package/services/swap-service/index.d.ts +2 -1
- package/services/swap-service/index.js +13 -2
- package/services/swap-service/utils.d.ts +2 -0
- package/services/swap-service/utils.js +10 -1
- package/services/transaction-service/index.js +15 -11
- package/services/transaction-service/utils.d.ts +2 -1
- package/services/transaction-service/utils.js +9 -2
- package/types/swap/index.d.ts +15 -3
- package/types/swap/index.js +5 -2
- package/utils/number.d.ts +9 -1
- package/utils/number.js +10 -4
|
@@ -2,8 +2,9 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
|
|
|
2
2
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
3
3
|
import { ServiceStatus, ServiceWithProcessInterface, StoppableServiceInterface } from '@subwallet/extension-base/services/base/types';
|
|
4
4
|
import { CommonOptimalPath } from '@subwallet/extension-base/types/service-base';
|
|
5
|
-
import { OptimalSwapPathParams, SwapPair, SwapQuoteResponse, SwapRequest, SwapRequestResult, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types/swap';
|
|
5
|
+
import { OptimalSwapPathParams, SwapPair, SwapProviderId, SwapQuoteResponse, SwapRequest, SwapRequestResult, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types/swap';
|
|
6
6
|
import { PromiseHandler } from '@subwallet/extension-base/utils';
|
|
7
|
+
export declare const _isChainSupportedByProvider: (providerSlug: SwapProviderId, chain: string) => boolean;
|
|
7
8
|
export declare class SwapService implements ServiceWithProcessInterface, StoppableServiceInterface {
|
|
8
9
|
protected readonly state: KoniState;
|
|
9
10
|
private eventService;
|
|
@@ -13,6 +13,11 @@ import { DEFAULT_FIRST_STEP, MOCK_STEP_FEE } from '@subwallet/extension-base/typ
|
|
|
13
13
|
import { _SUPPORTED_SWAP_PROVIDERS, SwapErrorType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
|
|
14
14
|
import { createPromiseHandler } from '@subwallet/extension-base/utils';
|
|
15
15
|
import { BehaviorSubject } from 'rxjs';
|
|
16
|
+
import { SimpleSwapHandler } from "./handler/simpleswap-handler.js";
|
|
17
|
+
export const _isChainSupportedByProvider = (providerSlug, chain) => {
|
|
18
|
+
const supportedChains = _PROVIDER_TO_SUPPORTED_PAIR_MAP[providerSlug];
|
|
19
|
+
return supportedChains ? supportedChains.includes(chain) : false;
|
|
20
|
+
};
|
|
16
21
|
export class SwapService {
|
|
17
22
|
swapPairSubject = new BehaviorSubject([]);
|
|
18
23
|
handlers = {};
|
|
@@ -29,7 +34,7 @@ export class SwapService {
|
|
|
29
34
|
const swappingSrcChain = this.chainService.getAssetBySlug(request.pair.from).originChain;
|
|
30
35
|
await Promise.all(Object.values(this.handlers).map(async handler => {
|
|
31
36
|
// temporary solution to reduce number of requests to providers, will work as long as there's only 1 provider for 1 chain
|
|
32
|
-
if (!
|
|
37
|
+
if (!_isChainSupportedByProvider(handler.providerSlug, swappingSrcChain)) {
|
|
33
38
|
return;
|
|
34
39
|
}
|
|
35
40
|
if (handler.init && handler.isReady === false) {
|
|
@@ -116,7 +121,10 @@ export class SwapService {
|
|
|
116
121
|
quoteError = (preferredErrorResp === null || preferredErrorResp === void 0 ? void 0 : preferredErrorResp.error) || (defaultErrorResp === null || defaultErrorResp === void 0 ? void 0 : defaultErrorResp.error);
|
|
117
122
|
} else {
|
|
118
123
|
var _selectedQuote;
|
|
119
|
-
selectedQuote = availableQuotes
|
|
124
|
+
selectedQuote = availableQuotes.find(quote => {
|
|
125
|
+
var _request$currentQuote;
|
|
126
|
+
return quote.provider.id === ((_request$currentQuote = request.currentQuote) === null || _request$currentQuote === void 0 ? void 0 : _request$currentQuote.id);
|
|
127
|
+
}) || availableQuotes[0];
|
|
120
128
|
aliveUntil = ((_selectedQuote = selectedQuote) === null || _selectedQuote === void 0 ? void 0 : _selectedQuote.aliveUntil) || +Date.now() + SWAP_QUOTE_TIMEOUT_MAP.default;
|
|
121
129
|
}
|
|
122
130
|
return {
|
|
@@ -150,6 +158,9 @@ export class SwapService {
|
|
|
150
158
|
case SwapProviderId.ROCOCO_ASSET_HUB:
|
|
151
159
|
this.handlers[providerId] = new AssetHubSwapHandler(this.chainService, this.state.balanceService, 'rococo_assethub');
|
|
152
160
|
break;
|
|
161
|
+
case SwapProviderId.SIMPLE_SWAP:
|
|
162
|
+
this.handlers[providerId] = new SimpleSwapHandler(this.chainService, this.state.balanceService);
|
|
163
|
+
break;
|
|
153
164
|
default:
|
|
154
165
|
throw new Error('Unsupported provider');
|
|
155
166
|
}
|
|
@@ -3,10 +3,12 @@ import { _ChainAsset } from '@subwallet/chain-list/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
|
+
export declare const SIMPLE_SWAP_EXPLORER = "https://simpleswap.io";
|
|
6
7
|
export declare const CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING: Record<string, Chain>;
|
|
7
8
|
export declare const CHAIN_FLIP_SUPPORTED_TESTNET_MAPPING: Record<string, Chain>;
|
|
8
9
|
export declare const CHAIN_FLIP_SUPPORTED_MAINNET_ASSET_MAPPING: Record<string, Asset>;
|
|
9
10
|
export declare const CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING: Record<string, Asset>;
|
|
11
|
+
export declare const SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING: Record<string, string>;
|
|
10
12
|
export declare const SWAP_QUOTE_TIMEOUT_MAP: Record<string, number>;
|
|
11
13
|
export declare const _PROVIDER_TO_SUPPORTED_PAIR_MAP: Record<string, string[]>;
|
|
12
14
|
export declare function getSwapAlternativeAsset(swapPair: SwapPair): string | undefined;
|
|
@@ -9,6 +9,7 @@ import { SwapProviderId } from '@subwallet/extension-base/types/swap';
|
|
|
9
9
|
import BigN from 'bignumber.js';
|
|
10
10
|
export const CHAIN_FLIP_TESTNET_EXPLORER = 'https://blocks-perseverance.chainflip.io';
|
|
11
11
|
export const CHAIN_FLIP_MAINNET_EXPLORER = 'https://scan.chainflip.io';
|
|
12
|
+
export const SIMPLE_SWAP_EXPLORER = 'https://simpleswap.io';
|
|
12
13
|
export const CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING = {
|
|
13
14
|
[COMMON_CHAIN_SLUGS.POLKADOT]: Chains.Polkadot,
|
|
14
15
|
[COMMON_CHAIN_SLUGS.ETHEREUM]: Chains.Ethereum,
|
|
@@ -29,6 +30,13 @@ export const CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING = {
|
|
|
29
30
|
[COMMON_ASSETS.ETH_SEPOLIA]: Assets.ETH,
|
|
30
31
|
[COMMON_ASSETS.USDC_SEPOLIA]: Assets.USDC
|
|
31
32
|
};
|
|
33
|
+
export const SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING = {
|
|
34
|
+
'bittensor-NATIVE-TAO': 'tao',
|
|
35
|
+
[COMMON_ASSETS.ETH]: 'eth',
|
|
36
|
+
[COMMON_ASSETS.DOT]: 'dot',
|
|
37
|
+
[COMMON_ASSETS.USDC_ETHEREUM]: 'usdc',
|
|
38
|
+
[COMMON_ASSETS.USDT_ETHEREUM]: 'usdterc20'
|
|
39
|
+
};
|
|
32
40
|
export const SWAP_QUOTE_TIMEOUT_MAP = {
|
|
33
41
|
// in milliseconds
|
|
34
42
|
default: 30000,
|
|
@@ -42,7 +50,8 @@ export const _PROVIDER_TO_SUPPORTED_PAIR_MAP = {
|
|
|
42
50
|
[SwapProviderId.CHAIN_FLIP_TESTNET]: [COMMON_CHAIN_SLUGS.CHAINFLIP_POLKADOT, COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA],
|
|
43
51
|
[SwapProviderId.POLKADOT_ASSET_HUB]: [COMMON_CHAIN_SLUGS.POLKADOT_ASSET_HUB],
|
|
44
52
|
[SwapProviderId.KUSAMA_ASSET_HUB]: [COMMON_CHAIN_SLUGS.KUSAMA_ASSET_HUB],
|
|
45
|
-
[SwapProviderId.ROCOCO_ASSET_HUB]: [COMMON_CHAIN_SLUGS.ROCOCO_ASSET_HUB]
|
|
53
|
+
[SwapProviderId.ROCOCO_ASSET_HUB]: [COMMON_CHAIN_SLUGS.ROCOCO_ASSET_HUB],
|
|
54
|
+
[SwapProviderId.SIMPLE_SWAP]: ['bittensor', COMMON_CHAIN_SLUGS.ETHEREUM, COMMON_CHAIN_SLUGS.POLKADOT]
|
|
46
55
|
};
|
|
47
56
|
export function getSwapAlternativeAsset(swapPair) {
|
|
48
57
|
var _swapPair$metadata;
|
|
@@ -15,7 +15,7 @@ import { getBaseTransactionInfo, getTransactionId, isSubstrateTransaction, isTon
|
|
|
15
15
|
import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
|
|
16
16
|
import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
17
17
|
import { BasicTxErrorType, YieldPoolType } from '@subwallet/extension-base/types';
|
|
18
|
-
import {
|
|
18
|
+
import { anyNumberToBN, pairToAccount, reformatAddress } from '@subwallet/extension-base/utils';
|
|
19
19
|
import { mergeTransactionAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
|
|
20
20
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
21
21
|
import { BN_ZERO } from '@subwallet/extension-base/utils/number';
|
|
@@ -1047,7 +1047,7 @@ export default class TransactionService {
|
|
|
1047
1047
|
}
|
|
1048
1048
|
return emitter;
|
|
1049
1049
|
}
|
|
1050
|
-
|
|
1050
|
+
signAndSendSubstrateTransaction({
|
|
1051
1051
|
address,
|
|
1052
1052
|
chain,
|
|
1053
1053
|
id,
|
|
@@ -1062,8 +1062,9 @@ export default class TransactionService {
|
|
|
1062
1062
|
extrinsicHash: id
|
|
1063
1063
|
};
|
|
1064
1064
|
const extrinsic = transaction;
|
|
1065
|
-
const registry = extrinsic.registry;
|
|
1066
|
-
const signedExtensions = registry.signedExtensions;
|
|
1065
|
+
// const registry = extrinsic.registry;
|
|
1066
|
+
// const signedExtensions = registry.signedExtensions;
|
|
1067
|
+
|
|
1067
1068
|
const signerOption = {
|
|
1068
1069
|
signer: {
|
|
1069
1070
|
signPayload: async payload => {
|
|
@@ -1080,13 +1081,16 @@ export default class TransactionService {
|
|
|
1080
1081
|
},
|
|
1081
1082
|
withSignedTransaction: true
|
|
1082
1083
|
};
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1084
|
+
|
|
1085
|
+
// if (_isRuntimeUpdated(signedExtensions)) {
|
|
1086
|
+
// const metadataHash = await this.state.chainService.calculateMetadataHash(chain);
|
|
1087
|
+
//
|
|
1088
|
+
// if (metadataHash) {
|
|
1089
|
+
// signerOption.mode = 1;
|
|
1090
|
+
// signerOption.metadataHash = metadataHash;
|
|
1091
|
+
// }
|
|
1092
|
+
// }
|
|
1093
|
+
|
|
1090
1094
|
extrinsic.signAsync(address, signerOption).then(async rs => {
|
|
1091
1095
|
// Emit signed event
|
|
1092
1096
|
emitter.emit('signed', eventData);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { ExtrinsicDataTypeMap, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
-
import { ChainflipSwapTxData } from '@subwallet/extension-base/types/swap';
|
|
3
|
+
import { ChainflipSwapTxData, SimpleSwapTxData } from '@subwallet/extension-base/types/swap';
|
|
4
4
|
export declare function parseTransactionData<T extends ExtrinsicType>(data: unknown): ExtrinsicDataTypeMap[T];
|
|
5
5
|
export declare function getExplorerLink(chainInfo: _ChainInfo, value: string, type: 'account' | 'tx'): string | undefined;
|
|
6
6
|
export declare function getChainflipExplorerLink(data: ChainflipSwapTxData, chainInfo: _ChainInfo): string;
|
|
7
|
+
export declare function getSimpleSwapExplorerLink(data: SimpleSwapTxData): string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { _getBlockExplorerFromChain, _isChainTestNet, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
|
-
import { CHAIN_FLIP_MAINNET_EXPLORER, CHAIN_FLIP_TESTNET_EXPLORER } from '@subwallet/extension-base/services/swap-service/utils';
|
|
5
|
+
import { CHAIN_FLIP_MAINNET_EXPLORER, CHAIN_FLIP_TESTNET_EXPLORER, SIMPLE_SWAP_EXPLORER } from '@subwallet/extension-base/services/swap-service/utils';
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
export function parseTransactionData(data) {
|
|
8
8
|
// @ts-ignore
|
|
@@ -46,7 +46,7 @@ function getBlockExplorerTxRoute(chainInfo) {
|
|
|
46
46
|
if (['aventus', 'deeper_network'].includes(chainInfo.slug)) {
|
|
47
47
|
return 'transaction';
|
|
48
48
|
}
|
|
49
|
-
if (['invarch'].includes(chainInfo.slug)) {
|
|
49
|
+
if (['invarch', 'tangle'].includes(chainInfo.slug)) {
|
|
50
50
|
return '#/extrinsics';
|
|
51
51
|
}
|
|
52
52
|
return 'extrinsic';
|
|
@@ -62,6 +62,9 @@ export function getExplorerLink(chainInfo, value, type) {
|
|
|
62
62
|
return undefined;
|
|
63
63
|
}
|
|
64
64
|
const route = getBlockExplorerTxRoute(chainInfo);
|
|
65
|
+
if (chainInfo.slug === 'tangle') {
|
|
66
|
+
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${value}${route}/${value}`;
|
|
67
|
+
}
|
|
65
68
|
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
|
|
66
69
|
}
|
|
67
70
|
return undefined;
|
|
@@ -69,4 +72,8 @@ export function getExplorerLink(chainInfo, value, type) {
|
|
|
69
72
|
export function getChainflipExplorerLink(data, chainInfo) {
|
|
70
73
|
const chainflipDomain = _isChainTestNet(chainInfo) ? CHAIN_FLIP_TESTNET_EXPLORER : CHAIN_FLIP_MAINNET_EXPLORER;
|
|
71
74
|
return `${chainflipDomain}/channels/${data.depositChannelId}`;
|
|
75
|
+
}
|
|
76
|
+
export function getSimpleSwapExplorerLink(data) {
|
|
77
|
+
const simpleswapDomain = SIMPLE_SWAP_EXPLORER;
|
|
78
|
+
return `${simpleswapDomain}/exchange?id=${data.id}`;
|
|
72
79
|
}
|
package/types/swap/index.d.ts
CHANGED
|
@@ -40,7 +40,8 @@ export declare enum SwapErrorType {
|
|
|
40
40
|
SWAP_NOT_ENOUGH_BALANCE = "SWAP_NOT_ENOUGH_BALANCE",
|
|
41
41
|
NOT_ENOUGH_LIQUIDITY = "NOT_ENOUGH_LIQUIDITY",
|
|
42
42
|
MAKE_POOL_NOT_ENOUGH_EXISTENTIAL_DEPOSIT = "MAKE_POOL_NOT_ENOUGH_EXISTENTIAL_DEPOSIT",
|
|
43
|
-
AMOUNT_CANNOT_BE_ZERO = "AMOUNT_CANNOT_BE_ZERO"
|
|
43
|
+
AMOUNT_CANNOT_BE_ZERO = "AMOUNT_CANNOT_BE_ZERO",
|
|
44
|
+
NOT_MEET_MIN_EXPECTED = "NOT_MEET_MIN_EXPECTED"
|
|
44
45
|
}
|
|
45
46
|
export declare enum SwapStepType {
|
|
46
47
|
SWAP = "SWAP"
|
|
@@ -52,7 +53,8 @@ export declare enum SwapProviderId {
|
|
|
52
53
|
HYDRADX_TESTNET = "HYDRADX_TESTNET",
|
|
53
54
|
POLKADOT_ASSET_HUB = "POLKADOT_ASSET_HUB",
|
|
54
55
|
KUSAMA_ASSET_HUB = "KUSAMA_ASSET_HUB",
|
|
55
|
-
ROCOCO_ASSET_HUB = "ROCOCO_ASSET_HUB"
|
|
56
|
+
ROCOCO_ASSET_HUB = "ROCOCO_ASSET_HUB",
|
|
57
|
+
SIMPLE_SWAP = "SIMPLE_SWAP"
|
|
56
58
|
}
|
|
57
59
|
export declare const _SUPPORTED_SWAP_PROVIDERS: SwapProviderId[];
|
|
58
60
|
export interface SwapProvider {
|
|
@@ -65,7 +67,7 @@ export declare enum SwapFeeType {
|
|
|
65
67
|
NETWORK_FEE = "NETWORK_FEE",
|
|
66
68
|
WALLET_FEE = "WALLET_FEE"
|
|
67
69
|
}
|
|
68
|
-
export declare type SwapTxData = ChainflipSwapTxData | HydradxSwapTxData;
|
|
70
|
+
export declare type SwapTxData = ChainflipSwapTxData | HydradxSwapTxData | SimpleSwapTxData;
|
|
69
71
|
export interface SwapBaseTxData {
|
|
70
72
|
provider: SwapProvider;
|
|
71
73
|
quote: SwapQuote;
|
|
@@ -79,6 +81,9 @@ export interface ChainflipSwapTxData extends SwapBaseTxData {
|
|
|
79
81
|
depositAddress: string;
|
|
80
82
|
estimatedDepositChannelExpiryTime?: number;
|
|
81
83
|
}
|
|
84
|
+
export interface SimpleSwapTxData extends SwapBaseTxData {
|
|
85
|
+
id: string;
|
|
86
|
+
}
|
|
82
87
|
export interface HydradxSwapTxData extends SwapBaseTxData {
|
|
83
88
|
txHex: string;
|
|
84
89
|
}
|
|
@@ -98,6 +103,11 @@ export interface AssetHubPreValidationMetadata {
|
|
|
98
103
|
quoteRate: string;
|
|
99
104
|
priceImpactPct?: string;
|
|
100
105
|
}
|
|
106
|
+
export interface SimpleSwapValidationMetadata {
|
|
107
|
+
minSwap: AmountData;
|
|
108
|
+
maxSwap: AmountData;
|
|
109
|
+
chain: _ChainInfo;
|
|
110
|
+
}
|
|
101
111
|
export interface QuoteAskResponse {
|
|
102
112
|
quote?: SwapQuote;
|
|
103
113
|
error?: SwapError;
|
|
@@ -109,6 +119,7 @@ export interface SwapRequest {
|
|
|
109
119
|
slippage: number;
|
|
110
120
|
recipient?: string;
|
|
111
121
|
feeToken?: string;
|
|
122
|
+
currentQuote?: SwapProvider;
|
|
112
123
|
}
|
|
113
124
|
export interface SwapRequestResult {
|
|
114
125
|
process: CommonOptimalPath;
|
|
@@ -158,3 +169,4 @@ export interface SlippageType {
|
|
|
158
169
|
isCustomType: boolean;
|
|
159
170
|
}
|
|
160
171
|
export declare const CHAINFLIP_SLIPPAGE = 0.02;
|
|
172
|
+
export declare const SIMPLE_SWAP_SLIPPAGE = 0.05;
|
package/types/swap/index.js
CHANGED
|
@@ -16,6 +16,7 @@ export let SwapErrorType;
|
|
|
16
16
|
SwapErrorType["NOT_ENOUGH_LIQUIDITY"] = "NOT_ENOUGH_LIQUIDITY";
|
|
17
17
|
SwapErrorType["MAKE_POOL_NOT_ENOUGH_EXISTENTIAL_DEPOSIT"] = "MAKE_POOL_NOT_ENOUGH_EXISTENTIAL_DEPOSIT";
|
|
18
18
|
SwapErrorType["AMOUNT_CANNOT_BE_ZERO"] = "AMOUNT_CANNOT_BE_ZERO";
|
|
19
|
+
SwapErrorType["NOT_MEET_MIN_EXPECTED"] = "NOT_MEET_MIN_EXPECTED";
|
|
19
20
|
})(SwapErrorType || (SwapErrorType = {}));
|
|
20
21
|
export let SwapStepType;
|
|
21
22
|
(function (SwapStepType) {
|
|
@@ -30,8 +31,9 @@ export let SwapProviderId;
|
|
|
30
31
|
SwapProviderId["POLKADOT_ASSET_HUB"] = "POLKADOT_ASSET_HUB";
|
|
31
32
|
SwapProviderId["KUSAMA_ASSET_HUB"] = "KUSAMA_ASSET_HUB";
|
|
32
33
|
SwapProviderId["ROCOCO_ASSET_HUB"] = "ROCOCO_ASSET_HUB";
|
|
34
|
+
SwapProviderId["SIMPLE_SWAP"] = "SIMPLE_SWAP";
|
|
33
35
|
})(SwapProviderId || (SwapProviderId = {}));
|
|
34
|
-
export const _SUPPORTED_SWAP_PROVIDERS = [SwapProviderId.CHAIN_FLIP_TESTNET, SwapProviderId.CHAIN_FLIP_MAINNET, SwapProviderId.HYDRADX_MAINNET, SwapProviderId.HYDRADX_TESTNET, SwapProviderId.POLKADOT_ASSET_HUB, SwapProviderId.KUSAMA_ASSET_HUB, SwapProviderId.ROCOCO_ASSET_HUB];
|
|
36
|
+
export const _SUPPORTED_SWAP_PROVIDERS = [SwapProviderId.CHAIN_FLIP_TESTNET, SwapProviderId.CHAIN_FLIP_MAINNET, SwapProviderId.HYDRADX_MAINNET, SwapProviderId.HYDRADX_TESTNET, SwapProviderId.POLKADOT_ASSET_HUB, SwapProviderId.KUSAMA_ASSET_HUB, SwapProviderId.ROCOCO_ASSET_HUB, SwapProviderId.SIMPLE_SWAP];
|
|
35
37
|
// process handling
|
|
36
38
|
export let SwapFeeType;
|
|
37
39
|
(function (SwapFeeType) {
|
|
@@ -39,4 +41,5 @@ export let SwapFeeType;
|
|
|
39
41
|
SwapFeeType["NETWORK_FEE"] = "NETWORK_FEE";
|
|
40
42
|
SwapFeeType["WALLET_FEE"] = "WALLET_FEE";
|
|
41
43
|
})(SwapFeeType || (SwapFeeType = {}));
|
|
42
|
-
export const CHAINFLIP_SLIPPAGE = 0.02; // Example: 0.01 for 1%
|
|
44
|
+
export const CHAINFLIP_SLIPPAGE = 0.02; // Example: 0.01 for 1%
|
|
45
|
+
export const SIMPLE_SWAP_SLIPPAGE = 0.05;
|
package/utils/number.d.ts
CHANGED
|
@@ -9,5 +9,13 @@ export interface NumberFormatter {
|
|
|
9
9
|
export declare const balanceFormatter: NumberFormatter;
|
|
10
10
|
export declare const balanceNoPrefixFormater: NumberFormatter;
|
|
11
11
|
export declare const PREDEFINED_FORMATTER: Record<string, NumberFormatter>;
|
|
12
|
-
|
|
12
|
+
/** @function formatNumber
|
|
13
|
+
* Convert number to a formatted string by dividing by 10^decimal
|
|
14
|
+
* @param {string | number | BigNumber} input - Input number
|
|
15
|
+
* @param {number} decimal - Decimal number
|
|
16
|
+
* @param {NumberFormatter} [formatter] - Formatter function
|
|
17
|
+
* - Default: balanceFormatter: With number > 1, show decimal with 2 numbers,
|
|
18
|
+
* with number < 1, show decimal with 6 (default) number
|
|
19
|
+
* @param {Record<string, number>} [metadata] - Metadata for formatter
|
|
20
|
+
*/
|
|
13
21
|
export declare const formatNumber: (input: string | number | BigNumber, decimal: number, formatter?: NumberFormatter, metadata?: Record<string, number>) => string;
|
package/utils/number.js
CHANGED
|
@@ -182,10 +182,16 @@ export const balanceNoPrefixFormater = (input, metadata) => {
|
|
|
182
182
|
export const PREDEFINED_FORMATTER = {
|
|
183
183
|
balance: balanceFormatter
|
|
184
184
|
};
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
185
|
+
|
|
186
|
+
/** @function formatNumber
|
|
187
|
+
* Convert number to a formatted string by dividing by 10^decimal
|
|
188
|
+
* @param {string | number | BigNumber} input - Input number
|
|
189
|
+
* @param {number} decimal - Decimal number
|
|
190
|
+
* @param {NumberFormatter} [formatter] - Formatter function
|
|
191
|
+
* - Default: balanceFormatter: With number > 1, show decimal with 2 numbers,
|
|
192
|
+
* with number < 1, show decimal with 6 (default) number
|
|
193
|
+
* @param {Record<string, number>} [metadata] - Metadata for formatter
|
|
194
|
+
*/
|
|
189
195
|
export const formatNumber = (input, decimal, formatter = balanceFormatter, metadata) => {
|
|
190
196
|
const raw = new BigNumber(input).dividedBy(BN_TEN.pow(decimal)).toFixed();
|
|
191
197
|
return formatter(raw, metadata);
|