@subwallet/extension-base 1.3.78-0 → 1.3.80-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/KoniTypes.d.ts +16 -6
- package/cjs/core/logic-validation/index.js +0 -12
- package/cjs/core/substrate/system-pallet.js +3 -0
- package/cjs/koni/api/nft/index.js +0 -14
- package/cjs/koni/background/cron.js +0 -17
- package/cjs/koni/background/handlers/Extension.js +13 -7
- package/cjs/koni/background/handlers/State.js +24 -6
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/process.js +49 -21
- package/cjs/services/balance-service/index.js +2 -2
- package/cjs/services/balance-service/transfer/xcm/utils.js +9 -9
- package/cjs/services/chain-service/constants.js +6 -2
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +13 -13
- package/cjs/services/earning-service/handlers/native-staking/tao.js +16 -10
- package/cjs/services/earning-service/handlers/special.js +12 -4
- package/cjs/services/nft-service/index.js +219 -150
- package/cjs/services/nft-service/multi-chain-nft-fetcher.js +145 -0
- package/cjs/services/nft-service/nft-handlers/base-nft-handler.js +28 -0
- package/cjs/services/nft-service/nft-handlers/evm/evm-nft-handler.js +179 -0
- package/cjs/services/nft-service/nft-handlers/registry.js +37 -0
- package/cjs/services/nft-service/nft-handlers/unique/unique-nft-handler.js +187 -0
- package/cjs/services/storage-service/DatabaseService.js +1 -1
- package/cjs/services/swap-service/handler/asset-hub/handler.js +7 -4
- package/cjs/services/swap-service/handler/asset-hub/router.js +2 -66
- package/cjs/services/swap-service/handler/base-handler.js +4 -3
- package/cjs/services/swap-service/handler/hydradx-handler.js +9 -5
- package/cjs/services/swap-service/index.js +5 -4
- package/cjs/types/swap/index.js +4 -9
- package/cjs/utils/account/common.js +44 -8
- package/core/logic-validation/index.d.ts +0 -1
- package/core/logic-validation/index.js +0 -1
- package/core/substrate/system-pallet.js +3 -0
- package/koni/api/nft/index.js +1 -15
- package/koni/background/cron.d.ts +0 -1
- package/koni/background/cron.js +1 -18
- package/koni/background/handlers/Extension.d.ts +4 -0
- package/koni/background/handlers/Extension.js +13 -7
- package/koni/background/handlers/State.d.ts +8 -2
- package/koni/background/handlers/State.js +24 -6
- package/package.json +31 -11
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/process.d.ts +1 -1
- package/services/balance-service/helpers/process.js +48 -21
- package/services/balance-service/index.js +2 -2
- package/services/balance-service/transfer/xcm/utils.js +9 -9
- package/services/chain-service/constants.d.ts +3 -0
- package/services/chain-service/constants.js +3 -0
- package/services/earning-service/handlers/native-staking/dtao.js +12 -13
- package/services/earning-service/handlers/native-staking/tao.d.ts +2 -1
- package/services/earning-service/handlers/native-staking/tao.js +15 -10
- package/services/earning-service/handlers/special.js +13 -5
- package/services/nft-service/index.d.ts +42 -6
- package/services/nft-service/index.js +219 -151
- package/services/nft-service/multi-chain-nft-fetcher.d.ts +13 -0
- package/services/nft-service/multi-chain-nft-fetcher.js +138 -0
- package/services/nft-service/nft-handlers/base-nft-handler.d.ts +13 -0
- package/services/nft-service/nft-handlers/base-nft-handler.js +21 -0
- package/services/nft-service/nft-handlers/evm/evm-nft-handler.d.ts +9 -0
- package/services/nft-service/nft-handlers/evm/evm-nft-handler.js +171 -0
- package/services/nft-service/nft-handlers/registry.d.ts +11 -0
- package/services/nft-service/nft-handlers/registry.js +29 -0
- package/services/nft-service/nft-handlers/unique/unique-nft-handler.d.ts +12 -0
- package/services/nft-service/nft-handlers/unique/unique-nft-handler.js +177 -0
- package/services/storage-service/DatabaseService.d.ts +1 -1
- package/services/storage-service/DatabaseService.js +1 -1
- package/services/swap-service/handler/asset-hub/handler.js +7 -4
- package/services/swap-service/handler/asset-hub/router.d.ts +0 -4
- package/services/swap-service/handler/asset-hub/router.js +1 -64
- package/services/swap-service/handler/base-handler.js +4 -3
- package/services/swap-service/handler/hydradx-handler.js +9 -5
- package/services/swap-service/index.js +5 -4
- package/types/swap/index.d.ts +7 -35
- package/types/swap/index.js +3 -8
- package/types/yield/actions/join/step.d.ts +1 -0
- package/types/yield/actions/join/submit.d.ts +2 -1
- package/utils/account/common.d.ts +22 -1
- package/utils/account/common.js +44 -8
- package/cjs/core/logic-validation/swap.js +0 -235
- package/core/logic-validation/swap.d.ts +0 -26
- package/core/logic-validation/swap.js +0 -219
package/types/swap/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ChainAsset
|
|
1
|
+
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
2
|
import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
|
|
3
|
-
import {
|
|
3
|
+
import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import { BaseStepDetail, BaseStepType, CommonOptimalSwapPath, CommonStepFeeInfo } from '@subwallet/extension-base/types/service-base';
|
|
5
5
|
import BigN from 'bignumber.js';
|
|
6
6
|
import { BaseProcessRequestSign, TransactionData } from '../transaction';
|
|
@@ -73,7 +73,6 @@ export declare const _SUPPORTED_SWAP_PROVIDERS: SwapProviderId[];
|
|
|
73
73
|
export interface SwapProvider {
|
|
74
74
|
id: SwapProviderId;
|
|
75
75
|
name: string;
|
|
76
|
-
faq?: string;
|
|
77
76
|
}
|
|
78
77
|
export declare enum SwapFeeType {
|
|
79
78
|
PLATFORM_FEE = "PLATFORM_FEE",
|
|
@@ -101,30 +100,13 @@ export interface HydradxSwapTxData extends SwapBaseTxData {
|
|
|
101
100
|
txHex: string;
|
|
102
101
|
}
|
|
103
102
|
export declare type GenSwapStepFuncV2 = (params: OptimalSwapPathParamsV2, stepIndex: number) => Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
104
|
-
export interface ChainflipPreValidationMetadata {
|
|
105
|
-
minSwap: AmountData;
|
|
106
|
-
maxSwap?: AmountData;
|
|
107
|
-
chain: _ChainInfo;
|
|
108
|
-
}
|
|
109
|
-
export interface HydradxPreValidationMetadata {
|
|
110
|
-
maxSwap: AmountData;
|
|
111
|
-
chain: _ChainInfo;
|
|
112
|
-
}
|
|
113
|
-
export interface AssetHubPreValidationMetadata {
|
|
114
|
-
chain: _ChainInfo;
|
|
115
|
-
toAmount: string;
|
|
116
|
-
quoteRate: string;
|
|
117
|
-
priceImpactPct?: string;
|
|
118
|
-
}
|
|
119
|
-
export interface SimpleSwapValidationMetadata {
|
|
120
|
-
minSwap: AmountData;
|
|
121
|
-
maxSwap: AmountData;
|
|
122
|
-
chain: _ChainInfo;
|
|
123
|
-
}
|
|
124
103
|
export interface ProcessedQuoteAskResponse {
|
|
125
104
|
quote?: SwapQuote;
|
|
126
105
|
error?: SwapError;
|
|
127
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated Use interface `SwapRequestV2` instead.
|
|
109
|
+
*/
|
|
128
110
|
export interface SwapRequest {
|
|
129
111
|
address: string;
|
|
130
112
|
pair: SwapPair;
|
|
@@ -136,6 +118,7 @@ export interface SwapRequest {
|
|
|
136
118
|
}
|
|
137
119
|
export interface SwapRequestV2 {
|
|
138
120
|
address: string;
|
|
121
|
+
alternativeAddress?: string;
|
|
139
122
|
pair: SwapPair;
|
|
140
123
|
fromAmount: string;
|
|
141
124
|
slippage: number;
|
|
@@ -182,22 +165,11 @@ export interface DynamicSwapAction {
|
|
|
182
165
|
action: DynamicSwapType;
|
|
183
166
|
pair: ActionPair;
|
|
184
167
|
}
|
|
185
|
-
export declare const enum BridgeStepPosition {
|
|
186
|
-
FIRST = 0,
|
|
187
|
-
AFTER_SWAP = 1
|
|
188
|
-
}
|
|
189
168
|
export interface OptimalSwapPathParamsV2 {
|
|
190
|
-
request:
|
|
169
|
+
request: SwapRequestV2;
|
|
191
170
|
selectedQuote?: SwapQuote;
|
|
192
171
|
path: DynamicSwapAction[];
|
|
193
172
|
}
|
|
194
|
-
export interface SwapEarlyValidation {
|
|
195
|
-
error?: SwapErrorType;
|
|
196
|
-
metadata?: ChainflipPreValidationMetadata | HydradxPreValidationMetadata | AssetHubPreValidationMetadata;
|
|
197
|
-
}
|
|
198
|
-
export interface AssetHubSwapEarlyValidation extends SwapEarlyValidation {
|
|
199
|
-
metadata: AssetHubPreValidationMetadata;
|
|
200
|
-
}
|
|
201
173
|
export interface ValidateSwapProcessParams {
|
|
202
174
|
address: string;
|
|
203
175
|
process: CommonOptimalSwapPath;
|
package/types/swap/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
// core
|
|
5
|
-
|
|
6
4
|
export let SwapErrorType;
|
|
7
5
|
(function (SwapErrorType) {
|
|
8
6
|
SwapErrorType["ERROR_FETCHING_QUOTE"] = "ERROR_FETCHING_QUOTE";
|
|
@@ -46,7 +44,6 @@ export let SwapProviderId;
|
|
|
46
44
|
SwapProviderId["BITTENSOR_TESTNET"] = "BITTENSOR_TESTNET";
|
|
47
45
|
})(SwapProviderId || (SwapProviderId = {}));
|
|
48
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, SwapProviderId.BITTENSOR, SwapProviderId.BITTENSOR_TESTNET];
|
|
49
|
-
// process handling
|
|
50
47
|
export let SwapFeeType;
|
|
51
48
|
(function (SwapFeeType) {
|
|
52
49
|
SwapFeeType["PLATFORM_FEE"] = "PLATFORM_FEE";
|
|
@@ -54,15 +51,13 @@ export let SwapFeeType;
|
|
|
54
51
|
SwapFeeType["WALLET_FEE"] = "WALLET_FEE";
|
|
55
52
|
})(SwapFeeType || (SwapFeeType = {})); // todo: will be more
|
|
56
53
|
// parameters & responses
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use interface `SwapRequestV2` instead.
|
|
56
|
+
*/
|
|
57
57
|
export let DynamicSwapType;
|
|
58
58
|
(function (DynamicSwapType) {
|
|
59
59
|
DynamicSwapType["SWAP"] = "SWAP";
|
|
60
60
|
DynamicSwapType["BRIDGE"] = "BRIDGE";
|
|
61
61
|
})(DynamicSwapType || (DynamicSwapType = {}));
|
|
62
|
-
export let BridgeStepPosition;
|
|
63
|
-
(function (BridgeStepPosition) {
|
|
64
|
-
BridgeStepPosition[BridgeStepPosition["FIRST"] = 0] = "FIRST";
|
|
65
|
-
BridgeStepPosition[BridgeStepPosition["AFTER_SWAP"] = 1] = "AFTER_SWAP";
|
|
66
|
-
})(BridgeStepPosition || (BridgeStepPosition = {}));
|
|
67
62
|
export const CHAINFLIP_SLIPPAGE = 0.02; // Example: 0.01 for 1%
|
|
68
63
|
export const SIMPLE_SWAP_SLIPPAGE = 0.05;
|
|
@@ -98,6 +98,7 @@ export interface OptimalYieldPath {
|
|
|
98
98
|
export declare type GenStepFunction = (params: OptimalYieldPathParams) => Promise<YieldStepBaseInfo | undefined>;
|
|
99
99
|
export interface XcmStepMetadataForLiqStaking {
|
|
100
100
|
sendingValue: string;
|
|
101
|
+
xcmDestinationFee?: string;
|
|
101
102
|
originTokenInfo: _ChainAsset;
|
|
102
103
|
destinationTokenInfo: _ChainAsset;
|
|
103
104
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _Address, ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
1
|
+
import { _Address, AmountData, ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import { BaseProcessRequestSign, BaseRequestSign, InternalRequestSign, TransactionData } from '../../../transaction';
|
|
3
3
|
import { BittensorRootClaimType, NominationPoolInfo, ValidatorInfo, YieldPoolType, YieldPositionInfo } from '../../info';
|
|
4
4
|
import { OptimalYieldPath } from './step';
|
|
@@ -10,6 +10,7 @@ export interface HandleYieldStepData {
|
|
|
10
10
|
txData: any;
|
|
11
11
|
transferNativeAmount: string;
|
|
12
12
|
xcmStepFee?: string;
|
|
13
|
+
xcmDestinationFee?: AmountData;
|
|
13
14
|
}
|
|
14
15
|
export interface AbstractSubmitYieldJoinData {
|
|
15
16
|
slug: string;
|
|
@@ -3,7 +3,28 @@ import { ChainType } from '@subwallet/extension-base/background/KoniTypes';
|
|
|
3
3
|
import { AccountChainType, AccountJson } from '@subwallet/extension-base/types';
|
|
4
4
|
export declare function isAccountAll(address?: string): boolean;
|
|
5
5
|
export declare function reformatAddress(address: string, networkPrefix?: number, isEthereum?: boolean, ignoreError?: boolean): string;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @private
|
|
8
|
+
* Reformats a wallet address based on the provided chain information.
|
|
9
|
+
*
|
|
10
|
+
* This function checks the chain type (Substrate, TON, Cardano, or others)
|
|
11
|
+
* and applies the corresponding formatting logic:
|
|
12
|
+
* 1. **Substrate**: Reformats the Substrate address using the chain's specific prefix.
|
|
13
|
+
* If the current `address` is an EVM address, it attempts to use the `alternativeAddress`
|
|
14
|
+
* (which is currently **always** expected to be the Substrate address) for Substrate
|
|
15
|
+
* formatting, as direct EVM-to-Substrate reformatting is not possible here.
|
|
16
|
+
* 2. **TON/Cardano**: Uses a simple prefix logic based on whether the chain is a testnet or a mainnet.
|
|
17
|
+
* 3. **Default (EVM/Others)**: Returns the original address without reformatting.
|
|
18
|
+
*
|
|
19
|
+
* @param address The current wallet address string.
|
|
20
|
+
* @param chainInfo An object containing chain details (e.g., chain type, testnet status, prefix).
|
|
21
|
+
* @param alternativeAddress An optional alternative address, which is currently expected to be the Substrate
|
|
22
|
+
* address associated with the account. It is used as a fallback for Substrate formatting when the main `address` is EVM.
|
|
23
|
+
* @returns The reformatted wallet address, or the original address if no reformatting is needed or possible.
|
|
24
|
+
*
|
|
25
|
+
* @todo This function currently lacks logic to reformat a Substrate address into an EVM address format.
|
|
26
|
+
*/
|
|
27
|
+
export declare const _reformatAddressWithChain: (address: string, chainInfo: _ChainInfo, alternativeAddress?: string) => string;
|
|
7
28
|
export declare const getAccountChainTypeForAddress: (address: string) => AccountChainType;
|
|
8
29
|
declare type AddressesByChainType = {
|
|
9
30
|
[key in ChainType]: string[];
|
package/utils/account/common.js
CHANGED
|
@@ -40,17 +40,53 @@ export function reformatAddress(address, networkPrefix = 42, isEthereum = false,
|
|
|
40
40
|
return address;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @private
|
|
46
|
+
* Reformats a wallet address based on the provided chain information.
|
|
47
|
+
*
|
|
48
|
+
* This function checks the chain type (Substrate, TON, Cardano, or others)
|
|
49
|
+
* and applies the corresponding formatting logic:
|
|
50
|
+
* 1. **Substrate**: Reformats the Substrate address using the chain's specific prefix.
|
|
51
|
+
* If the current `address` is an EVM address, it attempts to use the `alternativeAddress`
|
|
52
|
+
* (which is currently **always** expected to be the Substrate address) for Substrate
|
|
53
|
+
* formatting, as direct EVM-to-Substrate reformatting is not possible here.
|
|
54
|
+
* 2. **TON/Cardano**: Uses a simple prefix logic based on whether the chain is a testnet or a mainnet.
|
|
55
|
+
* 3. **Default (EVM/Others)**: Returns the original address without reformatting.
|
|
56
|
+
*
|
|
57
|
+
* @param address The current wallet address string.
|
|
58
|
+
* @param chainInfo An object containing chain details (e.g., chain type, testnet status, prefix).
|
|
59
|
+
* @param alternativeAddress An optional alternative address, which is currently expected to be the Substrate
|
|
60
|
+
* address associated with the account. It is used as a fallback for Substrate formatting when the main `address` is EVM.
|
|
61
|
+
* @returns The reformatted wallet address, or the original address if no reformatting is needed or possible.
|
|
62
|
+
*
|
|
63
|
+
* @todo This function currently lacks logic to reformat a Substrate address into an EVM address format.
|
|
64
|
+
*/
|
|
65
|
+
export const _reformatAddressWithChain = (address, chainInfo, alternativeAddress) => {
|
|
44
66
|
const chainType = _chainInfoToAccountChainType(chainInfo);
|
|
45
67
|
if (chainType === AccountChainType.SUBSTRATE) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
68
|
+
const addressPrefix = _getChainSubstrateAddressPrefix(chainInfo);
|
|
69
|
+
if (addressPrefix < 0) {
|
|
70
|
+
// not a valid address prefix for substrate chain type
|
|
71
|
+
return address;
|
|
72
|
+
}
|
|
73
|
+
if (isEthereumAddress(address)) {
|
|
74
|
+
if (alternativeAddress) {
|
|
75
|
+
// reformat using alternativeAddress of that account. Because can not reformat from evm address to substrate address
|
|
76
|
+
return reformatAddress(alternativeAddress, addressPrefix);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// can not reformat without substrateAddress info
|
|
80
|
+
return address;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// reformat as usual with substrate address
|
|
84
|
+
return reformatAddress(address, addressPrefix);
|
|
85
|
+
}
|
|
86
|
+
if (chainType === AccountChainType.TON || chainType === AccountChainType.CARDANO) {
|
|
87
|
+
return reformatAddress(address, chainInfo.isTestnet ? 0 : 1);
|
|
53
88
|
}
|
|
89
|
+
return address;
|
|
54
90
|
};
|
|
55
91
|
export const getAccountChainTypeForAddress = address => {
|
|
56
92
|
const type = getKeypairTypeByAddress(address);
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports._getChainflipEarlyValidationError = _getChainflipEarlyValidationError;
|
|
8
|
-
exports._getEarlyAssetHubValidationError = _getEarlyAssetHubValidationError;
|
|
9
|
-
exports._getEarlyHydradxValidationError = _getEarlyHydradxValidationError;
|
|
10
|
-
exports._getSimpleSwapEarlyValidationError = _getSimpleSwapEarlyValidationError;
|
|
11
|
-
exports._validateBalanceToSwap = _validateBalanceToSwap;
|
|
12
|
-
exports._validateBalanceToSwapOnAssetHub = _validateBalanceToSwapOnAssetHub;
|
|
13
|
-
exports._validateBalanceToSwapV2 = _validateBalanceToSwapV2;
|
|
14
|
-
exports._validateQuoteV2 = _validateQuoteV2;
|
|
15
|
-
exports._validateSwapRecipient = _validateSwapRecipient;
|
|
16
|
-
exports._validateSwapRecipientV2 = _validateSwapRecipientV2;
|
|
17
|
-
var _SwapError = require("@subwallet/extension-base/background/errors/SwapError");
|
|
18
|
-
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
19
|
-
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
20
|
-
var _types = require("@subwallet/extension-base/types");
|
|
21
|
-
var _swap = require("@subwallet/extension-base/types/swap");
|
|
22
|
-
var _utils2 = require("@subwallet/extension-base/utils");
|
|
23
|
-
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
24
|
-
var _utilCrypto = require("@polkadot/util-crypto");
|
|
25
|
-
// Copyright 2019-2022 @subwallet/extension-base
|
|
26
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
27
|
-
|
|
28
|
-
function _validateBalanceToSwapOnAssetHub(fromToken, feeToken, feeTokenChainInfo, feeAmount, fromTokenBalance, feeTokenBalance, swapAmount, isXcmOk, minSwap) {
|
|
29
|
-
const bnFromTokenBalance = new _bignumber.default(fromTokenBalance);
|
|
30
|
-
if (!(0, _utils._isNativeToken)(fromToken) && bnFromTokenBalance.minus(swapAmount).lt((0, _utils._getTokenMinAmount)(fromToken))) {
|
|
31
|
-
const parsedMaxBalanceSwap = (0, _utils2.formatNumber)(bnFromTokenBalance.minus((0, _utils._getTokenMinAmount)(fromToken)), (0, _utils._getAssetDecimals)(fromToken));
|
|
32
|
-
return new _TransactionError.TransactionError(_swap.SwapErrorType.SWAP_EXCEED_ALLOWANCE, `Amount too high. Lower your amount ${bnFromTokenBalance.gt(0) ? `below ${parsedMaxBalanceSwap} ${fromToken.symbol}` : ''} and try again`);
|
|
33
|
-
}
|
|
34
|
-
if (new _bignumber.default(feeTokenBalance).lte(feeAmount)) {
|
|
35
|
-
return new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE, `You don't have enough ${feeToken.symbol} (${feeTokenChainInfo.name}) to pay transaction fee`);
|
|
36
|
-
}
|
|
37
|
-
if (!(0, _utils._isNativeToken)(fromToken) && fromToken.slug === feeToken.slug) {
|
|
38
|
-
// todo: need review and refactor
|
|
39
|
-
if (bnFromTokenBalance.lte(new _bignumber.default(feeAmount).plus(swapAmount))) {
|
|
40
|
-
return new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromToken.symbol} and try again.`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (isXcmOk) {
|
|
44
|
-
// assume that the swap is valid if XCM is in the process and it was successful
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
if (minSwap) {
|
|
48
|
-
if (bnFromTokenBalance.lte(minSwap)) {
|
|
49
|
-
const parsedMinSwapValue = (0, _utils2.formatNumber)(minSwap, (0, _utils._getAssetDecimals)(fromToken));
|
|
50
|
-
return new _TransactionError.TransactionError(_swap.SwapErrorType.SWAP_NOT_ENOUGH_BALANCE, `Insufficient balance. You need more than ${parsedMinSwapValue} ${fromToken.symbol} to start swapping. Deposit ${fromToken.symbol} and try again.`); // todo: min swap or amount?
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (new _bignumber.default(swapAmount).gte(fromTokenBalance)) {
|
|
54
|
-
const parsedMaxBalanceSwap = (0, _utils2.formatNumber)(fromTokenBalance, (0, _utils._getAssetDecimals)(fromToken));
|
|
55
|
-
return new _TransactionError.TransactionError(_swap.SwapErrorType.SWAP_EXCEED_ALLOWANCE, `Amount too high. Lower your amount ${bnFromTokenBalance.gt(0) ? `below ${parsedMaxBalanceSwap} ${fromToken.symbol}` : ''} and try again`);
|
|
56
|
-
}
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
function _validateBalanceToSwap(fromToken, feeToken, feeTokenChainInfo, feeAmount, fromTokenBalance, feeTokenBalance, swapAmount, isXcmOk, minSwap) {
|
|
60
|
-
const bnFromTokenBalance = new _bignumber.default(fromTokenBalance);
|
|
61
|
-
if (new _bignumber.default(feeTokenBalance).lte(feeAmount)) {
|
|
62
|
-
return new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE, `You don't have enough ${feeToken.symbol} (${feeTokenChainInfo.name}) to pay transaction fee`);
|
|
63
|
-
}
|
|
64
|
-
if (fromToken.slug === feeToken.slug) {
|
|
65
|
-
// todo: need review and refactor
|
|
66
|
-
if (bnFromTokenBalance.lte(new _bignumber.default(feeAmount).plus(swapAmount))) {
|
|
67
|
-
return new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromToken.symbol} and try again.`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (isXcmOk) {
|
|
71
|
-
// assume that the swap is valid if XCM is in the process and it was successful
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
if (minSwap) {
|
|
75
|
-
if (bnFromTokenBalance.lte(minSwap)) {
|
|
76
|
-
const parsedMinSwapValue = (0, _utils2.formatNumber)(minSwap, (0, _utils._getAssetDecimals)(fromToken));
|
|
77
|
-
return new _TransactionError.TransactionError(_swap.SwapErrorType.SWAP_NOT_ENOUGH_BALANCE, `Insufficient balance. You need more than ${parsedMinSwapValue} ${fromToken.symbol} to start swapping. Deposit ${fromToken.symbol} and try again.`); // todo: min swap or amount?
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (new _bignumber.default(swapAmount).gte(fromTokenBalance)) {
|
|
81
|
-
const parsedMaxBalanceSwap = (0, _utils2.formatNumber)(fromTokenBalance, (0, _utils._getAssetDecimals)(fromToken));
|
|
82
|
-
return new _TransactionError.TransactionError(_swap.SwapErrorType.SWAP_EXCEED_ALLOWANCE, `Amount too high. Lower your amount ${bnFromTokenBalance.gt(0) ? `below ${parsedMaxBalanceSwap} ${fromToken.symbol}` : ''} and try again`);
|
|
83
|
-
}
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
function _validateSwapRecipient(destChainInfo, recipient) {
|
|
87
|
-
const isEvmAddress = (0, _utilCrypto.isEthereumAddress)(recipient);
|
|
88
|
-
const isEvmDestChain = (0, _utils._isChainEvmCompatible)(destChainInfo);
|
|
89
|
-
if (isEvmAddress && !isEvmDestChain || !isEvmAddress && isEvmDestChain) {
|
|
90
|
-
return new _TransactionError.TransactionError(_swap.SwapErrorType.INVALID_RECIPIENT);
|
|
91
|
-
}
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
function _getChainflipEarlyValidationError(error, metadata) {
|
|
95
|
-
// todo: support more providers
|
|
96
|
-
switch (error) {
|
|
97
|
-
case _swap.SwapErrorType.NOT_MEET_MIN_SWAP:
|
|
98
|
-
{
|
|
99
|
-
const parsedMinSwapValue = (0, _utils2.formatNumber)(metadata.minSwap.value, metadata.minSwap.decimals);
|
|
100
|
-
const message = `Amount too low. Increase your amount above ${parsedMinSwapValue} ${metadata.minSwap.symbol} and try again`;
|
|
101
|
-
return new _SwapError.SwapError(error, message);
|
|
102
|
-
}
|
|
103
|
-
case _swap.SwapErrorType.SWAP_EXCEED_ALLOWANCE:
|
|
104
|
-
{
|
|
105
|
-
if (metadata.maxSwap) {
|
|
106
|
-
const parsedMaxSwapValue = (0, _utils2.formatNumber)(metadata.maxSwap.value, metadata.maxSwap.decimals);
|
|
107
|
-
return new _SwapError.SwapError(error, `Amount too high. Lower your amount below ${parsedMaxSwapValue} ${metadata.maxSwap.symbol} and try again`);
|
|
108
|
-
} else {
|
|
109
|
-
return new _SwapError.SwapError(error, 'Amount too high. Lower your amount and try again');
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
case _swap.SwapErrorType.ASSET_NOT_SUPPORTED:
|
|
113
|
-
return new _SwapError.SwapError(error, 'This swap pair is not supported');
|
|
114
|
-
case _swap.SwapErrorType.UNKNOWN:
|
|
115
|
-
return new _SwapError.SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
116
|
-
case _swap.SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
117
|
-
return new _SwapError.SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
118
|
-
default:
|
|
119
|
-
return new _SwapError.SwapError(error);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function _getEarlyHydradxValidationError(error, metadata) {
|
|
123
|
-
switch (error) {
|
|
124
|
-
case _swap.SwapErrorType.AMOUNT_CANNOT_BE_ZERO:
|
|
125
|
-
{
|
|
126
|
-
return new _SwapError.SwapError(error, 'Amount too low. Increase your amount above 0 and try again');
|
|
127
|
-
}
|
|
128
|
-
case _swap.SwapErrorType.ASSET_NOT_SUPPORTED:
|
|
129
|
-
return new _SwapError.SwapError(error, 'This swap pair is not supported');
|
|
130
|
-
case _swap.SwapErrorType.UNKNOWN:
|
|
131
|
-
return new _SwapError.SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
132
|
-
case _swap.SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
133
|
-
return new _SwapError.SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
134
|
-
default:
|
|
135
|
-
return new _SwapError.SwapError(error);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function _getEarlyAssetHubValidationError(error, metadata) {
|
|
139
|
-
switch (error) {
|
|
140
|
-
case _swap.SwapErrorType.AMOUNT_CANNOT_BE_ZERO:
|
|
141
|
-
return new _SwapError.SwapError(error, 'Amount too low. Increase your amount above 0 and try again');
|
|
142
|
-
case _swap.SwapErrorType.ASSET_NOT_SUPPORTED:
|
|
143
|
-
return new _SwapError.SwapError(error, 'This swap pair is not supported');
|
|
144
|
-
case _swap.SwapErrorType.UNKNOWN:
|
|
145
|
-
return new _SwapError.SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
146
|
-
case _swap.SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
147
|
-
return new _SwapError.SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
148
|
-
case _swap.SwapErrorType.MAKE_POOL_NOT_ENOUGH_EXISTENTIAL_DEPOSIT:
|
|
149
|
-
return new _SwapError.SwapError(error, 'You swap too much. It make pool not enough existential deposit');
|
|
150
|
-
// TODO: i18n this
|
|
151
|
-
default:
|
|
152
|
-
return new _SwapError.SwapError(error);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
function _getSimpleSwapEarlyValidationError(error, metadata) {
|
|
156
|
-
// todo: support more providers
|
|
157
|
-
switch (error) {
|
|
158
|
-
case _swap.SwapErrorType.NOT_MEET_MIN_SWAP:
|
|
159
|
-
{
|
|
160
|
-
const message = `Amount too low. Increase your amount above ${metadata.minSwap.value} ${metadata.minSwap.symbol} and try again`;
|
|
161
|
-
return new _SwapError.SwapError(error, message);
|
|
162
|
-
}
|
|
163
|
-
case _swap.SwapErrorType.SWAP_EXCEED_ALLOWANCE:
|
|
164
|
-
{
|
|
165
|
-
if (metadata.maxSwap) {
|
|
166
|
-
return new _SwapError.SwapError(error, `Amount too high. Lower your amount below ${metadata.maxSwap.value} ${metadata.maxSwap.symbol} and try again`);
|
|
167
|
-
} else {
|
|
168
|
-
return new _SwapError.SwapError(error, 'Amount too high. Lower your amount and try again');
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
case _swap.SwapErrorType.ASSET_NOT_SUPPORTED:
|
|
172
|
-
return new _SwapError.SwapError(error, 'This swap pair is not supported');
|
|
173
|
-
case _swap.SwapErrorType.UNKNOWN:
|
|
174
|
-
return new _SwapError.SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
175
|
-
case _swap.SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
176
|
-
return new _SwapError.SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
177
|
-
default:
|
|
178
|
-
return new _SwapError.SwapError(error);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
function _validateQuoteV2(selectedQuote) {
|
|
182
|
-
if (!selectedQuote) {
|
|
183
|
-
return new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Check swapQuote alive
|
|
187
|
-
if (selectedQuote.aliveUntil <= +Date.now()) {
|
|
188
|
-
return new _TransactionError.TransactionError(_swap.SwapErrorType.QUOTE_TIMEOUT);
|
|
189
|
-
}
|
|
190
|
-
return undefined;
|
|
191
|
-
}
|
|
192
|
-
function _validateBalanceToSwapV2(request) {
|
|
193
|
-
const {
|
|
194
|
-
chainInfo,
|
|
195
|
-
feeAmount,
|
|
196
|
-
feeToken,
|
|
197
|
-
feeTokenBalance,
|
|
198
|
-
fromToken,
|
|
199
|
-
fromTokenBalance,
|
|
200
|
-
minSwapAmount,
|
|
201
|
-
swapAmount
|
|
202
|
-
} = request;
|
|
203
|
-
const bnFromTokenBalance = (0, _bignumber.default)(fromTokenBalance);
|
|
204
|
-
if (new _bignumber.default(feeTokenBalance).lte(feeAmount)) {
|
|
205
|
-
return new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE, `You don't have enough ${feeToken.symbol} (${chainInfo.name}) to pay transaction fee`);
|
|
206
|
-
}
|
|
207
|
-
if (fromToken.slug === feeToken.slug) {
|
|
208
|
-
// todo: need review and refactor
|
|
209
|
-
if (bnFromTokenBalance.lte((0, _bignumber.default)(feeAmount).plus(swapAmount))) {
|
|
210
|
-
return new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromToken.symbol} and try again.`);
|
|
211
|
-
}
|
|
212
|
-
} else {
|
|
213
|
-
if (bnFromTokenBalance.lt(swapAmount)) {
|
|
214
|
-
return new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromToken.symbol} and try again.`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (minSwapAmount) {
|
|
218
|
-
if (bnFromTokenBalance.lte(minSwapAmount)) {
|
|
219
|
-
const parsedMinSwapValue = (0, _utils2.formatNumber)(minSwapAmount, (0, _utils._getAssetDecimals)(fromToken));
|
|
220
|
-
return new _TransactionError.TransactionError(_swap.SwapErrorType.SWAP_NOT_ENOUGH_BALANCE, `Insufficient balance. You need more than ${parsedMinSwapValue} ${fromToken.symbol} to start swapping. Deposit ${fromToken.symbol} and try again.`); // todo: min swap or amount?
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return undefined;
|
|
224
|
-
}
|
|
225
|
-
function _validateSwapRecipientV2(destChainInfo, recipient) {
|
|
226
|
-
if (!recipient) {
|
|
227
|
-
return undefined;
|
|
228
|
-
}
|
|
229
|
-
const isEvmAddress = (0, _utilCrypto.isEthereumAddress)(recipient);
|
|
230
|
-
const isEvmDestChain = (0, _utils._isChainEvmCompatible)(destChainInfo);
|
|
231
|
-
if (isEvmAddress && !isEvmDestChain || !isEvmAddress && isEvmDestChain) {
|
|
232
|
-
return new _TransactionError.TransactionError(_swap.SwapErrorType.INVALID_RECIPIENT);
|
|
233
|
-
}
|
|
234
|
-
return undefined;
|
|
235
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
|
|
3
|
-
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
4
|
-
import { SwapQuote } from '@subwallet/extension-base/types';
|
|
5
|
-
import { AssetHubPreValidationMetadata, ChainflipPreValidationMetadata, HydradxPreValidationMetadata, SimpleSwapValidationMetadata, SwapErrorType } from '@subwallet/extension-base/types/swap';
|
|
6
|
-
interface RequestValidateSwap {
|
|
7
|
-
chainInfo: _ChainInfo;
|
|
8
|
-
fromToken: _ChainAsset;
|
|
9
|
-
fromTokenBalance: string;
|
|
10
|
-
feeToken: _ChainAsset;
|
|
11
|
-
feeTokenBalance: string;
|
|
12
|
-
feeAmount: string;
|
|
13
|
-
swapAmount: string;
|
|
14
|
-
minSwapAmount?: string;
|
|
15
|
-
}
|
|
16
|
-
export declare function _validateBalanceToSwapOnAssetHub(fromToken: _ChainAsset, feeToken: _ChainAsset, feeTokenChainInfo: _ChainInfo, feeAmount: string, fromTokenBalance: string, feeTokenBalance: string, swapAmount: string, isXcmOk: boolean, minSwap?: string): TransactionError | undefined;
|
|
17
|
-
export declare function _validateBalanceToSwap(fromToken: _ChainAsset, feeToken: _ChainAsset, feeTokenChainInfo: _ChainInfo, feeAmount: string, fromTokenBalance: string, feeTokenBalance: string, swapAmount: string, isXcmOk: boolean, minSwap?: string): TransactionError | undefined;
|
|
18
|
-
export declare function _validateSwapRecipient(destChainInfo: _ChainInfo, recipient: string): TransactionError | undefined;
|
|
19
|
-
export declare function _getChainflipEarlyValidationError(error: SwapErrorType, metadata: ChainflipPreValidationMetadata): SwapError;
|
|
20
|
-
export declare function _getEarlyHydradxValidationError(error: SwapErrorType, metadata: HydradxPreValidationMetadata): SwapError;
|
|
21
|
-
export declare function _getEarlyAssetHubValidationError(error: SwapErrorType, metadata: AssetHubPreValidationMetadata): SwapError;
|
|
22
|
-
export declare function _getSimpleSwapEarlyValidationError(error: SwapErrorType, metadata: SimpleSwapValidationMetadata): SwapError;
|
|
23
|
-
export declare function _validateQuoteV2(selectedQuote: SwapQuote): TransactionError | undefined;
|
|
24
|
-
export declare function _validateBalanceToSwapV2(request: RequestValidateSwap): TransactionError | undefined;
|
|
25
|
-
export declare function _validateSwapRecipientV2(destChainInfo: _ChainInfo, recipient: string | undefined): TransactionError | undefined;
|
|
26
|
-
export {};
|