@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
|
@@ -5,11 +5,12 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
|
|
|
5
5
|
import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { ALL_ACCOUNT_KEY, XCM_FEE_RATIO, XCM_MIN_AMOUNT_RATIO } from '@subwallet/extension-base/constants';
|
|
7
7
|
import { YIELD_POOL_STAT_REFRESH_INTERVAL } from '@subwallet/extension-base/koni/api/yield/helper/utils';
|
|
8
|
-
import {
|
|
8
|
+
import { createXcmExtrinsicV2, dryRunXcmExtrinsicV2 } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
|
|
9
9
|
import { _getAssetDecimals, _getAssetExistentialDeposit, _getAssetName, _getAssetSymbol, _getChainNativeTokenSlug, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
10
|
import { BasicTxErrorType, YieldStepType, YieldValidationStatus } from '@subwallet/extension-base/types';
|
|
11
11
|
import { createPromiseHandler, formatNumber } from '@subwallet/extension-base/utils';
|
|
12
12
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
13
|
+
import BigN from 'bignumber.js';
|
|
13
14
|
import { t } from 'i18next';
|
|
14
15
|
import { BN, BN_TEN, BN_ZERO, noop } from '@polkadot/util';
|
|
15
16
|
import BasePoolHandler from "./base.js";
|
|
@@ -219,7 +220,7 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
|
|
|
219
220
|
const xcmOriginSubstrateApi = await this.state.getSubstrateApi(altInputTokenInfo.originChain).isReady;
|
|
220
221
|
const id = getId();
|
|
221
222
|
const feeInfo = await this.state.feeService.subscribeChainFee(id, altChainInfo.slug, 'substrate');
|
|
222
|
-
const
|
|
223
|
+
const xcmRequest = {
|
|
223
224
|
sender: address,
|
|
224
225
|
originTokenInfo: altInputTokenInfo,
|
|
225
226
|
destinationTokenInfo: inputTokenInfo,
|
|
@@ -229,16 +230,20 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
|
|
|
229
230
|
originChain: altChainInfo,
|
|
230
231
|
substrateApi: xcmOriginSubstrateApi,
|
|
231
232
|
feeInfo
|
|
232
|
-
}
|
|
233
|
-
const _xcmFeeInfo = await xcmTransfer.paymentInfo(address);
|
|
234
|
-
const xcmFeeInfo = _xcmFeeInfo.toPrimitive();
|
|
235
|
-
// TODO: calculate fee for destination chain
|
|
233
|
+
};
|
|
236
234
|
|
|
235
|
+
// TODO: calculate fee for destination chain
|
|
236
|
+
let xcmFee;
|
|
237
|
+
const xcmFeeByDryRun = await dryRunXcmExtrinsicV2(xcmRequest);
|
|
238
|
+
if (xcmFeeByDryRun.fee) {
|
|
239
|
+
xcmFee = BigN(xcmFeeByDryRun.fee).multipliedBy(XCM_MIN_AMOUNT_RATIO).toFixed(0, 1);
|
|
240
|
+
} else {
|
|
241
|
+
throw new Error('Error estimating XCM fee');
|
|
242
|
+
}
|
|
237
243
|
const fee = {
|
|
238
244
|
slug: altInputTokenSlug,
|
|
239
|
-
amount:
|
|
245
|
+
amount: xcmFee
|
|
240
246
|
};
|
|
241
|
-
|
|
242
247
|
let bnTransferAmount = bnAmount.sub(bnInputTokenBalance);
|
|
243
248
|
if (_isNativeToken(altInputTokenInfo)) {
|
|
244
249
|
const bnXcmFee = new BN(fee.amount || 0); // xcm fee is paid in native token but swap token is not always native token
|
|
@@ -442,7 +447,7 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
|
|
|
442
447
|
const bnTotalAmount = bnAmount.sub(bnInputTokenBalance).add(bnXcmFee);
|
|
443
448
|
const id = getId();
|
|
444
449
|
const feeInfo = await this.state.feeService.subscribeChainFee(id, originChainInfo.slug, 'substrate');
|
|
445
|
-
const
|
|
450
|
+
const xcmRequest = {
|
|
446
451
|
destinationTokenInfo,
|
|
447
452
|
originTokenInfo,
|
|
448
453
|
recipient: address,
|
|
@@ -452,7 +457,11 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
|
|
|
452
457
|
originChain: originChainInfo,
|
|
453
458
|
destinationChain: this.chainInfo,
|
|
454
459
|
feeInfo
|
|
455
|
-
}
|
|
460
|
+
};
|
|
461
|
+
const extrinsic = await createXcmExtrinsicV2(xcmRequest);
|
|
462
|
+
if (!extrinsic) {
|
|
463
|
+
throw new Error('Error handling XCM extrinsic');
|
|
464
|
+
}
|
|
456
465
|
const xcmData = {
|
|
457
466
|
originNetworkKey: originChainInfo.slug,
|
|
458
467
|
destinationNetworkKey: destinationTokenInfo.originChain,
|
|
@@ -6,6 +6,7 @@ import { PersistDataServiceInterface, ServiceStatus, StoppableServiceInterface }
|
|
|
6
6
|
import { EarningRewardHistoryItem, EarningRewardItem, EarningRewardJson, HandleYieldStepData, HandleYieldStepParams, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, RequestEarningSlippage, RequestStakeCancelWithdrawal, RequestStakeClaimReward, RequestYieldLeave, RequestYieldWithdrawal, ResponseEarlyValidateYield, TransactionData, ValidateYieldProcessParams, YieldPoolInfo, YieldPoolTarget, YieldPositionInfo } from '@subwallet/extension-base/types';
|
|
7
7
|
import { PromiseHandler } from '@subwallet/extension-base/utils';
|
|
8
8
|
import { BehaviorSubject } from 'rxjs';
|
|
9
|
+
import { EarningSlippageResult } from './handlers/native-staking/dtao';
|
|
9
10
|
import { BasePoolHandler } from './handlers';
|
|
10
11
|
export default class EarningService implements StoppableServiceInterface, PersistDataServiceInterface {
|
|
11
12
|
protected readonly state: KoniState;
|
|
@@ -98,6 +99,6 @@ export default class EarningService implements StoppableServiceInterface, Persis
|
|
|
98
99
|
handleYieldWithdraw(params: RequestYieldWithdrawal): Promise<TransactionData>;
|
|
99
100
|
handleYieldCancelUnstake(params: RequestStakeCancelWithdrawal): Promise<TransactionData>;
|
|
100
101
|
handleYieldClaimReward(params: RequestStakeClaimReward): Promise<TransactionData>;
|
|
101
|
-
yieldGetEarningSlippage(params: RequestEarningSlippage): Promise<
|
|
102
|
+
yieldGetEarningSlippage(params: RequestEarningSlippage): Promise<EarningSlippageResult>;
|
|
102
103
|
resetWallet(): Promise<void>;
|
|
103
104
|
}
|
|
@@ -755,8 +755,9 @@ export default class EarningService {
|
|
|
755
755
|
} = params;
|
|
756
756
|
const handler = this.getPoolHandler(slug);
|
|
757
757
|
const netuid = (_params$poolInfo$meta = params.poolInfo.metadata.subnetData) === null || _params$poolInfo$meta === void 0 ? void 0 : _params$poolInfo$meta.netuid;
|
|
758
|
+
const slippage = params.slippage;
|
|
758
759
|
if (handler) {
|
|
759
|
-
return handler.handleYieldLeave(params.fastLeave, params.amount, params.address, params.selectedTarget, netuid);
|
|
760
|
+
return handler.handleYieldLeave(params.fastLeave, params.amount, params.address, params.selectedTarget, netuid, slippage);
|
|
760
761
|
} else {
|
|
761
762
|
return Promise.reject(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
|
|
762
763
|
}
|
|
@@ -11,4 +11,5 @@ export declare const fetchOnlineFeeData: (chainId: number, networkKey: string, u
|
|
|
11
11
|
export declare const recalculateGasPrice: (_price: string, chain: string) => string;
|
|
12
12
|
export declare const getEIP1559GasFee: (baseFee: BigN, maxPriorityFee: BigN, blockNumber: number, blockTime: number) => EvmEIP1559FeeOption;
|
|
13
13
|
export declare const calculateGasFeeParams: (web3: _EvmApi, networkKey: string, useOnline?: boolean, useInfura?: boolean) => Promise<EvmFeeInfo>;
|
|
14
|
+
export declare const enforceMinOneTip: (feeOptionDetail: EvmEIP1559FeeOption) => EvmEIP1559FeeOption;
|
|
14
15
|
export declare const calculateToAmountByReservePool: (api: ApiPromise, fromToken: _ChainAsset, toToken: _ChainAsset, fromAmount: string) => Promise<string>;
|
|
@@ -10,7 +10,7 @@ const INFURA_API_KEY = process.env.INFURA_API_KEY || '';
|
|
|
10
10
|
const INFURA_API_KEY_SECRET = process.env.INFURA_API_KEY_SECRET || '';
|
|
11
11
|
const INFURA_AUTH = 'Basic ' + Buffer.from(INFURA_API_KEY + ':' + INFURA_API_KEY_SECRET).toString('base64');
|
|
12
12
|
export const FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE = 105; // percentage
|
|
13
|
-
|
|
13
|
+
const EIP1559_MIN_PRIORITY_FEE = '1';
|
|
14
14
|
export const parseInfuraFee = (info, threshold) => {
|
|
15
15
|
const base = new BigN(info.estimatedBaseFee).multipliedBy(BN_WEI);
|
|
16
16
|
const thresholdBN = new BigN(threshold.busyThreshold).multipliedBy(BN_WEI);
|
|
@@ -161,15 +161,18 @@ export const calculateGasFeeParams = async (web3, networkKey, useOnline = true,
|
|
|
161
161
|
const slowPriorityFee = history.reward.reduce((previous, rewards) => previous.plus(rewards[0]), BN_ZERO).dividedBy(numBlock).decimalPlaces(0);
|
|
162
162
|
const averagePriorityFee = history.reward.reduce((previous, rewards) => previous.plus(rewards[1]), BN_ZERO).dividedBy(numBlock).decimalPlaces(0);
|
|
163
163
|
const fastPriorityFee = history.reward.reduce((previous, rewards) => previous.plus(rewards[2]), BN_ZERO).dividedBy(numBlock).decimalPlaces(0);
|
|
164
|
+
if (slowPriorityFee.eq(0) && averagePriorityFee.eq(0) && fastPriorityFee.eq(0)) {
|
|
165
|
+
throw new Error('Fee rates are currently same for all levels');
|
|
166
|
+
}
|
|
164
167
|
return {
|
|
165
168
|
type: 'evm',
|
|
166
169
|
gasPrice: undefined,
|
|
167
170
|
baseGasFee: baseGasFee.toString(),
|
|
168
171
|
busyNetwork,
|
|
169
172
|
options: {
|
|
170
|
-
slow: getEIP1559GasFee(baseGasFee, slowPriorityFee, 10, blockTime),
|
|
171
|
-
average: getEIP1559GasFee(baseGasFee, averagePriorityFee, 5, blockTime),
|
|
172
|
-
fast: getEIP1559GasFee(baseGasFee, fastPriorityFee, 3, blockTime),
|
|
173
|
+
slow: enforceMinOneTip(getEIP1559GasFee(baseGasFee, slowPriorityFee, 10, blockTime)),
|
|
174
|
+
average: enforceMinOneTip(getEIP1559GasFee(baseGasFee, averagePriorityFee, 5, blockTime)),
|
|
175
|
+
fast: enforceMinOneTip(getEIP1559GasFee(baseGasFee, fastPriorityFee, 3, blockTime)),
|
|
173
176
|
default: busyNetwork ? 'average' : 'slow'
|
|
174
177
|
}
|
|
175
178
|
};
|
|
@@ -185,6 +188,13 @@ export const calculateGasFeeParams = async (web3, networkKey, useOnline = true,
|
|
|
185
188
|
};
|
|
186
189
|
}
|
|
187
190
|
};
|
|
191
|
+
export const enforceMinOneTip = feeOptionDetail => {
|
|
192
|
+
if (feeOptionDetail.maxPriorityFeePerGas === '0') {
|
|
193
|
+
feeOptionDetail.maxPriorityFeePerGas = EIP1559_MIN_PRIORITY_FEE;
|
|
194
|
+
return feeOptionDetail;
|
|
195
|
+
}
|
|
196
|
+
return feeOptionDetail;
|
|
197
|
+
};
|
|
188
198
|
export const calculateToAmountByReservePool = async (api, fromToken, toToken, fromAmount) => {
|
|
189
199
|
const reserve = await getReserveForPool(api, fromToken, toToken);
|
|
190
200
|
return estimateTokensForPool(fromAmount, reserve);
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
import { COMMON_ASSETS, COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
5
|
import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { CRON_LISTEN_AVAIL_BRIDGE_CLAIM } from '@subwallet/extension-base/constants';
|
|
7
|
-
import {
|
|
7
|
+
import { fetchLatestRemindNotificationTime } from '@subwallet/extension-base/constants/remind-notification-time';
|
|
8
8
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
9
9
|
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants';
|
|
10
10
|
import { NotificationDescriptionMap, NotificationTitleMap, ONE_DAY_MILLISECOND } from '@subwallet/extension-base/services/inapp-notification-service/consts';
|
|
11
11
|
import { NotificationActionType, NotificationTab } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
|
|
12
12
|
import { AvailBridgeSourceChain, fetchAllAvailBridgeClaimable, fetchPolygonBridgeTransactions, hrsToMillisecond } from '@subwallet/extension-base/services/inapp-notification-service/utils';
|
|
13
|
+
import { getTokenPairFromStep } from '@subwallet/extension-base/services/swap-service/utils';
|
|
13
14
|
import { ProcessType, YieldPoolType } from '@subwallet/extension-base/types';
|
|
14
15
|
import { formatNumber, getAddressesByChainType, reformatAddress } from '@subwallet/extension-base/utils';
|
|
15
16
|
import { isSubstrateAddress } from '@subwallet/keyring';
|
|
@@ -148,7 +149,7 @@ export class InappNotificationService {
|
|
|
148
149
|
const [comparedNotifications, remindTimeConfig] = await Promise.all([this.fetchNotificationsByParams({
|
|
149
150
|
notificationTab: NotificationTab.ALL,
|
|
150
151
|
proxyId
|
|
151
|
-
}), await
|
|
152
|
+
}), await fetchLatestRemindNotificationTime()]);
|
|
152
153
|
for (const candidateNotification of notifications) {
|
|
153
154
|
candidateNotification.title = candidateNotification.title.replace('{{accountName}}', accountName);
|
|
154
155
|
if (this.passValidateNotification(candidateNotification, comparedNotifications, remindTimeConfig)) {
|
|
@@ -349,12 +350,17 @@ export class InappNotificationService {
|
|
|
349
350
|
actionType = NotificationActionType.SWAP;
|
|
350
351
|
extrinsicType = ExtrinsicType.SWAP;
|
|
351
352
|
const combineInfo = process.combineInfo;
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
353
|
+
const targetPair = (() => {
|
|
354
|
+
try {
|
|
355
|
+
return getTokenPairFromStep(combineInfo.process.steps) || combineInfo.quote.pair;
|
|
356
|
+
} catch (e) {
|
|
357
|
+
return combineInfo.quote.pair;
|
|
358
|
+
}
|
|
359
|
+
})();
|
|
360
|
+
const fromAsset = this.chainService.getAssetBySlug(targetPair.from);
|
|
361
|
+
const toAsset = this.chainService.getAssetBySlug(targetPair.to);
|
|
356
362
|
title = '[{{accountName}}] SWAPPED {{fromAsset}}'.replace('{{fromAsset}}', fromAsset.symbol);
|
|
357
|
-
description = '{{fromAmount}} {{fromAsset}}
|
|
363
|
+
description = '{{fromAmount}} {{fromAsset}} swapped for {{toAmount}} {{toAsset}}. Click to view details'.replace('{{fromAmount}}', formatNumber(combineInfo.quote.fromAmount, fromAsset.decimals || 0)).replace('{{fromAsset}}', fromAsset.symbol).replace('{{toAmount}}', formatNumber(combineInfo.quote.toAmount, toAsset.decimals || 0)).replace('{{toAsset}}', toAsset.symbol);
|
|
358
364
|
} else {
|
|
359
365
|
actionType = NotificationActionType.EARNING;
|
|
360
366
|
extrinsicType = ExtrinsicType.JOIN_YIELD_POOL; // Not used
|
|
@@ -150,7 +150,7 @@ export class AccountLedgerHandler extends AccountBaseHandler {
|
|
|
150
150
|
}
|
|
151
151
|
if (Object.keys(slugMap).length) {
|
|
152
152
|
for (const chainSlug of Object.keys(slugMap)) {
|
|
153
|
-
this.state.
|
|
153
|
+
this.state.enableChainWithPriorityAssets(chainSlug);
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
return true;
|
|
@@ -88,6 +88,7 @@ export declare class AccountState {
|
|
|
88
88
|
updateMetadataForProxy(): void;
|
|
89
89
|
findNetworkKeyByGenesisHash(genesisHash?: string): string | undefined;
|
|
90
90
|
enableChain(slug: string): void;
|
|
91
|
+
enableChainWithPriorityAssets(slug: string): void;
|
|
91
92
|
resetWallet(): void;
|
|
92
93
|
}
|
|
93
94
|
export {};
|
|
@@ -619,6 +619,9 @@ export class AccountState {
|
|
|
619
619
|
enableChain(slug) {
|
|
620
620
|
this.koniState.enableChain(slug, true).catch(console.error);
|
|
621
621
|
}
|
|
622
|
+
enableChainWithPriorityAssets(slug) {
|
|
623
|
+
this.koniState.enableChainWithPriorityAssets(slug, true).catch(console.error);
|
|
624
|
+
}
|
|
622
625
|
|
|
623
626
|
/* Others */
|
|
624
627
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { _isAssetAutoEnable } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
6
|
+
import { fetchStaticData } from '@subwallet/extension-base/utils';
|
|
7
|
+
// Usage:
|
|
8
|
+
// 1. Disable tokens with a balance of 0
|
|
9
|
+
// 2. Exclude tokens that belong to the popular list
|
|
10
|
+
// 3. Exclude tokens with the "auto enable" attribute
|
|
11
|
+
|
|
12
|
+
export default class DisableZeroBalanceTokens extends BaseMigrationJob {
|
|
13
|
+
async run() {
|
|
14
|
+
const state = this.state;
|
|
15
|
+
try {
|
|
16
|
+
const rawBalanceMap = await state.dbService.getStoredBalance();
|
|
17
|
+
const tokensList = await state.chainService.getAssetSettings();
|
|
18
|
+
const filteredEnabledTokens = Object.entries(tokensList).reduce((acc, [key, value]) => {
|
|
19
|
+
if (value.visible) {
|
|
20
|
+
acc[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return acc;
|
|
23
|
+
}, {});
|
|
24
|
+
const balanceNonZero = rawBalanceMap.filter(item => {
|
|
25
|
+
return BigInt(item.free) + BigInt(item.locked) > 0;
|
|
26
|
+
});
|
|
27
|
+
const priorityTokensMap = (await fetchStaticData('chain-assets/priority-tokens')) || {
|
|
28
|
+
tokenGroup: {},
|
|
29
|
+
token: {}
|
|
30
|
+
};
|
|
31
|
+
const priorityTokensList = priorityTokensMap.token && typeof priorityTokensMap.token === 'object' ? Object.keys(priorityTokensMap.token) : [];
|
|
32
|
+
const autoEnableTokenSlugs = Object.values(this.state.chainService.getAssetRegistry()).filter(asset => _isAssetAutoEnable(asset)).map(asset => asset.slug);
|
|
33
|
+
// Extract the slugs of tokens with balance > 0
|
|
34
|
+
const nonZeroBalanceSlugs = new Set(balanceNonZero.map(item => item.tokenSlug));
|
|
35
|
+
const updatedSettings = structuredClone(tokensList);
|
|
36
|
+
Object.keys(filteredEnabledTokens).forEach(slug => {
|
|
37
|
+
const hasBalance = nonZeroBalanceSlugs.has(slug);
|
|
38
|
+
const isPopularToken = priorityTokensList.includes(slug);
|
|
39
|
+
const isAutoEnableToken = autoEnableTokenSlugs.includes(slug);
|
|
40
|
+
if (!hasBalance && !isPopularToken && !isAutoEnableToken) {
|
|
41
|
+
updatedSettings[slug] = {
|
|
42
|
+
visible: false
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
state.chainService.setAssetSettings(updatedSettings);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -5,6 +5,6 @@ import BaseMigrationJob from '@subwallet/extension-base/services/migration-servi
|
|
|
5
5
|
export default class EnableChain extends BaseMigrationJob {
|
|
6
6
|
async run() {
|
|
7
7
|
const state = this.state;
|
|
8
|
-
await state.
|
|
8
|
+
await state.enableChainWithPriorityAssets(this.slug, true);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import AutoEnableSomeTokens from "./databases/AutoEnableSomeTokens.js";
|
|
5
4
|
import ClearMetadataDatabase from "./databases/ClearMetadataDatabase.js";
|
|
6
5
|
import ClearMetadataForMythos from "./databases/ClearMetadataForMythos.js";
|
|
7
6
|
import MigrateAssetSetting from "./databases/MigrateAssetSetting.js";
|
|
@@ -18,6 +17,7 @@ import MigratePolygonUSDCProvider from "./tokens/MigratePolygonUSDCProvider.js";
|
|
|
18
17
|
import DeleteChain from "./DeleteChain.js";
|
|
19
18
|
import DeleteChainStaking from "./DeleteChainStaking.js";
|
|
20
19
|
import DeleteEarningData from "./DeleteEarningData.js";
|
|
20
|
+
import DisableZeroBalanceTokens from "./DisableZeroBalanceTokens.js";
|
|
21
21
|
import EnableVaraChain from "./EnableVaraChain.js";
|
|
22
22
|
import MigrateAuthUrls from "./MigrateAuthUrls.js";
|
|
23
23
|
import MigrateImportedToken from "./MigrateImportedToken.js";
|
|
@@ -52,7 +52,7 @@ export default {
|
|
|
52
52
|
'1.1.28-01': MigrateEarningVersion,
|
|
53
53
|
'1.1.33-01': MigrateLedgerAccountV2,
|
|
54
54
|
'1.1.41-01': DeleteChainStaking,
|
|
55
|
-
'1.1.46-01': AutoEnableSomeTokens,
|
|
55
|
+
// '1.1.46-01': AutoEnableSomeTokens,
|
|
56
56
|
'1.2.28-01': MigrateAssetSetting,
|
|
57
57
|
'1.2.28-02': MigrateTransactionHistoryBySymbol,
|
|
58
58
|
'1.2.69-01': MigrateRemoveGenesisHash,
|
|
@@ -60,6 +60,7 @@ export default {
|
|
|
60
60
|
'1.2.32-01': MigratePairData,
|
|
61
61
|
'1.3.6-01': MigrateTransactionHistoryBridge,
|
|
62
62
|
'1.3.10-01': ClearMetadataDatabase,
|
|
63
|
+
'1.3.26-01': DisableZeroBalanceTokens,
|
|
63
64
|
[MYTHOS_MIGRATION_KEY]: ClearMetadataForMythos
|
|
64
65
|
// [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
|
|
65
66
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
@@ -2,7 +2,7 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
|
|
|
2
2
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
3
3
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
4
4
|
import FeeService from '@subwallet/extension-base/services/fee-service/service';
|
|
5
|
-
import { BaseStepDetail, CommonOptimalSwapPath, CommonStepFeeInfo,
|
|
5
|
+
import { BaseStepDetail, CommonOptimalSwapPath, CommonStepFeeInfo, OptimalSwapPathParamsV2, SwapProviderId, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types';
|
|
6
6
|
import { SwapBaseInterface } from '../base-handler';
|
|
7
7
|
export declare class AssetHubSwapHandler implements SwapBaseInterface {
|
|
8
8
|
private swapBaseHandler;
|
|
@@ -17,16 +17,9 @@ export declare class AssetHubSwapHandler implements SwapBaseInterface {
|
|
|
17
17
|
get name(): string;
|
|
18
18
|
get slug(): string;
|
|
19
19
|
init(): Promise<void>;
|
|
20
|
-
|
|
21
|
-
getSubmitStep(params: OptimalSwapPathParams): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
22
|
-
getXcmStepV2(params: OptimalSwapPathParamsV2): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
23
|
-
getSwapStepV2(params: OptimalSwapPathParamsV2): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
24
|
-
generateOptimalProcess(params: OptimalSwapPathParams): Promise<CommonOptimalSwapPath>;
|
|
20
|
+
getSubmitStep(params: OptimalSwapPathParamsV2, stepIndex: number): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
25
21
|
generateOptimalProcessV2(params: OptimalSwapPathParamsV2): Promise<CommonOptimalSwapPath>;
|
|
26
|
-
handleXcmStep(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
|
|
27
22
|
handleSubmitStep(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
|
|
28
23
|
handleSwapProcess(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
|
|
29
|
-
validateSwapStep(params: ValidateSwapProcessParams, isXcmOk: boolean, stepIndex: number): Promise<TransactionError[]>;
|
|
30
|
-
validateSwapProcess(params: ValidateSwapProcessParams): Promise<TransactionError[]>;
|
|
31
24
|
validateSwapProcessV2(params: ValidateSwapProcessParams): Promise<TransactionError[]>;
|
|
32
25
|
}
|