@subwallet/extension-base 1.1.54-0 → 1.1.55-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 +21 -1
- package/background/KoniTypes.js +1 -0
- package/background/errors/SwapError.d.ts +6 -0
- package/background/errors/SwapError.js +57 -0
- package/background/errors/TransactionError.js +9 -0
- package/background/types.d.ts +2 -0
- package/cjs/background/KoniTypes.js +1 -0
- package/cjs/background/errors/SwapError.js +64 -0
- package/cjs/background/errors/TransactionError.js +9 -0
- package/cjs/koni/api/staking/bonding/utils.js +35 -6
- package/cjs/koni/background/handlers/Extension.js +214 -102
- package/cjs/koni/background/handlers/State.js +5 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/index.js +6 -3
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/chain-service/index.js +39 -18
- package/cjs/services/chain-service/utils/index.js +15 -4
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/constants/chains.js +4 -2
- package/cjs/services/earning-service/handlers/native-staking/astar.js +4 -3
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +22 -3
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +4 -17
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +4 -17
- package/cjs/services/migration-service/scripts/index.js +3 -3
- package/cjs/services/swap-service/handler/base-handler.js +189 -0
- package/cjs/services/swap-service/handler/chainflip-handler.js +407 -0
- package/cjs/services/swap-service/handler/hydradx-handler.js +531 -0
- package/cjs/services/swap-service/index.js +250 -0
- package/cjs/services/swap-service/utils.js +126 -0
- package/cjs/services/transaction-service/index.js +20 -0
- package/cjs/services/transaction-service/utils.js +6 -0
- package/cjs/types/fee/evm.js +1 -0
- package/cjs/types/fee/fee.js +70 -0
- package/cjs/types/fee/index.js +27 -1
- package/cjs/types/service-base.js +1 -0
- package/cjs/types/swap/index.js +50 -0
- package/cjs/utils/index.js +12 -0
- package/cjs/utils/swap.js +78 -0
- package/koni/api/staking/bonding/utils.d.ts +3 -1
- package/koni/api/staking/bonding/utils.js +32 -6
- package/koni/background/handlers/Extension.d.ts +6 -0
- package/koni/background/handlers/Extension.js +111 -0
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +5 -2
- package/package.json +65 -8
- package/packageInfo.js +1 -1
- package/services/balance-service/index.js +6 -3
- package/services/base/types.d.ts +4 -0
- package/services/chain-service/constants.js +1 -1
- package/services/chain-service/index.d.ts +4 -0
- package/services/chain-service/index.js +21 -1
- package/services/chain-service/utils/index.d.ts +7 -5
- package/services/chain-service/utils/index.js +9 -2
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/constants/chains.d.ts +1 -0
- package/services/earning-service/constants/chains.js +1 -0
- package/services/earning-service/handlers/native-staking/astar.js +4 -3
- package/services/earning-service/handlers/native-staking/relay-chain.js +24 -5
- package/services/event-service/types.d.ts +1 -0
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +4 -17
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +4 -17
- package/services/migration-service/scripts/index.js +3 -3
- package/services/swap-service/handler/base-handler.d.ts +38 -0
- package/services/swap-service/handler/base-handler.js +180 -0
- package/services/swap-service/handler/chainflip-handler.d.ts +30 -0
- package/services/swap-service/handler/chainflip-handler.js +399 -0
- package/services/swap-service/handler/hydradx-handler.d.ts +36 -0
- package/services/swap-service/handler/hydradx-handler.js +522 -0
- package/services/swap-service/index.d.ts +32 -0
- package/services/swap-service/index.js +241 -0
- package/services/swap-service/utils.d.ts +18 -0
- package/services/swap-service/utils.js +105 -0
- package/services/transaction-service/index.js +20 -0
- package/services/transaction-service/utils.d.ts +2 -0
- package/services/transaction-service/utils.js +6 -2
- package/types/fee/evm.d.ts +49 -0
- package/types/fee/evm.js +1 -0
- package/types/fee/fee.d.ts +32 -0
- package/types/fee/fee.js +63 -0
- package/types/fee/index.d.ts +2 -49
- package/types/fee/index.js +5 -1
- package/types/service-base.d.ts +10 -0
- package/types/service-base.js +1 -0
- package/types/swap/index.d.ts +168 -0
- package/types/swap/index.js +41 -0
- package/types/yield/info/chain/target.d.ts +2 -0
- package/types/yield/info/pallet.d.ts +4 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +2 -1
- package/utils/swap.d.ts +3 -0
- package/utils/swap.js +70 -0
|
@@ -51,14 +51,15 @@ export declare function _isSubstrateRelayChain(chainInfo: _ChainInfo): boolean;
|
|
|
51
51
|
export declare function _isSubstrateParaChain(chainInfo: _ChainInfo): boolean;
|
|
52
52
|
export declare function _getEvmAbiExplorer(chainInfo: _ChainInfo): string;
|
|
53
53
|
export declare function _isAssetValuable(assetInfo: _ChainAsset): boolean;
|
|
54
|
-
export declare function _getMultiChainAsset(assetInfo
|
|
55
|
-
export declare function _getAssetPriceId(assetInfo
|
|
54
|
+
export declare function _getMultiChainAsset(assetInfo?: _ChainAsset): string;
|
|
55
|
+
export declare function _getAssetPriceId(assetInfo?: _ChainAsset): string;
|
|
56
|
+
export declare function _getAssetName(assetInfo?: _ChainAsset): string;
|
|
56
57
|
export declare function _getMultiChainAssetPriceId(multiChainAsset: _MultiChainAsset): string;
|
|
57
|
-
export declare function _getAssetSymbol(assetInfo
|
|
58
|
+
export declare function _getAssetSymbol(assetInfo?: _ChainAsset): string;
|
|
58
59
|
export declare function _getMultiChainAssetSymbol(multiChainAsset: _MultiChainAsset): string;
|
|
59
|
-
export declare function _getAssetOriginChain(assetInfo
|
|
60
|
+
export declare function _getAssetOriginChain(assetInfo?: _ChainAsset): string;
|
|
60
61
|
export declare function _getChainName(chainInfo: _ChainInfo): string;
|
|
61
|
-
export declare function _getAssetDecimals(assetInfo
|
|
62
|
+
export declare function _getAssetDecimals(assetInfo?: _ChainAsset): number;
|
|
62
63
|
export declare function _getBlockExplorerFromChain(chainInfo: _ChainInfo): string | undefined;
|
|
63
64
|
export declare function _parseMetadataForSmartContractAsset(contractAddress: string): Record<string, string>;
|
|
64
65
|
export declare function _isChainTestNet(chainInfo: _ChainInfo): boolean;
|
|
@@ -74,6 +75,7 @@ export declare function randomizeProvider(providers: Record<string, string>, exc
|
|
|
74
75
|
providerKey: string;
|
|
75
76
|
providerValue: string;
|
|
76
77
|
};
|
|
78
|
+
export declare function _isAssetCanPayTxFee(chainAsset: _ChainAsset): boolean;
|
|
77
79
|
export declare function updateLatestChainInfo(currentDataMap: _DataMap, latestChainInfoList: _ChainInfo[]): {
|
|
78
80
|
storedChainInfoList: IChain[];
|
|
79
81
|
needUpdateChainApiList: _ChainInfo[];
|
|
@@ -280,6 +280,9 @@ export function _getMultiChainAsset(assetInfo) {
|
|
|
280
280
|
export function _getAssetPriceId(assetInfo) {
|
|
281
281
|
return (assetInfo === null || assetInfo === void 0 ? void 0 : assetInfo.priceId) || '';
|
|
282
282
|
}
|
|
283
|
+
export function _getAssetName(assetInfo) {
|
|
284
|
+
return (assetInfo === null || assetInfo === void 0 ? void 0 : assetInfo.name) || '';
|
|
285
|
+
}
|
|
283
286
|
export function _getMultiChainAssetPriceId(multiChainAsset) {
|
|
284
287
|
return (multiChainAsset === null || multiChainAsset === void 0 ? void 0 : multiChainAsset.priceId) || '';
|
|
285
288
|
}
|
|
@@ -290,13 +293,13 @@ export function _getMultiChainAssetSymbol(multiChainAsset) {
|
|
|
290
293
|
return multiChainAsset.symbol;
|
|
291
294
|
}
|
|
292
295
|
export function _getAssetOriginChain(assetInfo) {
|
|
293
|
-
return assetInfo.originChain;
|
|
296
|
+
return (assetInfo === null || assetInfo === void 0 ? void 0 : assetInfo.originChain) || '';
|
|
294
297
|
}
|
|
295
298
|
export function _getChainName(chainInfo) {
|
|
296
299
|
return chainInfo.name;
|
|
297
300
|
}
|
|
298
301
|
export function _getAssetDecimals(assetInfo) {
|
|
299
|
-
return assetInfo.decimals || 0;
|
|
302
|
+
return (assetInfo === null || assetInfo === void 0 ? void 0 : assetInfo.decimals) || 0;
|
|
300
303
|
}
|
|
301
304
|
export function _getBlockExplorerFromChain(chainInfo) {
|
|
302
305
|
let blockExplorer;
|
|
@@ -395,6 +398,10 @@ export function randomizeProvider(providers, excludedKeys) {
|
|
|
395
398
|
providerValue: selectedProviderValue
|
|
396
399
|
};
|
|
397
400
|
}
|
|
401
|
+
export function _isAssetCanPayTxFee(chainAsset) {
|
|
402
|
+
var _ref, _chainAsset$metadata;
|
|
403
|
+
return (_ref = (_chainAsset$metadata = chainAsset.metadata) === null || _chainAsset$metadata === void 0 ? void 0 : _chainAsset$metadata.canPayTxFee) !== null && _ref !== void 0 ? _ref : false;
|
|
404
|
+
}
|
|
398
405
|
export function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
|
|
399
406
|
const currentChainInfoMap = currentDataMap.chainInfoMap;
|
|
400
407
|
const currentChainStateMap = currentDataMap.chainStateMap;
|
|
@@ -5,7 +5,7 @@ import fetch from 'cross-fetch';
|
|
|
5
5
|
const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
6
6
|
const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
|
|
7
7
|
const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
|
|
8
|
-
const ChainListVersion = '0.2.
|
|
8
|
+
const ChainListVersion = '0.2.55';
|
|
9
9
|
export async function fetchPatchData(slug) {
|
|
10
10
|
try {
|
|
11
11
|
const fetchPromise = fetch(`${fetchDomain}/patch/${ChainListVersion}/${slug}`);
|
|
@@ -13,6 +13,7 @@ export declare const _STAKING_CHAIN_GROUP: {
|
|
|
13
13
|
krest_network: string[];
|
|
14
14
|
manta: string[];
|
|
15
15
|
};
|
|
16
|
+
export declare const MaxEraRewardPointsEras = 14;
|
|
16
17
|
export declare const ST_LIQUID_TOKEN_ABI: Record<string, any>;
|
|
17
18
|
export declare const MANTA_VALIDATOR_POINTS_PER_BLOCK = 20;
|
|
18
19
|
export declare const MANTA_MIN_DELEGATION = 500;
|
|
@@ -18,6 +18,7 @@ export const _STAKING_CHAIN_GROUP = {
|
|
|
18
18
|
krest_network: ['krest_network'],
|
|
19
19
|
manta: ['manta_network']
|
|
20
20
|
};
|
|
21
|
+
export const MaxEraRewardPointsEras = 14;
|
|
21
22
|
|
|
22
23
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
23
24
|
export const ST_LIQUID_TOKEN_ABI = require("./abis/st_liquid_token_abi.json");
|
|
@@ -242,11 +242,12 @@ export default class AstarNativeStakingPoolHandler extends BaseParaNativeStaking
|
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
244
|
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
245
|
+
var _substrateApi$api$que;
|
|
245
246
|
let cancel = false;
|
|
246
247
|
const substrateApi = await this.substrateApi.isReady;
|
|
247
248
|
const defaultInfo = this.baseInfo;
|
|
248
249
|
const chainInfo = this.chainInfo;
|
|
249
|
-
const unsub = await substrateApi.api.query.dappsStaking.ledger.multi(useAddresses, async ledgers => {
|
|
250
|
+
const unsub = await ((_substrateApi$api$que = substrateApi.api.query.dappsStaking) === null || _substrateApi$api$que === void 0 ? void 0 : _substrateApi$api$que.ledger.multi(useAddresses, async ledgers => {
|
|
250
251
|
if (cancel) {
|
|
251
252
|
unsub();
|
|
252
253
|
return;
|
|
@@ -280,10 +281,10 @@ export default class AstarNativeStakingPoolHandler extends BaseParaNativeStaking
|
|
|
280
281
|
}
|
|
281
282
|
}));
|
|
282
283
|
}
|
|
283
|
-
});
|
|
284
|
+
}));
|
|
284
285
|
return () => {
|
|
285
286
|
cancel = true;
|
|
286
|
-
unsub();
|
|
287
|
+
unsub && unsub();
|
|
287
288
|
};
|
|
288
289
|
}
|
|
289
290
|
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
5
|
import { BasicTxErrorType, ExtrinsicType, StakingTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
-
import { calculateAlephZeroValidatorReturn, calculateChainStakedReturnV2, calculateInflation, calculateTernoaValidatorReturn, calculateValidatorStakedReturn, getAvgValidatorEraReward, getCommission, getMaxValidatorErrorMessage, getMinStakeErrorMessage, getSupportedDaysByHistoryDepth } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
6
|
+
import { calculateAlephZeroValidatorReturn, calculateChainStakedReturnV2, calculateInflation, calculateTernoaValidatorReturn, calculateValidatorStakedReturn, getAvgValidatorEraReward, getCommission, getMaxValidatorErrorMessage, getMinStakeErrorMessage, getSupportedDaysByHistoryDepth, getTopValidatorByPoints, getValidatorPointsMap } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
7
7
|
import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
8
|
import { _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
|
-
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants';
|
|
9
|
+
import { _STAKING_CHAIN_GROUP, MaxEraRewardPointsEras } from '@subwallet/extension-base/services/earning-service/constants';
|
|
10
10
|
import { parseIdentity } from '@subwallet/extension-base/services/earning-service/utils';
|
|
11
11
|
import { EarningStatus, UnstakingStatus } from '@subwallet/extension-base/types';
|
|
12
12
|
import { balanceFormatter, formatNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
@@ -274,11 +274,23 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
274
274
|
if (!poolInfo || !poolInfo.statistic) {
|
|
275
275
|
return Promise.reject(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
|
|
276
276
|
}
|
|
277
|
-
const _era = await chainApi.api.query.staking.currentEra();
|
|
277
|
+
const [_era, _activeEraInfo] = await Promise.all([chainApi.api.query.staking.currentEra(), chainApi.api.query.staking.activeEra()]);
|
|
278
278
|
const currentEra = _era.toString();
|
|
279
|
+
const activeEraInfo = _activeEraInfo.toPrimitive();
|
|
280
|
+
const activeEra = activeEraInfo.index;
|
|
279
281
|
const allValidators = [];
|
|
280
282
|
const validatorInfoList = [];
|
|
281
|
-
const
|
|
283
|
+
const maxEraRewardPointsEras = MaxEraRewardPointsEras;
|
|
284
|
+
const endEraForPoints = parseInt(activeEra) - 1;
|
|
285
|
+
let startEraForPoints = endEraForPoints - maxEraRewardPointsEras + 1;
|
|
286
|
+
const [_totalEraStake, _eraStakers, _minBond, _stakingRewards, _validators, ..._eraRewardPoints] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra)), chainApi.api.query.staking.minNominatorBond(), ((_chainApi$api$query$s = chainApi.api.query.stakingRewards) === null || _chainApi$api$query$s === void 0 ? void 0 : _chainApi$api$query$s.data) && chainApi.api.query.stakingRewards.data(), chainApi.api.query.staking.validators.entries(), chainApi.api.query.staking.erasRewardPoints.multi([...Array(maxEraRewardPointsEras).keys()].map(i => i + startEraForPoints))]);
|
|
287
|
+
const eraRewardMap = {};
|
|
288
|
+
for (const item of _eraRewardPoints[0]) {
|
|
289
|
+
eraRewardMap[startEraForPoints] = item.toHuman();
|
|
290
|
+
startEraForPoints++;
|
|
291
|
+
}
|
|
292
|
+
const validatorPointsMap = getValidatorPointsMap(eraRewardMap);
|
|
293
|
+
const topValidatorList = getTopValidatorByPoints(validatorPointsMap);
|
|
282
294
|
|
|
283
295
|
// filter blocked validators
|
|
284
296
|
const validators = _validators;
|
|
@@ -309,6 +321,11 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
309
321
|
const rawValidatorStat = item[1].toHuman();
|
|
310
322
|
const validatorAddress = rawValidatorInfo[1];
|
|
311
323
|
if (!blockValidatorList.includes(validatorAddress)) {
|
|
324
|
+
var _validatorPointsMap$v;
|
|
325
|
+
let isTopQuartile = false;
|
|
326
|
+
if (topValidatorList.includes(validatorAddress)) {
|
|
327
|
+
isTopQuartile = true;
|
|
328
|
+
}
|
|
312
329
|
const rawTotalStake = rawValidatorStat.total;
|
|
313
330
|
const rawOwnStake = rawValidatorStat.own;
|
|
314
331
|
const bnTotalStake = new BN(rawTotalStake.replaceAll(',', ''));
|
|
@@ -333,7 +350,9 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool
|
|
|
333
350
|
blocked: false,
|
|
334
351
|
isVerified: false,
|
|
335
352
|
minBond,
|
|
336
|
-
isCrowded: unlimitedNominatorRewarded ? false : nominatorCount > parseInt(maxNominatorRewarded)
|
|
353
|
+
isCrowded: unlimitedNominatorRewarded ? false : nominatorCount > parseInt(maxNominatorRewarded),
|
|
354
|
+
eraRewardPoint: ((_validatorPointsMap$v = validatorPointsMap[validatorAddress]) !== null && _validatorPointsMap$v !== void 0 ? _validatorPointsMap$v : BN_ZERO).toString(),
|
|
355
|
+
topQuartile: isTopQuartile
|
|
337
356
|
});
|
|
338
357
|
}
|
|
339
358
|
}
|
|
@@ -38,6 +38,7 @@ export interface EventRegistry {
|
|
|
38
38
|
'buy.tokens.ready': [boolean];
|
|
39
39
|
'buy.services.ready': [boolean];
|
|
40
40
|
'earning.ready': [boolean];
|
|
41
|
+
'swap.ready': [boolean];
|
|
41
42
|
}
|
|
42
43
|
export declare type EventType = keyof EventRegistry;
|
|
43
44
|
export declare const COMMON_RELOAD_EVENTS: EventType[];
|
|
@@ -7,23 +7,10 @@ export default class MigrateTransactionHistoryBySymbol extends BaseMigrationJob
|
|
|
7
7
|
const state = this.state;
|
|
8
8
|
try {
|
|
9
9
|
const changeSlugsMap = {
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
'moonriver-LOCAL-xcaUSD': 'moonriver-LOCAL-xcaSeed',
|
|
15
|
-
'moonriver-LOCAL-xckBTC': 'moonriver-LOCAL-xcKBTC',
|
|
16
|
-
'bifrost-LOCAL-aUSD': 'bifrost-LOCAL-KUSD',
|
|
17
|
-
'calamari-LOCAL-aUSD': 'calamari-LOCAL-AUSD',
|
|
18
|
-
'shiden-LOCAL-aUSD': 'shiden-LOCAL-aSEED',
|
|
19
|
-
'shidenEvm-ERC20-aUSD-0xfFFfFFfF00000000000000010000000000000000': 'shidenEvm-ERC20-aSEED-0xfFFfFFfF00000000000000010000000000000000',
|
|
20
|
-
'ethereum_goerli-NATIVE-GoerliETH': 'ethereum_goerli-NATIVE-ETH',
|
|
21
|
-
'binance_test-NATIVE-BNB': 'binance_test-NATIVE-tBNB',
|
|
22
|
-
'pangolin-LOCAL-CKTON': 'pangolin-LOCAL-PKTON',
|
|
23
|
-
'zeta_test-NATIVE-aZETA': 'zeta_test-NATIVE-ZETA',
|
|
24
|
-
'origintrail-NATIVE-OTP': 'origintrail-NATIVE-NEURO',
|
|
25
|
-
'moonbeam-LOCAL-xciBTC': 'moonbeam-LOCAL-xcIBTC',
|
|
26
|
-
'tomochain-NATIVE-TOMO': 'tomochain-NATIVE-VIC'
|
|
10
|
+
'moonbeam-LOCAL-xcaUSD': 'moonbeam-LOCAL-xcaSEED',
|
|
11
|
+
'calamari-LOCAL-AUSD': 'calamari-LOCAL-aSEED',
|
|
12
|
+
'moonriver-LOCAL-xcaSeed': 'moonriver-LOCAL-xcaSEED',
|
|
13
|
+
'bifrost-LOCAL-KUSD': 'bifrost-LOCAL-aSEED'
|
|
27
14
|
};
|
|
28
15
|
const allTxs = [];
|
|
29
16
|
await Promise.all(Object.entries(changeSlugsMap).map(async ([oldSlug, newSlug], i) => {
|
|
@@ -6,23 +6,10 @@ export default class MigrateAssetSetting extends BaseMigrationJob {
|
|
|
6
6
|
async run() {
|
|
7
7
|
try {
|
|
8
8
|
const changeSlugsMap = {
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'moonriver-LOCAL-xcaUSD': 'moonriver-LOCAL-xcaSeed',
|
|
14
|
-
'moonriver-LOCAL-xckBTC': 'moonriver-LOCAL-xcKBTC',
|
|
15
|
-
'bifrost-LOCAL-aUSD': 'bifrost-LOCAL-KUSD',
|
|
16
|
-
'calamari-LOCAL-aUSD': 'calamari-LOCAL-AUSD',
|
|
17
|
-
'shiden-LOCAL-aUSD': 'shiden-LOCAL-aSEED',
|
|
18
|
-
'shidenEvm-ERC20-aUSD-0xfFFfFFfF00000000000000010000000000000000': 'shidenEvm-ERC20-aSEED-0xfFFfFFfF00000000000000010000000000000000',
|
|
19
|
-
'ethereum_goerli-NATIVE-GoerliETH': 'ethereum_goerli-NATIVE-ETH',
|
|
20
|
-
'binance_test-NATIVE-BNB': 'binance_test-NATIVE-tBNB',
|
|
21
|
-
'pangolin-LOCAL-CKTON': 'pangolin-LOCAL-PKTON',
|
|
22
|
-
'zeta_test-NATIVE-aZETA': 'zeta_test-NATIVE-ZETA',
|
|
23
|
-
'origintrail-NATIVE-OTP': 'origintrail-NATIVE-NEURO',
|
|
24
|
-
'moonbeam-LOCAL-xciBTC': 'moonbeam-LOCAL-xcIBTC',
|
|
25
|
-
'tomochain-NATIVE-TOMO': 'tomochain-NATIVE-VIC'
|
|
9
|
+
'moonbeam-LOCAL-xcaUSD': 'moonbeam-LOCAL-xcaSEED',
|
|
10
|
+
'calamari-LOCAL-AUSD': 'calamari-LOCAL-aSEED',
|
|
11
|
+
'moonriver-LOCAL-xcaSeed': 'moonriver-LOCAL-xcaSEED',
|
|
12
|
+
'bifrost-LOCAL-KUSD': 'bifrost-LOCAL-aSEED'
|
|
26
13
|
};
|
|
27
14
|
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
28
15
|
const migratedAssetSetting = {};
|
|
@@ -47,9 +47,9 @@ export default {
|
|
|
47
47
|
'1.1.26-01': MigratePolygonUSDCProvider,
|
|
48
48
|
'1.1.28-01': MigrateEarningVersion,
|
|
49
49
|
'1.1.41-01': DeleteChainStaking,
|
|
50
|
-
'1.1.
|
|
51
|
-
'1.1.
|
|
52
|
-
'1.1.
|
|
50
|
+
'1.1.46-01': AutoEnableSomeTokens,
|
|
51
|
+
'1.1.53-01': MigrateAssetSetting,
|
|
52
|
+
'1.1.53-02': MigrateTransactionHistoryBySymbol
|
|
53
53
|
// [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
|
|
54
54
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
55
55
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
|
|
2
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
|
+
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
4
|
+
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
5
|
+
import { BaseStepDetail } from '@subwallet/extension-base/types/service-base';
|
|
6
|
+
import { GenSwapStepFunc, OptimalSwapPath, OptimalSwapPathParams, SwapEarlyValidation, SwapFeeInfo, SwapProvider, SwapQuote, SwapRequest, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types/swap';
|
|
7
|
+
export interface SwapBaseInterface {
|
|
8
|
+
getSwapQuote: (request: SwapRequest) => Promise<SwapQuote | SwapError>;
|
|
9
|
+
generateOptimalProcess: (params: OptimalSwapPathParams) => Promise<OptimalSwapPath>;
|
|
10
|
+
getSubmitStep: (params: OptimalSwapPathParams) => Promise<[BaseStepDetail, SwapFeeInfo] | undefined>;
|
|
11
|
+
validateSwapRequest: (request: SwapRequest) => Promise<SwapEarlyValidation>;
|
|
12
|
+
validateSwapProcess: (params: ValidateSwapProcessParams) => Promise<TransactionError[]>;
|
|
13
|
+
handleSwapProcess: (params: SwapSubmitParams) => Promise<SwapSubmitStepData>;
|
|
14
|
+
handleSubmitStep: (params: SwapSubmitParams) => Promise<SwapSubmitStepData>;
|
|
15
|
+
isReady?: boolean;
|
|
16
|
+
init?: () => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface SwapBaseHandlerInitParams {
|
|
19
|
+
providerSlug: string;
|
|
20
|
+
providerName: string;
|
|
21
|
+
chainService: ChainService;
|
|
22
|
+
balanceService: BalanceService;
|
|
23
|
+
}
|
|
24
|
+
export declare class SwapBaseHandler {
|
|
25
|
+
private readonly providerSlug;
|
|
26
|
+
private readonly providerName;
|
|
27
|
+
chainService: ChainService;
|
|
28
|
+
balanceService: BalanceService;
|
|
29
|
+
constructor({ balanceService, chainService, providerName, providerSlug }: SwapBaseHandlerInitParams);
|
|
30
|
+
generateOptimalProcess(params: OptimalSwapPathParams, genStepFuncList: GenSwapStepFunc[]): Promise<OptimalSwapPath>;
|
|
31
|
+
validateXcmStep(params: ValidateSwapProcessParams, stepIndex: number): Promise<TransactionError[]>;
|
|
32
|
+
validateTokenApproveStep(params: ValidateSwapProcessParams, stepIndex: number): Promise<TransactionError[]>;
|
|
33
|
+
validateSetFeeTokenStep(params: ValidateSwapProcessParams, stepIndex: number): Promise<TransactionError[]>;
|
|
34
|
+
validateSwapStep(params: ValidateSwapProcessParams, isXcmOk: boolean, stepIndex: number): Promise<TransactionError[]>;
|
|
35
|
+
get name(): string;
|
|
36
|
+
get slug(): string;
|
|
37
|
+
get providerInfo(): SwapProvider;
|
|
38
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
|
+
import { BasicTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
+
import { _getAssetDecimals, _getTokenMinAmount, _isChainEvmCompatible, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
+
import { DEFAULT_SWAP_FIRST_STEP, getSwapAlternativeAsset, MOCK_SWAP_FEE } from '@subwallet/extension-base/services/swap-service/utils';
|
|
8
|
+
import { SwapErrorType, SwapFeeType } from '@subwallet/extension-base/types/swap';
|
|
9
|
+
import { formatNumber } from '@subwallet/extension-base/utils';
|
|
10
|
+
import BigNumber from 'bignumber.js';
|
|
11
|
+
import { t } from 'i18next';
|
|
12
|
+
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
13
|
+
export class SwapBaseHandler {
|
|
14
|
+
constructor({
|
|
15
|
+
balanceService,
|
|
16
|
+
chainService,
|
|
17
|
+
providerName,
|
|
18
|
+
providerSlug
|
|
19
|
+
}) {
|
|
20
|
+
this.providerName = providerName;
|
|
21
|
+
this.providerSlug = providerSlug;
|
|
22
|
+
this.chainService = chainService;
|
|
23
|
+
this.balanceService = balanceService;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// public abstract getSwapQuote(request: SwapRequest): Promise<SwapQuote | SwapError>;
|
|
27
|
+
async generateOptimalProcess(params, genStepFuncList) {
|
|
28
|
+
const result = {
|
|
29
|
+
totalFee: [MOCK_SWAP_FEE],
|
|
30
|
+
steps: [DEFAULT_SWAP_FIRST_STEP]
|
|
31
|
+
};
|
|
32
|
+
try {
|
|
33
|
+
for (const genStepFunc of genStepFuncList) {
|
|
34
|
+
const step = await genStepFunc.bind(this, params)();
|
|
35
|
+
if (step) {
|
|
36
|
+
result.steps.push({
|
|
37
|
+
id: result.steps.length,
|
|
38
|
+
...step[0]
|
|
39
|
+
});
|
|
40
|
+
result.totalFee.push(step[1]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
} catch (e) {
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async validateXcmStep(params, stepIndex) {
|
|
49
|
+
const bnAmount = new BigNumber(params.selectedQuote.fromAmount);
|
|
50
|
+
const swapPair = params.selectedQuote.pair;
|
|
51
|
+
const alternativeAssetSlug = getSwapAlternativeAsset(swapPair);
|
|
52
|
+
if (!alternativeAssetSlug) {
|
|
53
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
54
|
+
}
|
|
55
|
+
const alternativeAsset = this.chainService.getAssetBySlug(alternativeAssetSlug);
|
|
56
|
+
const fromAsset = this.chainService.getAssetBySlug(swapPair.from);
|
|
57
|
+
const [alternativeAssetBalance, fromAssetBalance] = await Promise.all([this.balanceService.getTokenFreeBalance(params.address, alternativeAsset.originChain, alternativeAssetSlug), this.balanceService.getTokenFreeBalance(params.address, fromAsset.originChain, fromAsset.slug)]);
|
|
58
|
+
const bnAlternativeAssetBalance = new BigNumber(alternativeAssetBalance.value);
|
|
59
|
+
const bnFromAssetBalance = new BigNumber(fromAssetBalance.value);
|
|
60
|
+
const xcmFeeComponent = params.process.totalFee[stepIndex].feeComponent[0]; // todo: can do better than indexing
|
|
61
|
+
const xcmFee = new BigNumber(xcmFeeComponent.amount || '0');
|
|
62
|
+
let xcmAmount = bnAmount.minus(bnFromAssetBalance);
|
|
63
|
+
if (_isNativeToken(alternativeAsset)) {
|
|
64
|
+
xcmAmount = xcmAmount.plus(xcmFee);
|
|
65
|
+
}
|
|
66
|
+
const alternativeTokenMinAmount = new BigNumber(alternativeAsset.minAmount || '0');
|
|
67
|
+
if (!bnAlternativeAssetBalance.minus(xcmAmount).gte(alternativeTokenMinAmount)) {
|
|
68
|
+
const maxBn = bnFromAssetBalance.plus(new BigNumber(alternativeAssetBalance.value)).minus(xcmFee).minus(alternativeTokenMinAmount);
|
|
69
|
+
const maxValue = formatNumber(maxBn.toString(), fromAsset.decimals || 0);
|
|
70
|
+
const altInputTokenInfo = this.chainService.getAssetBySlug(alternativeAssetSlug);
|
|
71
|
+
const symbol = altInputTokenInfo.symbol;
|
|
72
|
+
const alternativeChain = this.chainService.getChainInfoByKey(altInputTokenInfo.originChain);
|
|
73
|
+
const chain = this.chainService.getChainInfoByKey(fromAsset.originChain);
|
|
74
|
+
const inputNetworkName = chain.name;
|
|
75
|
+
const altNetworkName = alternativeChain.name;
|
|
76
|
+
const currentValue = formatNumber(bnFromAssetBalance.toString(), fromAsset.decimals || 0);
|
|
77
|
+
const bnMaxXCM = new BigNumber(alternativeAssetBalance.value).minus(xcmFee).minus(alternativeTokenMinAmount);
|
|
78
|
+
const maxXCMValue = formatNumber(bnMaxXCM.toString(), fromAsset.decimals || 0);
|
|
79
|
+
if (maxBn.lte(0) || bnFromAssetBalance.lte(0) || bnMaxXCM.lte(0)) {
|
|
80
|
+
return [new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE, t(`Insufficient balance. Deposit ${fromAsset.symbol} and try again.`))];
|
|
81
|
+
}
|
|
82
|
+
return [new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE, t('You can only enter a maximum of {{maxValue}} {{symbol}}, which is {{currentValue}} {{symbol}} ({{inputNetworkName}}) and {{maxXCMValue}} {{symbol}} ({{altNetworkName}}). Lower your amount and try again.', {
|
|
83
|
+
replace: {
|
|
84
|
+
symbol,
|
|
85
|
+
maxValue,
|
|
86
|
+
inputNetworkName,
|
|
87
|
+
altNetworkName,
|
|
88
|
+
currentValue,
|
|
89
|
+
maxXCMValue
|
|
90
|
+
}
|
|
91
|
+
}))];
|
|
92
|
+
}
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
async validateTokenApproveStep(params, stepIndex) {
|
|
96
|
+
return Promise.resolve([]);
|
|
97
|
+
}
|
|
98
|
+
async validateSetFeeTokenStep(params, stepIndex) {
|
|
99
|
+
if (!params.selectedQuote) {
|
|
100
|
+
return Promise.resolve([new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]);
|
|
101
|
+
}
|
|
102
|
+
const feeInfo = params.process.totalFee[stepIndex];
|
|
103
|
+
const feeAmount = feeInfo.feeComponent[0];
|
|
104
|
+
const feeTokenInfo = this.chainService.getAssetBySlug(feeInfo.defaultFeeToken);
|
|
105
|
+
const feeTokenBalance = await this.balanceService.getTokenFreeBalance(params.address, feeTokenInfo.originChain, feeTokenInfo.slug);
|
|
106
|
+
const bnFeeTokenBalance = new BigNumber(feeTokenBalance.value);
|
|
107
|
+
const bnFeeAmount = new BigNumber(feeAmount.amount);
|
|
108
|
+
if (bnFeeAmount.gte(bnFeeTokenBalance)) {
|
|
109
|
+
return Promise.resolve([new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE)]);
|
|
110
|
+
}
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
async validateSwapStep(params, isXcmOk, stepIndex) {
|
|
114
|
+
if (!params.selectedQuote) {
|
|
115
|
+
return Promise.resolve([new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]);
|
|
116
|
+
}
|
|
117
|
+
const selectedQuote = params.selectedQuote;
|
|
118
|
+
const currentTimestamp = +Date.now();
|
|
119
|
+
if (selectedQuote.aliveUntil <= currentTimestamp) {
|
|
120
|
+
return Promise.resolve([new TransactionError(SwapErrorType.QUOTE_TIMEOUT)]);
|
|
121
|
+
}
|
|
122
|
+
const bnAmount = new BigNumber(params.selectedQuote.fromAmount);
|
|
123
|
+
const fromAsset = this.chainService.getAssetBySlug(params.selectedQuote.pair.from);
|
|
124
|
+
const stepFee = params.process.totalFee[stepIndex].feeComponent;
|
|
125
|
+
const networkFee = stepFee.find(fee => fee.feeType === SwapFeeType.NETWORK_FEE);
|
|
126
|
+
if (!networkFee) {
|
|
127
|
+
return Promise.resolve([new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]);
|
|
128
|
+
}
|
|
129
|
+
const feeTokenInfo = this.chainService.getAssetBySlug(networkFee.tokenSlug);
|
|
130
|
+
const feeTokenChain = this.chainService.getChainInfoByKey(feeTokenInfo.originChain);
|
|
131
|
+
const [feeTokenBalance, fromAssetBalance] = await Promise.all([this.balanceService.getTokenFreeBalance(params.address, feeTokenInfo.originChain, feeTokenInfo.slug), this.balanceService.getTokenFreeBalance(params.address, fromAsset.originChain, fromAsset.slug)]);
|
|
132
|
+
const bnFeeTokenBalance = new BigNumber(feeTokenBalance.value);
|
|
133
|
+
const bnFromAssetBalance = new BigNumber(fromAssetBalance.value);
|
|
134
|
+
const bnFeeAmount = new BigNumber(networkFee.amount);
|
|
135
|
+
if (bnFeeTokenBalance.lte(bnFeeAmount)) {
|
|
136
|
+
return Promise.resolve([new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE, `You don't have enough ${feeTokenInfo.symbol} (${feeTokenChain.name}) to pay transaction fee`)]);
|
|
137
|
+
}
|
|
138
|
+
if (fromAsset.slug === feeTokenInfo.slug) {
|
|
139
|
+
if (bnFromAssetBalance.lte(bnFeeAmount.plus(bnAmount))) {
|
|
140
|
+
return Promise.resolve([new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE, `Insufficient balance. Deposit ${fromAsset.symbol} and try again.`)]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (params.selectedQuote.minSwap) {
|
|
144
|
+
const minProtocolSwap = new BigNumber(params.selectedQuote.minSwap);
|
|
145
|
+
if (!isXcmOk && bnFromAssetBalance.lte(minProtocolSwap)) {
|
|
146
|
+
const parsedMinSwapValue = formatNumber(minProtocolSwap, _getAssetDecimals(fromAsset));
|
|
147
|
+
return Promise.resolve([new TransactionError(SwapErrorType.SWAP_NOT_ENOUGH_BALANCE, `Insufficient balance. You need more than ${parsedMinSwapValue} ${fromAsset.symbol} to start swapping. Deposit ${fromAsset.symbol} and try again.`)]); // todo: min swap or amount?
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const bnSrcAssetMinAmount = new BigNumber(_getTokenMinAmount(fromAsset));
|
|
152
|
+
const bnMaxBalanceSwap = bnFromAssetBalance.minus(bnSrcAssetMinAmount);
|
|
153
|
+
if (!isXcmOk && bnAmount.gte(bnMaxBalanceSwap)) {
|
|
154
|
+
const parsedMaxBalanceSwap = formatNumber(bnMaxBalanceSwap, _getAssetDecimals(fromAsset));
|
|
155
|
+
return Promise.resolve([new TransactionError(SwapErrorType.SWAP_EXCEED_ALLOWANCE, `Amount too high. Lower your amount ${bnMaxBalanceSwap.gt(0) ? `below ${parsedMaxBalanceSwap} ${fromAsset.symbol}` : ''} and try again`)]);
|
|
156
|
+
}
|
|
157
|
+
if (params.recipient) {
|
|
158
|
+
const toAsset = this.chainService.getAssetBySlug(params.selectedQuote.pair.to);
|
|
159
|
+
const destChainInfo = this.chainService.getChainInfoByKey(toAsset.originChain);
|
|
160
|
+
const isEvmAddress = isEthereumAddress(params.recipient);
|
|
161
|
+
const isEvmDestChain = _isChainEvmCompatible(destChainInfo);
|
|
162
|
+
if (isEvmAddress && !isEvmDestChain || !isEvmAddress && isEvmDestChain) {
|
|
163
|
+
return Promise.resolve([new TransactionError(SwapErrorType.INVALID_RECIPIENT)]);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return Promise.resolve([]);
|
|
167
|
+
}
|
|
168
|
+
get name() {
|
|
169
|
+
return this.providerName;
|
|
170
|
+
}
|
|
171
|
+
get slug() {
|
|
172
|
+
return this.providerSlug;
|
|
173
|
+
}
|
|
174
|
+
get providerInfo() {
|
|
175
|
+
return {
|
|
176
|
+
id: this.providerSlug,
|
|
177
|
+
name: this.providerName
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { COMMON_ASSETS } from '@subwallet/chain-list';
|
|
2
|
+
import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
|
|
3
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
4
|
+
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
5
|
+
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
6
|
+
import { SwapBaseInterface } from '@subwallet/extension-base/services/swap-service/handler/base-handler';
|
|
7
|
+
import { BaseStepDetail } from '@subwallet/extension-base/types/service-base';
|
|
8
|
+
import { OptimalSwapPath, OptimalSwapPathParams, SwapEarlyValidation, SwapFeeInfo, SwapQuote, SwapRequest, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types/swap';
|
|
9
|
+
export declare class ChainflipSwapHandler implements SwapBaseInterface {
|
|
10
|
+
private swapSdk;
|
|
11
|
+
private readonly isTestnet;
|
|
12
|
+
private swapBaseHandler;
|
|
13
|
+
constructor(chainService: ChainService, balanceService: BalanceService, isTestnet?: boolean);
|
|
14
|
+
get chainService(): ChainService;
|
|
15
|
+
get balanceService(): BalanceService;
|
|
16
|
+
get providerInfo(): import("@subwallet/extension-base/types/swap").SwapProvider;
|
|
17
|
+
get name(): string;
|
|
18
|
+
get slug(): string;
|
|
19
|
+
get assetMapping(): Record<string, import("@chainflip/sdk/dist/contracts-b0BB7B5m").A>;
|
|
20
|
+
get chainMapping(): Record<string, import("@chainflip/sdk/dist/contracts-b0BB7B5m").C>;
|
|
21
|
+
get intermediaryAssetSlug(): COMMON_ASSETS.USDC_ETHEREUM | COMMON_ASSETS.USDC_SEPOLIA;
|
|
22
|
+
validateSwapRequest(request: SwapRequest): Promise<SwapEarlyValidation>;
|
|
23
|
+
private parseSwapPath;
|
|
24
|
+
getSwapQuote(request: SwapRequest): Promise<SwapQuote | SwapError>;
|
|
25
|
+
validateSwapProcess(params: ValidateSwapProcessParams): Promise<TransactionError[]>;
|
|
26
|
+
handleSubmitStep(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
|
|
27
|
+
handleSwapProcess(params: SwapSubmitParams): Promise<SwapSubmitStepData>;
|
|
28
|
+
getSubmitStep(params: OptimalSwapPathParams): Promise<[BaseStepDetail, SwapFeeInfo] | undefined>;
|
|
29
|
+
generateOptimalProcess(params: OptimalSwapPathParams): Promise<OptimalSwapPath>;
|
|
30
|
+
}
|