@subwallet/extension-base 1.3.29-1 → 1.3.31-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 -4
- package/background/errors/SwapError.js +1 -1
- package/cjs/background/errors/SwapError.js +1 -1
- package/cjs/constants/blocked-actions.js +2 -2
- package/cjs/constants/paraspell-chain-map.js +13 -0
- package/cjs/constants/remind-notification-time.js +3 -3
- package/cjs/core/logic-validation/swap.js +63 -4
- package/cjs/core/logic-validation/transfer.js +13 -1
- package/cjs/core/substrate/xcm-parser.js +5 -1
- package/cjs/core/utils.js +36 -15
- package/cjs/koni/background/handlers/Extension.js +141 -172
- package/cjs/koni/background/handlers/State.js +8 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/process.js +27 -0
- package/cjs/services/balance-service/index.js +9 -0
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +229 -0
- package/cjs/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/cjs/services/balance-service/transfer/xcm/index.js +96 -7
- package/cjs/services/balance-service/transfer/xcm/utils.js +213 -0
- package/cjs/services/chain-service/constants.js +2 -4
- package/cjs/services/chain-service/index.js +71 -17
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/base.js +6 -3
- package/cjs/services/earning-service/handlers/native-staking/base.js +4 -1
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +68 -50
- package/cjs/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/cjs/services/earning-service/handlers/special.js +18 -9
- package/cjs/services/earning-service/service.js +2 -1
- package/cjs/services/fee-service/utils/index.js +16 -4
- package/cjs/services/inapp-notification-service/index.js +19 -13
- package/cjs/services/keyring-service/context/handlers/Ledger.js +1 -1
- package/cjs/services/keyring-service/context/state.js +3 -0
- package/cjs/services/migration-service/scripts/DisableZeroBalanceTokens.js +60 -0
- package/cjs/services/migration-service/scripts/EnableChain.js +1 -1
- package/cjs/services/migration-service/scripts/index.js +3 -2
- package/cjs/services/swap-service/handler/asset-hub/handler.js +61 -314
- package/cjs/services/swap-service/handler/base-handler.js +406 -231
- package/cjs/services/swap-service/handler/chainflip-handler.js +18 -40
- package/cjs/services/swap-service/handler/hydradx-handler.js +77 -269
- package/cjs/services/swap-service/handler/simpleswap-handler.js +27 -48
- package/cjs/services/swap-service/handler/uniswap-handler.js +33 -54
- package/cjs/services/swap-service/index.js +154 -143
- package/cjs/services/swap-service/utils.js +107 -17
- package/cjs/services/transaction-service/index.js +1 -1
- package/cjs/services/transaction-service/utils.js +38 -14
- package/cjs/types/swap/index.js +13 -1
- package/cjs/utils/fee/transfer.js +52 -28
- package/cjs/utils/staticData/index.js +7 -2
- package/cjs/utils/swap.js +5 -1
- package/constants/blocked-actions.d.ts +1 -1
- package/constants/blocked-actions.js +1 -1
- package/constants/paraspell-chain-map.d.ts +1 -0
- package/constants/paraspell-chain-map.js +7 -0
- package/constants/remind-notification-time.d.ts +1 -1
- package/constants/remind-notification-time.js +1 -1
- package/core/logic-validation/swap.d.ts +15 -0
- package/core/logic-validation/swap.js +60 -4
- package/core/logic-validation/transfer.d.ts +1 -0
- package/core/logic-validation/transfer.js +12 -1
- package/core/substrate/xcm-parser.d.ts +1 -0
- package/core/substrate/xcm-parser.js +4 -1
- package/core/utils.d.ts +2 -2
- package/core/utils.js +36 -15
- package/koni/background/handlers/Extension.d.ts +1 -1
- package/koni/background/handlers/Extension.js +66 -98
- package/koni/background/handlers/State.d.ts +1 -0
- package/koni/background/handlers/State.js +7 -1
- package/package.json +23 -13
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/process.d.ts +2 -1
- package/services/balance-service/helpers/process.js +26 -0
- package/services/balance-service/index.js +11 -2
- package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +15 -0
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +216 -0
- package/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/services/balance-service/transfer/xcm/index.d.ts +5 -1
- package/services/balance-service/transfer/xcm/index.js +85 -1
- package/services/balance-service/transfer/xcm/utils.d.ts +11 -0
- package/services/balance-service/transfer/xcm/utils.js +208 -0
- package/services/base/types.d.ts +0 -4
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +1 -2
- package/services/chain-service/index.d.ts +9 -2
- package/services/chain-service/index.js +72 -18
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/base.d.ts +4 -3
- package/services/earning-service/handlers/base.js +6 -4
- package/services/earning-service/handlers/native-staking/base.js +4 -1
- package/services/earning-service/handlers/native-staking/dtao.d.ts +9 -6
- package/services/earning-service/handlers/native-staking/dtao.js +69 -48
- package/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/services/earning-service/handlers/special.js +19 -10
- package/services/earning-service/service.d.ts +2 -1
- package/services/earning-service/service.js +2 -1
- package/services/fee-service/utils/index.d.ts +1 -0
- package/services/fee-service/utils/index.js +14 -4
- package/services/inapp-notification-service/index.js +13 -7
- package/services/keyring-service/context/handlers/Ledger.js +1 -1
- package/services/keyring-service/context/state.d.ts +1 -0
- package/services/keyring-service/context/state.js +3 -0
- package/services/migration-service/scripts/DisableZeroBalanceTokens.d.ts +4 -0
- package/services/migration-service/scripts/DisableZeroBalanceTokens.js +51 -0
- package/services/migration-service/scripts/EnableChain.js +1 -1
- package/services/migration-service/scripts/index.js +3 -2
- package/services/swap-service/handler/asset-hub/handler.d.ts +2 -9
- package/services/swap-service/handler/asset-hub/handler.js +64 -317
- package/services/swap-service/handler/base-handler.d.ts +6 -9
- package/services/swap-service/handler/base-handler.js +405 -230
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -4
- package/services/swap-service/handler/chainflip-handler.js +15 -37
- package/services/swap-service/handler/hydradx-handler.d.ts +3 -10
- package/services/swap-service/handler/hydradx-handler.js +78 -270
- package/services/swap-service/handler/simpleswap-handler.d.ts +2 -4
- package/services/swap-service/handler/simpleswap-handler.js +24 -45
- package/services/swap-service/handler/uniswap-handler.d.ts +4 -6
- package/services/swap-service/handler/uniswap-handler.js +25 -46
- package/services/swap-service/index.d.ts +8 -14
- package/services/swap-service/index.js +141 -129
- package/services/swap-service/utils.d.ts +11 -3
- package/services/swap-service/utils.js +96 -15
- package/services/transaction-service/index.js +2 -2
- package/services/transaction-service/types.d.ts +3 -2
- package/services/transaction-service/utils.d.ts +1 -0
- package/services/transaction-service/utils.js +38 -15
- package/types/balance/transfer.d.ts +1 -0
- package/types/service-base.d.ts +2 -3
- package/types/swap/index.d.ts +25 -9
- package/types/swap/index.js +10 -0
- package/types/transaction/process.d.ts +19 -0
- package/types/transaction/request.d.ts +7 -0
- package/types/yield/actions/join/submit.d.ts +4 -1
- package/types/yield/actions/others.d.ts +2 -0
- package/utils/fee/transfer.d.ts +1 -0
- package/utils/fee/transfer.js +54 -30
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/paraSpellChainMap.json +1 -0
- package/utils/swap.d.ts +3 -0
- package/utils/swap.js +3 -0
- package/cjs/services/swap-service/interface.js +0 -14
- package/services/swap-service/interface.d.ts +0 -9
- package/services/swap-service/interface.js +0 -8
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { fetchStaticData } from '@subwallet/extension-base/utils';
|
|
5
|
-
export const
|
|
5
|
+
export const fetchLatestRemindNotificationTime = async () => {
|
|
6
6
|
return await fetchStaticData('config/remind-notification-time');
|
|
7
7
|
};
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
|
|
3
3
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
4
|
+
import { SwapQuote } from '@subwallet/extension-base/types';
|
|
4
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
|
+
}
|
|
5
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;
|
|
6
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;
|
|
7
18
|
export declare function _validateSwapRecipient(destChainInfo: _ChainInfo, recipient: string): TransactionError | undefined;
|
|
@@ -9,3 +20,7 @@ export declare function _getChainflipEarlyValidationError(error: SwapErrorType,
|
|
|
9
20
|
export declare function _getEarlyHydradxValidationError(error: SwapErrorType, metadata: HydradxPreValidationMetadata): SwapError;
|
|
10
21
|
export declare function _getEarlyAssetHubValidationError(error: SwapErrorType, metadata: AssetHubPreValidationMetadata): SwapError;
|
|
11
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 {};
|
|
@@ -100,7 +100,7 @@ export function _getChainflipEarlyValidationError(error, metadata) {
|
|
|
100
100
|
case SwapErrorType.UNKNOWN:
|
|
101
101
|
return new SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
102
102
|
case SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
103
|
-
return new SwapError(error, 'No swap quote found.
|
|
103
|
+
return new SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
104
104
|
default:
|
|
105
105
|
return new SwapError(error);
|
|
106
106
|
}
|
|
@@ -116,7 +116,7 @@ export function _getEarlyHydradxValidationError(error, metadata) {
|
|
|
116
116
|
case SwapErrorType.UNKNOWN:
|
|
117
117
|
return new SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
118
118
|
case SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
119
|
-
return new SwapError(error, 'No swap quote found.
|
|
119
|
+
return new SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
120
120
|
default:
|
|
121
121
|
return new SwapError(error);
|
|
122
122
|
}
|
|
@@ -130,7 +130,7 @@ export function _getEarlyAssetHubValidationError(error, metadata) {
|
|
|
130
130
|
case SwapErrorType.UNKNOWN:
|
|
131
131
|
return new SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
132
132
|
case SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
133
|
-
return new SwapError(error, 'No swap quote found.
|
|
133
|
+
return new SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
134
134
|
case SwapErrorType.MAKE_POOL_NOT_ENOUGH_EXISTENTIAL_DEPOSIT:
|
|
135
135
|
return new SwapError(error, 'You swap too much. It make pool not enough existential deposit');
|
|
136
136
|
// TODO: i18n this
|
|
@@ -159,8 +159,64 @@ export function _getSimpleSwapEarlyValidationError(error, metadata) {
|
|
|
159
159
|
case SwapErrorType.UNKNOWN:
|
|
160
160
|
return new SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
161
161
|
case SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
162
|
-
return new SwapError(error, 'No swap quote found.
|
|
162
|
+
return new SwapError(error, 'No swap quote found. Change your network endpoint or adjust amount and try again');
|
|
163
163
|
default:
|
|
164
164
|
return new SwapError(error);
|
|
165
165
|
}
|
|
166
|
+
}
|
|
167
|
+
export function _validateQuoteV2(selectedQuote) {
|
|
168
|
+
if (!selectedQuote) {
|
|
169
|
+
return new TransactionError(BasicTxErrorType.INTERNAL_ERROR);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Check swapQuote alive
|
|
173
|
+
if (selectedQuote.aliveUntil <= +Date.now()) {
|
|
174
|
+
return new TransactionError(SwapErrorType.QUOTE_TIMEOUT);
|
|
175
|
+
}
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
export function _validateBalanceToSwapV2(request) {
|
|
179
|
+
const {
|
|
180
|
+
chainInfo,
|
|
181
|
+
feeAmount,
|
|
182
|
+
feeToken,
|
|
183
|
+
feeTokenBalance,
|
|
184
|
+
fromToken,
|
|
185
|
+
fromTokenBalance,
|
|
186
|
+
minSwapAmount,
|
|
187
|
+
swapAmount
|
|
188
|
+
} = request;
|
|
189
|
+
const bnFromTokenBalance = BigN(fromTokenBalance);
|
|
190
|
+
if (new BigN(feeTokenBalance).lte(feeAmount)) {
|
|
191
|
+
return new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE, `You don't have enough ${feeToken.symbol} (${chainInfo.name}) to pay transaction fee`);
|
|
192
|
+
}
|
|
193
|
+
if (fromToken.slug === feeToken.slug) {
|
|
194
|
+
// todo: need review and refactor
|
|
195
|
+
if (bnFromTokenBalance.lte(BigN(feeAmount).plus(swapAmount))) {
|
|
196
|
+
return new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromToken.symbol} and try again.`);
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
if (bnFromTokenBalance.lt(swapAmount)) {
|
|
200
|
+
return new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromToken.symbol} and try again.`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (minSwapAmount) {
|
|
204
|
+
if (bnFromTokenBalance.lte(minSwapAmount)) {
|
|
205
|
+
const parsedMinSwapValue = formatNumber(minSwapAmount, _getAssetDecimals(fromToken));
|
|
206
|
+
return new TransactionError(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?
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
export function _validateSwapRecipientV2(destChainInfo, recipient) {
|
|
213
|
+
if (!recipient) {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
const isEvmAddress = isEthereumAddress(recipient);
|
|
217
|
+
const isEvmDestChain = _isChainEvmCompatible(destChainInfo);
|
|
218
|
+
if (isEvmAddress && !isEvmDestChain || !isEvmAddress && isEvmDestChain) {
|
|
219
|
+
return new TransactionError(SwapErrorType.INVALID_RECIPIENT);
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
166
222
|
}
|
|
@@ -17,3 +17,4 @@ export declare function estimateFeeForTransaction(validationResponse: SWTransact
|
|
|
17
17
|
export declare function checkSigningAccountForTransaction(validationResponse: SWTransactionResponse, chainInfoMap: Record<string, _ChainInfo>): void;
|
|
18
18
|
export declare function checkBalanceWithTransactionFee(validationResponse: SWTransactionResponse, transactionInput: SWTransactionInput, nativeTokenInfo: _ChainAsset, nativeTokenAvailable: AmountData): void;
|
|
19
19
|
export declare function checkTonAddressBounceableAndAccountNotActive(tonApi: _TonApi, validationResponse: SWTransactionResponse): Promise<void>;
|
|
20
|
+
export declare function validateXcmMinAmountToMythos(destChain: string, destToken: string, amount: string): TransactionError | undefined;
|
|
@@ -315,7 +315,8 @@ export async function estimateFeeForTransaction(validationResponse, transaction,
|
|
|
315
315
|
if (transaction) {
|
|
316
316
|
try {
|
|
317
317
|
if (isSubstrateTransaction(transaction)) {
|
|
318
|
-
|
|
318
|
+
var _validationResponse$x;
|
|
319
|
+
estimateFee.value = (_validationResponse$x = validationResponse.xcmFeeDryRun) !== null && _validationResponse$x !== void 0 ? _validationResponse$x : (await transaction.paymentInfo(validationResponse.address)).partialFee.toString();
|
|
319
320
|
} else if (isTonTransaction(transaction)) {
|
|
320
321
|
estimateFee.value = transaction.estimateFee; // todo: might need to update logic estimate fee inside for future actions excluding normal transfer Ton and Jetton
|
|
321
322
|
} else if (isCardanoTransaction(transaction)) {
|
|
@@ -443,4 +444,14 @@ function isTonAddressBounceable(address) {
|
|
|
443
444
|
async function isAccountActive(tonApi, address) {
|
|
444
445
|
const state = await tonApi.getAccountState(address);
|
|
445
446
|
return state === 'active';
|
|
447
|
+
}
|
|
448
|
+
export function validateXcmMinAmountToMythos(destChain, destToken, amount) {
|
|
449
|
+
const MYTHOS_DESTINATION_FEE = '2500000000000000000';
|
|
450
|
+
const errorMsg = 'Enter an amount higher than 2.5 MYTH to pay cross-chain fee and avoid your MYTH being lost after the transaction';
|
|
451
|
+
if (destChain === 'mythos' && destToken === 'mythos-NATIVE-MYTH') {
|
|
452
|
+
if (BigN(amount).lte(MYTHOS_DESTINATION_FEE)) {
|
|
453
|
+
return new TransactionError(TransferTxErrorType.NOT_ENOUGH_VALUE, t(errorMsg));
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return undefined;
|
|
446
457
|
}
|
|
@@ -55,4 +55,5 @@ export declare function _isAvailBridgeXcm(originChainInfo: _ChainInfo, destChain
|
|
|
55
55
|
export declare function _isMythosFromHydrationToMythos(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): boolean;
|
|
56
56
|
export declare function _isPolygonBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
57
57
|
export declare function _isPosBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
58
|
+
export declare function _isAcrossBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
58
59
|
export declare function _adaptX1Interior(_assetIdentifier: Record<string, any>, version: number): Record<string, any>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
|
+
import { _isAcrossChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
|
|
5
6
|
import { isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
6
7
|
import { _isPolygonChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
7
8
|
import { _isPosChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
|
|
@@ -127,7 +128,9 @@ export function _isPolygonBridgeXcm(originChainInfo, destChainInfo) {
|
|
|
127
128
|
export function _isPosBridgeXcm(originChainInfo, destChainInfo) {
|
|
128
129
|
return _isPosChainBridge(originChainInfo.slug, destChainInfo.slug);
|
|
129
130
|
}
|
|
130
|
-
|
|
131
|
+
export function _isAcrossBridgeXcm(originChainInfo, destChainInfo) {
|
|
132
|
+
return _isAcrossChainBridge(originChainInfo.slug, destChainInfo.slug);
|
|
133
|
+
}
|
|
131
134
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
132
135
|
|
|
133
136
|
function _getMultiLocationParent(originChainInfo, isWithinSameConsensus) {
|
package/core/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
|
-
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { ExtrinsicType, SufficientChainsDetails } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { LedgerMustCheckType, ValidateRecipientParams } from '@subwallet/extension-base/core/types';
|
|
4
4
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
5
|
import { AccountJson } from '@subwallet/extension-base/types';
|
|
@@ -15,4 +15,4 @@ export declare function _isValidTonAddressFormat(validateRecipientParams: Valida
|
|
|
15
15
|
export declare function _isValidCardanoAddressFormat(validateRecipientParams: ValidateRecipientParams): string;
|
|
16
16
|
export declare function _isNotDuplicateAddress(validateRecipientParams: ValidateRecipientParams): string;
|
|
17
17
|
export declare function _isSupportLedgerAccount(validateRecipientParams: ValidateRecipientParams): string;
|
|
18
|
-
export declare const _isSufficientToken: (tokenInfo: _ChainAsset, substrateApi: _SubstrateApi) => Promise<boolean>;
|
|
18
|
+
export declare const _isSufficientToken: (tokenInfo: _ChainAsset, substrateApi: _SubstrateApi, sufficientChain: SufficientChainsDetails) => Promise<boolean>;
|
package/core/utils.js
CHANGED
|
@@ -5,7 +5,6 @@ import { _AssetType } from '@subwallet/chain-list/types';
|
|
|
5
5
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
|
|
7
7
|
import { tonAddressInfo } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
|
|
8
|
-
import { SUFFICIENT_CHAIN } from '@subwallet/extension-base/services/chain-service/constants';
|
|
9
8
|
import { _getTokenOnChainAssetId, _getXcmAssetMultilocation, _isBridgedToken, _isChainCardanoCompatible, _isChainEvmCompatible, _isChainSubstrateCompatible, _isChainTonCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
9
|
import { isAddressAndChainCompatible, isSameAddress, reformatAddress } from '@subwallet/extension-base/utils';
|
|
11
10
|
import { isAddress, isCardanoTestnetAddress, isTonAddress } from '@subwallet/keyring';
|
|
@@ -132,27 +131,49 @@ export function _isSupportLedgerAccount(validateRecipientParams) {
|
|
|
132
131
|
}
|
|
133
132
|
return '';
|
|
134
133
|
}
|
|
135
|
-
export const _isSufficientToken = async (tokenInfo, substrateApi) => {
|
|
136
|
-
|
|
137
|
-
if (
|
|
134
|
+
export const _isSufficientToken = async (tokenInfo, substrateApi, sufficientChain) => {
|
|
135
|
+
var _tokenInfo$metadata;
|
|
136
|
+
if (tokenInfo.assetType !== _AssetType.NATIVE) {
|
|
138
137
|
const assetId = _isBridgedToken(tokenInfo) ? _getXcmAssetMultilocation(tokenInfo) : _getTokenOnChainAssetId(tokenInfo);
|
|
138
|
+
const chainSlug = tokenInfo.originChain;
|
|
139
139
|
const queryParams = {
|
|
140
140
|
section: 'query',
|
|
141
|
-
module: 'foreignAssets',
|
|
142
|
-
method: 'asset',
|
|
143
141
|
args: [assetId]
|
|
144
142
|
};
|
|
145
|
-
if (
|
|
143
|
+
if (sufficientChain.assetHubPallet.includes(chainSlug)) {
|
|
144
|
+
if (!_isBridgedToken(tokenInfo)) {
|
|
145
|
+
queryParams.module = 'assets';
|
|
146
|
+
} else {
|
|
147
|
+
queryParams.module = 'foreignAssets';
|
|
148
|
+
}
|
|
149
|
+
queryParams.method = 'asset';
|
|
150
|
+
}
|
|
151
|
+
if (sufficientChain.assetRegistryPallet.includes(chainSlug)) {
|
|
152
|
+
queryParams.module = 'assetRegistry';
|
|
153
|
+
queryParams.method = 'assets';
|
|
154
|
+
}
|
|
155
|
+
if (sufficientChain.assetsPallet.includes(chainSlug)) {
|
|
146
156
|
queryParams.module = 'assets';
|
|
157
|
+
queryParams.method = 'asset';
|
|
158
|
+
}
|
|
159
|
+
if (sufficientChain.foreignAssetsPallet.includes(chainSlug)) {
|
|
160
|
+
queryParams.module = 'foreignAsset';
|
|
161
|
+
queryParams.method = 'asset';
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
if (queryParams.method && queryParams.module) {
|
|
165
|
+
const metadata = await substrateApi.makeRpcQuery(queryParams);
|
|
166
|
+
if ((metadata === null || metadata === void 0 ? void 0 : metadata.isSufficient) !== undefined) {
|
|
167
|
+
return metadata === null || metadata === void 0 ? void 0 : metadata.isSufficient;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
} catch (e) {
|
|
171
|
+
console.error(e);
|
|
147
172
|
}
|
|
148
|
-
const metadata = await substrateApi.makeRpcQuery(queryParams);
|
|
149
|
-
return metadata.isSufficient;
|
|
150
173
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
// }
|
|
156
|
-
|
|
174
|
+
if ((_tokenInfo$metadata = tokenInfo.metadata) !== null && _tokenInfo$metadata !== void 0 && _tokenInfo$metadata.isSufficient) {
|
|
175
|
+
var _tokenInfo$metadata2;
|
|
176
|
+
return (_tokenInfo$metadata2 = tokenInfo.metadata) === null || _tokenInfo$metadata2 === void 0 ? void 0 : _tokenInfo$metadata2.isSufficient;
|
|
177
|
+
}
|
|
157
178
|
return false;
|
|
158
179
|
};
|
|
@@ -129,6 +129,7 @@ export default class KoniExtension {
|
|
|
129
129
|
private removeCustomChain;
|
|
130
130
|
private disableChain;
|
|
131
131
|
private enableChain;
|
|
132
|
+
private enableChainWithPriorityAssets;
|
|
132
133
|
private reconnectChain;
|
|
133
134
|
private validateNetwork;
|
|
134
135
|
private resetDefaultNetwork;
|
|
@@ -255,7 +256,6 @@ export default class KoniExtension {
|
|
|
255
256
|
private subscribeBuyTokens;
|
|
256
257
|
private subscribeBuyServices;
|
|
257
258
|
private subscribeSwapPairs;
|
|
258
|
-
private getOptimalSwapProcessOnSelectQuote;
|
|
259
259
|
private handleSwapRequest;
|
|
260
260
|
private handleSwapRequestV2;
|
|
261
261
|
private getLatestSwapQuote;
|