@subwallet/extension-base 1.1.34-0 → 1.1.35-beta.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 +111 -69
- package/background/KoniTypes.js +19 -13
- package/background/errors/TransactionError.js +9 -0
- package/cjs/background/KoniTypes.js +20 -16
- package/cjs/background/errors/TransactionError.js +9 -0
- package/cjs/constants/index.js +19 -4
- package/cjs/constants/staking.js +1 -1
- package/cjs/koni/api/dotsama/balance.js +464 -0
- package/cjs/koni/api/nft/config.js +33 -23
- package/cjs/koni/api/nft/index.js +14 -0
- package/cjs/koni/api/nft/nft.js +1 -22
- package/cjs/koni/api/nft/ordinal_nft/constants.js +21 -0
- package/cjs/koni/api/nft/ordinal_nft/index.js +121 -0
- package/cjs/koni/api/nft/ordinal_nft/utils.js +41 -0
- package/cjs/koni/api/staking/bonding/amplitude.js +19 -16
- package/cjs/koni/api/staking/bonding/astar.js +11 -10
- package/cjs/koni/api/staking/bonding/index.js +4 -1
- package/cjs/koni/api/staking/bonding/paraChain.js +25 -23
- package/cjs/koni/api/staking/bonding/relayChain.js +48 -45
- package/cjs/koni/api/staking/bonding/utils.js +104 -86
- package/cjs/koni/api/staking/index.js +6 -5
- package/cjs/koni/api/staking/paraChain.js +6 -5
- package/cjs/koni/api/staking/relayChain.js +3 -2
- package/cjs/koni/api/yield/helper/utils.js +46 -0
- package/cjs/koni/background/cron.js +3 -21
- package/cjs/koni/background/handlers/Extension.js +368 -69
- package/cjs/koni/background/handlers/State.js +18 -12
- package/cjs/koni/background/handlers/index.js +4 -2
- package/cjs/koni/background/subscription.js +7 -104
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/campaign-service/index.js +9 -6
- package/cjs/services/chain-service/constants.js +2 -17
- package/cjs/services/chain-service/index.js +50 -3
- package/cjs/services/chain-service/utils.js +7 -1
- package/cjs/services/earning-service/constants/chains.js +30 -0
- package/cjs/services/earning-service/constants/index.js +27 -0
- package/cjs/services/earning-service/constants/step.js +18 -0
- package/cjs/services/earning-service/handlers/base.js +262 -0
- package/cjs/services/earning-service/handlers/index.js +60 -0
- package/cjs/services/earning-service/handlers/lending/base.js +81 -0
- package/cjs/services/earning-service/handlers/lending/index.js +13 -0
- package/cjs/services/earning-service/handlers/lending/interlay.js +192 -0
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +240 -0
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +97 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +140 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +298 -0
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +227 -0
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +404 -0
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +434 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +466 -0
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +146 -0
- package/cjs/services/earning-service/handlers/native-staking/base.js +161 -0
- package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +390 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +567 -0
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +566 -0
- package/cjs/services/earning-service/handlers/special.js +493 -0
- package/cjs/services/earning-service/service.js +733 -0
- package/cjs/services/earning-service/utils/index.js +128 -0
- package/cjs/services/event-service/index.js +5 -0
- package/cjs/services/keyring-service/index.js +14 -2
- package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
- package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
- package/cjs/services/migration-service/scripts/MigrateEthProvider.js +17 -0
- package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +17 -0
- package/cjs/services/migration-service/scripts/MigrateProvider.js +29 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +21 -0
- package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +21 -0
- package/cjs/services/migration-service/scripts/index.js +6 -1
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
- package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
- package/cjs/services/mint-campaign-service/constants.js +11 -0
- package/cjs/services/mint-campaign-service/index.js +18 -0
- package/cjs/services/notification-service/NotificationService.js +3 -2
- package/cjs/services/request-service/handler/PopupHandler.js +2 -3
- package/cjs/services/storage-service/DatabaseService.js +97 -0
- package/cjs/services/storage-service/databases/index.js +4 -0
- package/cjs/services/storage-service/db-stores/AssetRef.js +24 -0
- package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/cjs/services/storage-service/db-stores/YieldPoolStore.js +36 -0
- package/cjs/services/storage-service/db-stores/YieldPositionStore.js +71 -0
- package/cjs/services/storage-service/index.js +241 -0
- package/cjs/services/subscan-service/index.js +16 -0
- package/cjs/services/transaction-service/event-parser/index.js +58 -0
- package/cjs/services/transaction-service/helpers/index.js +3 -1
- package/cjs/services/transaction-service/index.js +249 -75
- package/cjs/services/transaction-service/utils.js +1 -0
- package/cjs/types/campaigns/index.js +16 -0
- package/cjs/types/campaigns/unlock-dot.js +1 -0
- package/cjs/types/index.js +44 -0
- package/cjs/types/ordinal.js +1 -0
- package/cjs/types/transaction.js +1 -0
- package/cjs/types/yield/actions/index.js +27 -0
- package/cjs/types/yield/actions/join/index.js +38 -0
- package/cjs/types/yield/actions/join/step.js +47 -0
- package/cjs/types/yield/actions/join/submit.js +1 -0
- package/cjs/types/yield/actions/join/validate.js +16 -0
- package/cjs/types/yield/actions/others.js +1 -0
- package/cjs/types/yield/index.js +27 -0
- package/cjs/types/yield/info/account/index.js +49 -0
- package/cjs/types/yield/info/account/info.js +1 -0
- package/cjs/types/yield/info/account/reward.js +1 -0
- package/cjs/types/yield/info/account/target.js +32 -0
- package/cjs/types/yield/info/account/unstake.js +27 -0
- package/cjs/types/yield/info/base.js +41 -0
- package/cjs/types/yield/info/chain/index.js +27 -0
- package/cjs/types/yield/info/chain/info.js +1 -0
- package/cjs/types/yield/info/chain/target.js +1 -0
- package/cjs/types/yield/info/index.js +49 -0
- package/cjs/types/yield/info/pallet.js +15 -0
- package/cjs/types.js +1 -0
- package/cjs/utils/address.js +34 -0
- package/cjs/utils/environment.js +23 -28
- package/cjs/utils/fetchStaticCache.js +22 -0
- package/cjs/utils/fetchStaticData.js +2 -1
- package/cjs/utils/index.js +94 -10
- package/cjs/utils/keyring.js +57 -0
- package/cjs/utils/mv3.js +14 -0
- package/cjs/utils/number.js +6 -2
- package/cjs/utils/object.js +12 -0
- package/constants/index.d.ts +6 -1
- package/constants/index.js +6 -1
- package/constants/staking.js +1 -1
- package/koni/api/nft/config.js +33 -23
- package/koni/api/nft/index.js +15 -1
- package/koni/api/nft/nft.js +2 -23
- package/koni/api/nft/ordinal_nft/constants.d.ts +9 -0
- package/koni/api/nft/ordinal_nft/constants.js +12 -0
- package/koni/api/nft/ordinal_nft/index.d.ts +8 -0
- package/koni/api/nft/ordinal_nft/index.js +114 -0
- package/koni/api/nft/ordinal_nft/utils.d.ts +2 -0
- package/koni/api/nft/ordinal_nft/utils.js +33 -0
- package/koni/api/staking/bonding/amplitude.js +13 -10
- package/koni/api/staking/bonding/astar.js +9 -8
- package/koni/api/staking/bonding/index.d.ts +1 -1
- package/koni/api/staking/bonding/index.js +5 -1
- package/koni/api/staking/bonding/paraChain.js +12 -10
- package/koni/api/staking/bonding/relayChain.d.ts +2 -2
- package/koni/api/staking/bonding/relayChain.js +33 -30
- package/koni/api/staking/bonding/utils.d.ts +15 -38
- package/koni/api/staking/bonding/utils.js +85 -69
- package/koni/api/staking/index.js +2 -1
- package/koni/api/staking/paraChain.js +7 -6
- package/koni/api/staking/relayChain.js +4 -3
- package/koni/api/yield/helper/utils.d.ts +10 -0
- package/koni/api/yield/helper/utils.js +32 -0
- package/koni/background/cron.d.ts +0 -4
- package/koni/background/cron.js +4 -22
- package/koni/background/handlers/Extension.d.ts +17 -1
- package/koni/background/handlers/Extension.js +327 -30
- package/koni/background/handlers/State.d.ts +6 -1
- package/koni/background/handlers/State.js +17 -12
- package/koni/background/handlers/index.js +4 -2
- package/koni/background/subscription.d.ts +1 -6
- package/koni/background/subscription.js +8 -104
- package/package.json +335 -7
- package/packageInfo.js +1 -1
- package/services/campaign-service/index.js +9 -6
- package/services/chain-service/constants.d.ts +1 -13
- package/services/chain-service/constants.js +1 -15
- package/services/chain-service/index.d.ts +3 -0
- package/services/chain-service/index.js +50 -3
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +5 -1
- package/services/earning-service/constants/abis/compound_finance_v2_abi.json +1235 -0
- package/services/earning-service/constants/abis/st_liquid_token_abi.json +1355 -0
- package/services/earning-service/constants/chains.d.ts +15 -0
- package/services/earning-service/constants/chains.js +22 -0
- package/services/earning-service/constants/index.d.ts +2 -0
- package/services/earning-service/constants/index.js +5 -0
- package/services/earning-service/constants/step.d.ts +3 -0
- package/services/earning-service/constants/step.js +10 -0
- package/services/earning-service/handlers/base.d.ts +113 -0
- package/services/earning-service/handlers/base.js +256 -0
- package/services/earning-service/handlers/index.d.ts +5 -0
- package/services/earning-service/handlers/index.js +8 -0
- package/services/earning-service/handlers/lending/base.d.ts +8 -0
- package/services/earning-service/handlers/lending/base.js +73 -0
- package/services/earning-service/handlers/lending/index.d.ts +1 -0
- package/services/earning-service/handlers/lending/index.js +4 -0
- package/services/earning-service/handlers/lending/interlay.d.ts +24 -0
- package/services/earning-service/handlers/lending/interlay.js +184 -0
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +232 -0
- package/services/earning-service/handlers/liquid-staking/base.d.ts +11 -0
- package/services/earning-service/handlers/liquid-staking/base.js +89 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +46 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.js +287 -0
- package/services/earning-service/handlers/liquid-staking/index.d.ts +4 -0
- package/services/earning-service/handlers/liquid-staking/index.js +7 -0
- package/services/earning-service/handlers/liquid-staking/parallel.d.ts +26 -0
- package/services/earning-service/handlers/liquid-staking/parallel.js +219 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +34 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +394 -0
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +425 -0
- package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
- package/services/earning-service/handlers/native-staking/astar.js +456 -0
- package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
- package/services/earning-service/handlers/native-staking/base-para.js +138 -0
- package/services/earning-service/handlers/native-staking/base.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/base.js +152 -0
- package/services/earning-service/handlers/native-staking/index.d.ts +4 -0
- package/services/earning-service/handlers/native-staking/index.js +7 -0
- package/services/earning-service/handlers/native-staking/para-chain.d.ts +15 -0
- package/services/earning-service/handlers/native-staking/para-chain.js +382 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +558 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +36 -0
- package/services/earning-service/handlers/nomination-pool/index.js +556 -0
- package/services/earning-service/handlers/special.d.ts +64 -0
- package/services/earning-service/handlers/special.js +485 -0
- package/services/earning-service/service.d.ts +94 -0
- package/services/earning-service/service.js +722 -0
- package/services/earning-service/utils/index.d.ts +18 -0
- package/services/earning-service/utils/index.js +112 -0
- package/services/event-service/index.d.ts +2 -0
- package/services/event-service/index.js +5 -0
- package/services/event-service/types.d.ts +9 -0
- package/services/keyring-service/index.d.ts +2 -1
- package/services/keyring-service/index.js +14 -2
- package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
- package/services/migration-service/scripts/DeleteEarningData.js +13 -0
- package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
- package/services/migration-service/scripts/EnableEarningChains.js +13 -0
- package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningHistory.js +13 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.js +13 -0
- package/services/migration-service/scripts/index.js +6 -1
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
- package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
- package/services/mint-campaign-service/campaigns/index.js +4 -0
- package/services/mint-campaign-service/constants.d.ts +1 -0
- package/services/mint-campaign-service/constants.js +4 -0
- package/services/mint-campaign-service/index.d.ts +7 -0
- package/services/mint-campaign-service/index.js +11 -0
- package/services/notification-service/NotificationService.js +3 -2
- package/services/request-service/handler/PopupHandler.js +3 -4
- package/services/storage-service/DatabaseService.d.ts +22 -1
- package/services/storage-service/DatabaseService.js +97 -0
- package/services/storage-service/databases/index.d.ts +7 -2
- package/services/storage-service/databases/index.js +4 -0
- package/services/storage-service/db-stores/AssetRef.d.ts +7 -0
- package/services/storage-service/db-stores/AssetRef.js +16 -0
- package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/services/storage-service/db-stores/YieldPoolStore.d.ts +10 -0
- package/services/storage-service/db-stores/YieldPoolStore.js +28 -0
- package/services/storage-service/db-stores/YieldPositionStore.d.ts +11 -0
- package/services/storage-service/db-stores/YieldPositionStore.js +63 -0
- package/services/subscan-service/index.d.ts +3 -2
- package/services/subscan-service/index.js +15 -0
- package/services/subscan-service/types.d.ts +20 -0
- package/services/transaction-service/event-parser/index.d.ts +3 -1
- package/services/transaction-service/event-parser/index.js +57 -1
- package/services/transaction-service/helpers/index.js +3 -1
- package/services/transaction-service/index.d.ts +6 -13
- package/services/transaction-service/index.js +247 -73
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.js +1 -0
- package/types/campaigns/index.d.ts +1 -0
- package/types/campaigns/index.js +4 -0
- package/types/campaigns/unlock-dot.d.ts +71 -0
- package/types/campaigns/unlock-dot.js +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.js +5 -1
- package/types/ordinal.d.ts +69 -0
- package/types/ordinal.js +1 -0
- package/types/transaction.d.ts +3 -0
- package/types/transaction.js +1 -0
- package/types/yield/actions/index.d.ts +2 -0
- package/types/yield/actions/index.js +5 -0
- package/types/yield/actions/join/index.d.ts +3 -0
- package/types/yield/actions/join/index.js +6 -0
- package/types/yield/actions/join/step.d.ts +95 -0
- package/types/yield/actions/join/step.js +46 -0
- package/types/yield/actions/join/submit.d.ts +58 -0
- package/types/yield/actions/join/submit.js +1 -0
- package/types/yield/actions/join/validate.d.ts +18 -0
- package/types/yield/actions/join/validate.js +10 -0
- package/types/yield/actions/others.d.ts +85 -0
- package/types/yield/actions/others.js +1 -0
- package/types/yield/index.d.ts +2 -0
- package/types/yield/index.js +5 -0
- package/types/yield/info/account/index.d.ts +4 -0
- package/types/yield/info/account/index.js +7 -0
- package/types/yield/info/account/info.d.ts +92 -0
- package/types/yield/info/account/info.js +1 -0
- package/types/yield/info/account/reward.d.ts +47 -0
- package/types/yield/info/account/reward.js +1 -0
- package/types/yield/info/account/target.d.ts +43 -0
- package/types/yield/info/account/target.js +27 -0
- package/types/yield/info/account/unstake.d.ts +31 -0
- package/types/yield/info/account/unstake.js +22 -0
- package/types/yield/info/base.d.ts +45 -0
- package/types/yield/info/base.js +36 -0
- package/types/yield/info/chain/index.d.ts +2 -0
- package/types/yield/info/chain/index.js +5 -0
- package/types/yield/info/chain/info.d.ts +252 -0
- package/types/yield/info/chain/info.js +1 -0
- package/types/yield/info/chain/target.d.ts +37 -0
- package/types/yield/info/chain/target.js +1 -0
- package/types/yield/info/index.d.ts +4 -0
- package/types/yield/info/index.js +7 -0
- package/types/yield/info/pallet.d.ts +143 -0
- package/types/yield/info/pallet.js +9 -0
- package/utils/environment.d.ts +9 -2
- package/utils/environment.js +14 -26
- package/utils/fetchStaticCache.d.ts +1 -0
- package/utils/fetchStaticCache.js +14 -0
- package/utils/fetchStaticData.js +2 -1
- package/utils/index.d.ts +5 -1
- package/utils/index.js +53 -3
- package/utils/mv3.d.ts +2 -0
- package/utils/mv3.js +6 -0
- package/utils/number.d.ts +2 -1
- package/utils/number.js +2 -1
- package/utils/object.d.ts +1 -0
- package/utils/object.js +6 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
6
|
+
import { BasicTxErrorType, ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
7
|
+
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
8
|
+
import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
|
|
9
|
+
import { YIELD_POOL_STAT_REFRESH_INTERVAL } from '@subwallet/extension-base/koni/api/yield/helper/utils';
|
|
10
|
+
import { _getChainNativeTokenSlug } from '@subwallet/extension-base/services/chain-service/utils';
|
|
11
|
+
import { YieldStepType, YieldValidationStatus } from '@subwallet/extension-base/types';
|
|
12
|
+
import { createPromiseHandler, formatNumber } from '@subwallet/extension-base/utils';
|
|
13
|
+
import { t } from 'i18next';
|
|
14
|
+
import { BN, BN_TEN, BN_ZERO, noop } from '@polkadot/util';
|
|
15
|
+
import BasePoolHandler from "./base.js";
|
|
16
|
+
export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
|
|
17
|
+
/** Pool's type */
|
|
18
|
+
|
|
19
|
+
/** Exchange rate before divine with decimals */
|
|
20
|
+
rate = 0;
|
|
21
|
+
constructor(state, chain) {
|
|
22
|
+
super(state, chain);
|
|
23
|
+
this.exchangeRatePromise = createPromiseHandler();
|
|
24
|
+
}
|
|
25
|
+
get metadataInfo() {
|
|
26
|
+
return {
|
|
27
|
+
altInputAssets: this.altInputAsset,
|
|
28
|
+
derivativeAssets: this.derivativeAssets,
|
|
29
|
+
inputAsset: this.inputAsset,
|
|
30
|
+
rewardAssets: this.rewardAssets,
|
|
31
|
+
feeAssets: this.feeAssets,
|
|
32
|
+
logo: this.logo,
|
|
33
|
+
shortName: this.shortName,
|
|
34
|
+
name: this.name,
|
|
35
|
+
isAvailable: true,
|
|
36
|
+
maintainAsset: this.nativeToken.slug,
|
|
37
|
+
maintainBalance: this.maintainBalance,
|
|
38
|
+
availableMethod: this.availableMethod
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
updateExchangeRate(rate) {
|
|
42
|
+
this.rate = rate;
|
|
43
|
+
this.exchangeRatePromise.resolve(true);
|
|
44
|
+
}
|
|
45
|
+
async getExchangeRate() {
|
|
46
|
+
await this.exchangeRatePromise.promise;
|
|
47
|
+
return this.rate;
|
|
48
|
+
}
|
|
49
|
+
get isPoolSupportAlternativeFee() {
|
|
50
|
+
return this.feeAssets.length > 1;
|
|
51
|
+
}
|
|
52
|
+
async earlyValidate(request) {
|
|
53
|
+
var _poolInfo$statistic;
|
|
54
|
+
const poolInfo = await this.getPoolInfo();
|
|
55
|
+
if (!poolInfo || !((_poolInfo$statistic = poolInfo.statistic) !== null && _poolInfo$statistic !== void 0 && _poolInfo$statistic.earningThreshold.join)) {
|
|
56
|
+
return {
|
|
57
|
+
passed: false,
|
|
58
|
+
errorMessage: 'There is a problem fetching your data. Check your Internet connection or change the network endpoint and try again.'
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (request.address === ALL_ACCOUNT_KEY) {
|
|
62
|
+
return {
|
|
63
|
+
passed: true
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const feeAssetInfo = this.state.chainService.getAssetBySlug(this.feeAssets[0]);
|
|
67
|
+
const altInputAssetInfo = this.state.chainService.getAssetBySlug(this.altInputAsset);
|
|
68
|
+
const inputAssetInfo = this.state.chainService.getAssetBySlug(this.inputAsset);
|
|
69
|
+
const [inputAssetBalance, altInputAssetBalance, feeAssetBalance] = await Promise.all([this.state.balanceService.getTokenFreeBalance(request.address, inputAssetInfo.originChain, inputAssetInfo.slug), altInputAssetInfo ? this.state.balanceService.getTokenFreeBalance(request.address, altInputAssetInfo.originChain, altInputAssetInfo.slug) : Promise.resolve({
|
|
70
|
+
symbol: '',
|
|
71
|
+
decimals: 0,
|
|
72
|
+
value: '0'
|
|
73
|
+
}), this.state.balanceService.getTokenFreeBalance(request.address, feeAssetInfo.originChain, feeAssetInfo.slug)]);
|
|
74
|
+
const bnInputAssetBalance = new BN(inputAssetBalance.value);
|
|
75
|
+
const bnAltInputAssetBalance = new BN(altInputAssetBalance.value);
|
|
76
|
+
const bnMinJoinPool = new BN(poolInfo.statistic.earningThreshold.join);
|
|
77
|
+
const inputTokenInfo = this.state.chainService.getAssetBySlug(this.inputAsset);
|
|
78
|
+
const altInputTokenInfo = this.state.chainService.getAssetBySlug(this.altInputAsset);
|
|
79
|
+
if (bnInputAssetBalance.add(bnAltInputAssetBalance).lt(bnMinJoinPool)) {
|
|
80
|
+
const originChain = this.state.getChainInfo(inputTokenInfo.originChain);
|
|
81
|
+
const altChain = this.state.getChainInfo(altInputTokenInfo.originChain);
|
|
82
|
+
const parsedMinJoinPool = formatNumber(bnMinJoinPool.toString(), inputAssetInfo.decimals || 0);
|
|
83
|
+
return {
|
|
84
|
+
passed: false,
|
|
85
|
+
errorMessage: `You need at least ${parsedMinJoinPool} ${inputTokenInfo.symbol} (${originChain.name}) or ${altInputTokenInfo.symbol} (${altChain.name}) to start earning`
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (this.feeAssets.length === 1) {
|
|
89
|
+
const bnFeeAssetBalance = new BN(feeAssetBalance.value);
|
|
90
|
+
const minFeeAssetBalance = new BN(this.maintainBalance || '0');
|
|
91
|
+
const feeAssetDiv = BN_TEN.pow(new BN(feeAssetInfo.decimals || 0));
|
|
92
|
+
const parsedMinFeeAssetBalance = minFeeAssetBalance.div(feeAssetDiv).mul(new BN(12)).div(BN_TEN);
|
|
93
|
+
if (bnFeeAssetBalance.lte(BN_ZERO)) {
|
|
94
|
+
const feeChain = this.state.getChainInfo(feeAssetInfo.originChain);
|
|
95
|
+
return {
|
|
96
|
+
passed: false,
|
|
97
|
+
errorMessage: `You need at least ${parsedMinFeeAssetBalance.toString()} ${feeAssetInfo.symbol} (${feeChain.name}) to start earning`
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
passed: true
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
get group() {
|
|
106
|
+
const inputAsset = this.state.getAssetBySlug(this.inputAsset);
|
|
107
|
+
const groupSlug = inputAsset.multiChainAsset;
|
|
108
|
+
return groupSlug || this.inputAsset;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* Subscribe pool info */
|
|
112
|
+
|
|
113
|
+
async subscribePoolInfo(callback) {
|
|
114
|
+
let cancel = false;
|
|
115
|
+
const _callback = data => {
|
|
116
|
+
!cancel && callback(data);
|
|
117
|
+
};
|
|
118
|
+
const defaultCallback = async () => {
|
|
119
|
+
const data = {
|
|
120
|
+
...this.baseInfo,
|
|
121
|
+
type: this.type,
|
|
122
|
+
metadata: {
|
|
123
|
+
...this.metadataInfo,
|
|
124
|
+
description: this.getDescription()
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const poolInfo = await this.getPoolInfo();
|
|
128
|
+
!poolInfo && _callback(data);
|
|
129
|
+
};
|
|
130
|
+
const getStatInterval = () => {
|
|
131
|
+
if (!this.isActive) {
|
|
132
|
+
defaultCallback().catch(console.error);
|
|
133
|
+
} else {
|
|
134
|
+
defaultCallback().then(() => {
|
|
135
|
+
return this.getPoolStat();
|
|
136
|
+
}).then(rs => {
|
|
137
|
+
_callback(rs);
|
|
138
|
+
}).catch(console.error);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
getStatInterval();
|
|
142
|
+
const interval = setInterval(() => {
|
|
143
|
+
if (cancel) {
|
|
144
|
+
clearInterval(interval);
|
|
145
|
+
} else {
|
|
146
|
+
getStatInterval();
|
|
147
|
+
}
|
|
148
|
+
}, YIELD_POOL_STAT_REFRESH_INTERVAL);
|
|
149
|
+
return new Promise(resolve => {
|
|
150
|
+
const rs = () => {
|
|
151
|
+
cancel = true;
|
|
152
|
+
clearInterval(interval);
|
|
153
|
+
};
|
|
154
|
+
resolve(rs);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/* Subscribe pool info */
|
|
159
|
+
|
|
160
|
+
/* Get pool reward */
|
|
161
|
+
|
|
162
|
+
async getPoolReward() {
|
|
163
|
+
return new Promise(resolve => resolve(noop));
|
|
164
|
+
}
|
|
165
|
+
async getPoolRewardHistory() {
|
|
166
|
+
return new Promise(resolve => resolve(noop));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* Get pool reward */
|
|
170
|
+
|
|
171
|
+
/* Get pool targets */
|
|
172
|
+
|
|
173
|
+
async getPoolTargets() {
|
|
174
|
+
return new Promise(resolve => resolve([]));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* Get pool targets */
|
|
178
|
+
|
|
179
|
+
/* Join pool action */
|
|
180
|
+
|
|
181
|
+
/* Generate steps */
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @async
|
|
185
|
+
* @function getXcmStep
|
|
186
|
+
* */
|
|
187
|
+
async getXcmStep(params) {
|
|
188
|
+
const {
|
|
189
|
+
address,
|
|
190
|
+
amount
|
|
191
|
+
} = params;
|
|
192
|
+
const bnAmount = new BN(amount);
|
|
193
|
+
const inputTokenSlug = this.inputAsset; // assume that the pool only has 1 input token, will update later
|
|
194
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
195
|
+
const inputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, inputTokenInfo.originChain, inputTokenSlug);
|
|
196
|
+
const bnInputTokenBalance = new BN(inputTokenBalance.value);
|
|
197
|
+
if (!bnInputTokenBalance.gte(bnAmount)) {
|
|
198
|
+
if (this.altInputAsset) {
|
|
199
|
+
const altInputTokenSlug = this.altInputAsset;
|
|
200
|
+
const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
|
|
201
|
+
const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, altInputTokenInfo.originChain, altInputTokenSlug);
|
|
202
|
+
const bnAltInputTokenBalance = new BN(altInputTokenBalance.value || '0');
|
|
203
|
+
if (bnAltInputTokenBalance.gt(BN_ZERO)) {
|
|
204
|
+
const step = {
|
|
205
|
+
metadata: {
|
|
206
|
+
sendingValue: bnAmount.toString(),
|
|
207
|
+
originTokenInfo: altInputTokenInfo,
|
|
208
|
+
destinationTokenInfo: inputTokenInfo
|
|
209
|
+
},
|
|
210
|
+
name: 'Transfer DOT from Polkadot',
|
|
211
|
+
type: YieldStepType.XCM
|
|
212
|
+
};
|
|
213
|
+
const xcmOriginSubstrateApi = await this.state.getSubstrateApi(altInputTokenInfo.originChain).isReady;
|
|
214
|
+
const xcmTransfer = await createXcmExtrinsic({
|
|
215
|
+
originTokenInfo: altInputTokenInfo,
|
|
216
|
+
destinationTokenInfo: inputTokenInfo,
|
|
217
|
+
sendingValue: bnAmount.toString(),
|
|
218
|
+
recipient: address,
|
|
219
|
+
chainInfoMap: this.state.getChainInfoMap(),
|
|
220
|
+
substrateApi: xcmOriginSubstrateApi
|
|
221
|
+
});
|
|
222
|
+
const _xcmFeeInfo = await xcmTransfer.paymentInfo(address);
|
|
223
|
+
const xcmFeeInfo = _xcmFeeInfo.toPrimitive();
|
|
224
|
+
// TODO: calculate fee for destination chain
|
|
225
|
+
|
|
226
|
+
const fee = {
|
|
227
|
+
slug: altInputTokenSlug,
|
|
228
|
+
amount: Math.round(xcmFeeInfo.partialFee * 1.2).toString() // TODO
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
return [step, fee];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
get defaultSubmitStep() {
|
|
238
|
+
return [this.submitJoinStepInfo, {
|
|
239
|
+
slug: this.feeAssets[0],
|
|
240
|
+
amount: '0'
|
|
241
|
+
}];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @function submitJoinStepInfo
|
|
246
|
+
* @description Base info of submit step
|
|
247
|
+
* @return Fee of the submitting step
|
|
248
|
+
* */
|
|
249
|
+
|
|
250
|
+
async getSubmitStep(params) {
|
|
251
|
+
const fee = await this.getSubmitStepFee(params);
|
|
252
|
+
return [this.submitJoinStepInfo, fee];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* Generate steps */
|
|
256
|
+
|
|
257
|
+
/* Validate join action */
|
|
258
|
+
|
|
259
|
+
async validateTokenApproveStep(params, path) {
|
|
260
|
+
return Promise.resolve([new TransactionError(BasicTxErrorType.UNSUPPORTED)]);
|
|
261
|
+
}
|
|
262
|
+
async validateXcmStep(params, path, bnInputTokenBalance) {
|
|
263
|
+
const processValidation = {
|
|
264
|
+
ok: true,
|
|
265
|
+
status: YieldValidationStatus.OK
|
|
266
|
+
};
|
|
267
|
+
const bnAmount = new BN(params.amount);
|
|
268
|
+
const altInputTokenSlug = this.altInputAsset || '';
|
|
269
|
+
const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
|
|
270
|
+
const inputTokenInfo = this.state.getAssetBySlug(this.inputAsset);
|
|
271
|
+
const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(params.address, altInputTokenInfo.originChain, altInputTokenSlug);
|
|
272
|
+
const missingAmount = bnAmount.sub(bnInputTokenBalance); // TODO: what if input token is not LOCAL ??
|
|
273
|
+
const xcmFee = new BN(path.totalFee[1].amount || '0');
|
|
274
|
+
const xcmAmount = missingAmount.add(xcmFee);
|
|
275
|
+
const bnAltInputTokenBalance = new BN(altInputTokenBalance.value || '0');
|
|
276
|
+
const altInputTokenMinAmount = new BN(altInputTokenInfo.minAmount || '0');
|
|
277
|
+
if (!bnAltInputTokenBalance.sub(xcmAmount).gte(altInputTokenMinAmount)) {
|
|
278
|
+
processValidation.failedStep = path.steps[1];
|
|
279
|
+
processValidation.ok = false;
|
|
280
|
+
processValidation.status = YieldValidationStatus.NOT_ENOUGH_BALANCE;
|
|
281
|
+
const maxBn = bnInputTokenBalance.add(new BN(altInputTokenBalance.value)).sub(xcmFee).sub(altInputTokenMinAmount);
|
|
282
|
+
const maxValue = formatNumber(maxBn.toString(), inputTokenInfo.decimals || 0);
|
|
283
|
+
const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
|
|
284
|
+
const symbol = altInputTokenInfo.symbol;
|
|
285
|
+
const altNetwork = this.state.getChainInfo(altInputTokenInfo.originChain);
|
|
286
|
+
const inputNetworkName = this.chainInfo.name;
|
|
287
|
+
const altNetworkName = altNetwork.name;
|
|
288
|
+
const currentValue = formatNumber(bnInputTokenBalance.toString(), inputTokenInfo.decimals || 0);
|
|
289
|
+
const bnMaxXCM = new BN(altInputTokenBalance.value).sub(xcmFee).sub(altInputTokenMinAmount);
|
|
290
|
+
const maxXCMValue = formatNumber(bnMaxXCM.toString(), inputTokenInfo.decimals || 0);
|
|
291
|
+
processValidation.message = 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.', {
|
|
292
|
+
replace: {
|
|
293
|
+
symbol,
|
|
294
|
+
maxValue,
|
|
295
|
+
inputNetworkName,
|
|
296
|
+
altNetworkName,
|
|
297
|
+
currentValue,
|
|
298
|
+
maxXCMValue
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_BALANCE, processValidation.message, processValidation)];
|
|
302
|
+
}
|
|
303
|
+
return [];
|
|
304
|
+
}
|
|
305
|
+
async validateJoinStep(id, params, path, bnInputTokenBalance, isXcmOk) {
|
|
306
|
+
const _poolInfo = await this.getPoolInfo();
|
|
307
|
+
if (!_poolInfo) {
|
|
308
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
309
|
+
}
|
|
310
|
+
const poolInfo = _poolInfo;
|
|
311
|
+
if (!poolInfo.statistic) {
|
|
312
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
313
|
+
}
|
|
314
|
+
const processValidation = {
|
|
315
|
+
ok: true,
|
|
316
|
+
status: YieldValidationStatus.OK
|
|
317
|
+
};
|
|
318
|
+
const feeTokenSlug = path.totalFee[id].slug;
|
|
319
|
+
const feeTokenInfo = this.state.getAssetBySlug(feeTokenSlug);
|
|
320
|
+
const inputTokenInfo = this.state.getAssetBySlug(this.inputAsset);
|
|
321
|
+
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
322
|
+
const bnAmount = new BN(params.amount);
|
|
323
|
+
if (this.feeAssets.length === 1 && feeTokenSlug === defaultFeeTokenSlug) {
|
|
324
|
+
var _path$totalFee$id;
|
|
325
|
+
const bnFeeAmount = new BN(((_path$totalFee$id = path.totalFee[id]) === null || _path$totalFee$id === void 0 ? void 0 : _path$totalFee$id.amount) || '0');
|
|
326
|
+
const feeTokenBalance = await this.state.balanceService.getTokenFreeBalance(params.address, feeTokenInfo.originChain, feeTokenSlug);
|
|
327
|
+
const bnFeeTokenBalance = new BN(feeTokenBalance.value || '0');
|
|
328
|
+
const bnFeeTokenMinAmount = new BN((feeTokenInfo === null || feeTokenInfo === void 0 ? void 0 : feeTokenInfo.minAmount) || '0');
|
|
329
|
+
if (!bnFeeTokenBalance.sub(bnFeeAmount).gte(bnFeeTokenMinAmount)) {
|
|
330
|
+
processValidation.failedStep = path.steps[id];
|
|
331
|
+
processValidation.ok = false;
|
|
332
|
+
processValidation.status = YieldValidationStatus.NOT_ENOUGH_FEE;
|
|
333
|
+
return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_FEE, processValidation.message, processValidation)];
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (!bnAmount.gte(new BN(poolInfo.statistic.earningThreshold.join || '0'))) {
|
|
337
|
+
processValidation.failedStep = path.steps[id];
|
|
338
|
+
processValidation.ok = false;
|
|
339
|
+
processValidation.status = YieldValidationStatus.NOT_ENOUGH_MIN_JOIN_POOL;
|
|
340
|
+
return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_MIN_JOIN_POOL, processValidation.message, processValidation)];
|
|
341
|
+
}
|
|
342
|
+
if (!isXcmOk && bnAmount.gt(bnInputTokenBalance)) {
|
|
343
|
+
processValidation.failedStep = path.steps[id];
|
|
344
|
+
processValidation.ok = false;
|
|
345
|
+
processValidation.status = YieldValidationStatus.NOT_ENOUGH_BALANCE;
|
|
346
|
+
const maxString = formatNumber(bnInputTokenBalance.toString(), inputTokenInfo.decimals || 0);
|
|
347
|
+
if (maxString !== '0') {
|
|
348
|
+
processValidation.message = t('Amount must be equal or less than {{number}}', {
|
|
349
|
+
replace: {
|
|
350
|
+
number: maxString
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
} else {
|
|
354
|
+
processValidation.message = t('You need balance greater than 0 to continue');
|
|
355
|
+
}
|
|
356
|
+
return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_BALANCE, processValidation.message, processValidation)];
|
|
357
|
+
}
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
async validateYieldJoin(params, path) {
|
|
361
|
+
const inputTokenSlug = this.inputAsset;
|
|
362
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
363
|
+
const balanceService = this.state.balanceService;
|
|
364
|
+
const inputTokenBalance = await balanceService.getTokenFreeBalance(params.address, inputTokenInfo.originChain, inputTokenSlug);
|
|
365
|
+
const bnInputTokenBalance = new BN(inputTokenBalance.value || '0');
|
|
366
|
+
const bnAmount = new BN(params.amount);
|
|
367
|
+
if (bnAmount.lte(BN_ZERO)) {
|
|
368
|
+
return [new TransactionError(BasicTxErrorType.INVALID_PARAMS, 'Amount must be greater than 0')];
|
|
369
|
+
}
|
|
370
|
+
let isXcmOk = false;
|
|
371
|
+
for (const step of path.steps) {
|
|
372
|
+
const getErrors = async () => {
|
|
373
|
+
switch (step.type) {
|
|
374
|
+
case YieldStepType.DEFAULT:
|
|
375
|
+
return Promise.resolve([]);
|
|
376
|
+
case YieldStepType.XCM:
|
|
377
|
+
return this.validateXcmStep(params, path, bnInputTokenBalance);
|
|
378
|
+
case YieldStepType.TOKEN_APPROVAL:
|
|
379
|
+
return this.validateTokenApproveStep(params, path);
|
|
380
|
+
default:
|
|
381
|
+
return this.validateJoinStep(step.id, params, path, bnInputTokenBalance, isXcmOk);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
const errors = await getErrors();
|
|
385
|
+
if (errors.length) {
|
|
386
|
+
return errors;
|
|
387
|
+
} else if (step.type === YieldStepType.XCM) {
|
|
388
|
+
isXcmOk = true;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return [];
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/* Validate join action */
|
|
395
|
+
|
|
396
|
+
/* Submit join action */
|
|
397
|
+
|
|
398
|
+
async handleTokenApproveStep(data, path) {
|
|
399
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
400
|
+
}
|
|
401
|
+
async handleXcmStep(data, path, xcmFee) {
|
|
402
|
+
const {
|
|
403
|
+
address,
|
|
404
|
+
amount
|
|
405
|
+
} = data;
|
|
406
|
+
const destinationTokenSlug = this.inputAsset;
|
|
407
|
+
const originChainInfo = this.state.getChainInfo(COMMON_CHAIN_SLUGS.POLKADOT);
|
|
408
|
+
const originTokenSlug = _getChainNativeTokenSlug(originChainInfo);
|
|
409
|
+
const originTokenInfo = this.state.getAssetBySlug(originTokenSlug);
|
|
410
|
+
const destinationTokenInfo = this.state.getAssetBySlug(destinationTokenSlug);
|
|
411
|
+
const substrateApi = this.state.getSubstrateApi(originChainInfo.slug);
|
|
412
|
+
const inputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, destinationTokenInfo.originChain, destinationTokenSlug);
|
|
413
|
+
const bnInputTokenBalance = new BN(inputTokenBalance.value);
|
|
414
|
+
const bnXcmFee = new BN(xcmFee);
|
|
415
|
+
const bnAmount = new BN(amount);
|
|
416
|
+
const bnTotalAmount = bnAmount.sub(bnInputTokenBalance).add(bnXcmFee);
|
|
417
|
+
const extrinsic = await createXcmExtrinsic({
|
|
418
|
+
chainInfoMap: this.state.getChainInfoMap(),
|
|
419
|
+
destinationTokenInfo,
|
|
420
|
+
originTokenInfo,
|
|
421
|
+
recipient: address,
|
|
422
|
+
sendingValue: bnTotalAmount.toString(),
|
|
423
|
+
substrateApi
|
|
424
|
+
});
|
|
425
|
+
const xcmData = {
|
|
426
|
+
originNetworkKey: originChainInfo.slug,
|
|
427
|
+
destinationNetworkKey: destinationTokenInfo.originChain,
|
|
428
|
+
from: address,
|
|
429
|
+
to: address,
|
|
430
|
+
value: bnTotalAmount.toString(),
|
|
431
|
+
tokenSlug: originTokenSlug,
|
|
432
|
+
showExtraWarning: true
|
|
433
|
+
};
|
|
434
|
+
return {
|
|
435
|
+
txChain: originChainInfo.slug,
|
|
436
|
+
extrinsicType: ExtrinsicType.TRANSFER_XCM,
|
|
437
|
+
extrinsic,
|
|
438
|
+
txData: xcmData,
|
|
439
|
+
transferNativeAmount: bnTotalAmount.toString(),
|
|
440
|
+
chainType: ChainType.SUBSTRATE
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
handleYieldJoin(data, path, currentStep) {
|
|
444
|
+
const type = path.steps[currentStep].type;
|
|
445
|
+
switch (type) {
|
|
446
|
+
case YieldStepType.DEFAULT:
|
|
447
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
448
|
+
case YieldStepType.TOKEN_APPROVAL:
|
|
449
|
+
return this.handleTokenApproveStep(data, path);
|
|
450
|
+
case YieldStepType.XCM:
|
|
451
|
+
{
|
|
452
|
+
const xcmFee = path.totalFee[currentStep].amount || '0';
|
|
453
|
+
return this.handleXcmStep(data, path, xcmFee);
|
|
454
|
+
}
|
|
455
|
+
default:
|
|
456
|
+
return this.handleSubmitStep(data, path);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/* Submit join action */
|
|
461
|
+
|
|
462
|
+
/* Join pool action */
|
|
463
|
+
|
|
464
|
+
/* Leave pool action */
|
|
465
|
+
|
|
466
|
+
handleYieldUnstake(amount, address, selectedTarget) {
|
|
467
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/* Leave pool action */
|
|
471
|
+
|
|
472
|
+
/* Other action */
|
|
473
|
+
|
|
474
|
+
handleYieldCancelUnstake() {
|
|
475
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
476
|
+
}
|
|
477
|
+
handleYieldClaimReward(address, bondReward) {
|
|
478
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
479
|
+
}
|
|
480
|
+
handleYieldWithdraw(address, unstakingInfo) {
|
|
481
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/* Other actions */
|
|
485
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
|
+
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
+
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
5
|
+
import { PersistDataServiceInterface, ServiceStatus, StoppableServiceInterface } from '@subwallet/extension-base/services/base/types';
|
|
6
|
+
import { EarningRewardHistoryItem, EarningRewardItem, EarningRewardJson, HandleYieldStepData, HandleYieldStepParams, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, RequestStakeCancelWithdrawal, RequestStakeClaimReward, RequestYieldLeave, RequestYieldWithdrawal, ResponseEarlyValidateYield, TransactionData, ValidateYieldProcessParams, YieldPoolInfo, YieldPoolTarget, YieldPositionInfo } from '@subwallet/extension-base/types';
|
|
7
|
+
import { PromiseHandler } from '@subwallet/extension-base/utils';
|
|
8
|
+
import { BehaviorSubject } from 'rxjs';
|
|
9
|
+
import { BasePoolHandler } from './handlers';
|
|
10
|
+
export default class EarningService implements StoppableServiceInterface, PersistDataServiceInterface {
|
|
11
|
+
protected readonly state: KoniState;
|
|
12
|
+
protected handlers: Record<string, BasePoolHandler>;
|
|
13
|
+
private earningRewardSubject;
|
|
14
|
+
private earningRewardHistorySubject;
|
|
15
|
+
private minAmountPercentSubject;
|
|
16
|
+
readonly yieldPoolInfoSubject: BehaviorSubject<Record<string, YieldPoolInfo>>;
|
|
17
|
+
readonly yieldPositionSubject: BehaviorSubject<Record<string, YieldPositionInfo>>;
|
|
18
|
+
readonly yieldPositionListSubject: BehaviorSubject<YieldPositionInfo[]>;
|
|
19
|
+
private dbService;
|
|
20
|
+
private eventService;
|
|
21
|
+
constructor(state: KoniState);
|
|
22
|
+
private initHandlers;
|
|
23
|
+
startPromiseHandler: PromiseHandler<void>;
|
|
24
|
+
stopPromiseHandler: PromiseHandler<void>;
|
|
25
|
+
status: ServiceStatus;
|
|
26
|
+
init(): Promise<void>;
|
|
27
|
+
handleActions(): void;
|
|
28
|
+
loadData(): Promise<void>;
|
|
29
|
+
persistData(): Promise<void>;
|
|
30
|
+
start(): Promise<void>;
|
|
31
|
+
stop(): Promise<void>;
|
|
32
|
+
waitForStarted(): Promise<void>;
|
|
33
|
+
waitForStopped(): Promise<void>;
|
|
34
|
+
getPoolHandler(slug: string): BasePoolHandler | undefined;
|
|
35
|
+
isPoolSupportAlternativeFee(slug: string): boolean;
|
|
36
|
+
subscribeMinAmountPercent(): BehaviorSubject<Record<string, number>>;
|
|
37
|
+
getMinAmountPercent(): Record<string, number>;
|
|
38
|
+
getYieldPool(slug: string): Promise<YieldPoolInfo | undefined>;
|
|
39
|
+
subscribePoolsInfo(callback: (rs: YieldPoolInfo) => void): Promise<VoidFunction>;
|
|
40
|
+
private getYieldPoolInfoFromDB;
|
|
41
|
+
subscribeYieldPoolInfo(): BehaviorSubject<Record<string, YieldPoolInfo>>;
|
|
42
|
+
getYieldPoolInfo(): Promise<YieldPoolInfo[]>;
|
|
43
|
+
private yieldPoolPersistQueue;
|
|
44
|
+
updateYieldPoolInfo(data: YieldPoolInfo): void;
|
|
45
|
+
private fetchingPoolsInfoOnline;
|
|
46
|
+
private yieldPoolsInfoUnsub;
|
|
47
|
+
runSubscribePoolsInfo(): Promise<void>;
|
|
48
|
+
runUnsubscribePoolsInfo(): void;
|
|
49
|
+
getYieldPosition(address: string, slug: string): Promise<YieldPositionInfo | undefined>;
|
|
50
|
+
subscribePoolPositions(addresses: string[], callback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
51
|
+
removeYieldPositions(chains?: string[], addresses?: string[]): Promise<void>;
|
|
52
|
+
private getYieldPositionFromDB;
|
|
53
|
+
subscribeYieldPosition(): BehaviorSubject<YieldPositionInfo[]>;
|
|
54
|
+
getYieldPositionInfo(): Promise<YieldPositionInfo[]>;
|
|
55
|
+
yieldPositionPersistQueue: YieldPositionInfo[];
|
|
56
|
+
resetYieldPositionQueue(): void;
|
|
57
|
+
resetYieldPosition(): void;
|
|
58
|
+
private _getYieldPositionKey;
|
|
59
|
+
updateYieldPosition(data: YieldPositionInfo): void;
|
|
60
|
+
reloadEarning(reset?: boolean): Promise<void>;
|
|
61
|
+
private yieldPositionUnsub;
|
|
62
|
+
runSubscribePoolsPosition(): Promise<void>;
|
|
63
|
+
runUnsubscribePoolsPosition(): void;
|
|
64
|
+
updateEarningReward(stakingRewardData: EarningRewardItem): void;
|
|
65
|
+
getPoolReward(addresses: string[], callback: (result: EarningRewardItem) => void): Promise<VoidFunction>;
|
|
66
|
+
subscribeEarningReward(): BehaviorSubject<EarningRewardJson>;
|
|
67
|
+
getEarningRewards(): EarningRewardJson;
|
|
68
|
+
earningsRewardInterval: NodeJS.Timer | undefined;
|
|
69
|
+
runSubscribeStakingRewardInterval(): void;
|
|
70
|
+
runUnsubscribeStakingRewardInterval(): void;
|
|
71
|
+
fetchPoolRewardHistory(addresses: string[], callback: (result: EarningRewardHistoryItem) => void): Promise<VoidFunction>;
|
|
72
|
+
updateEarningRewardHistory(earningRewardHistory: EarningRewardHistoryItem): void;
|
|
73
|
+
subscribeEarningRewardHistory(): BehaviorSubject<Record<string, EarningRewardHistoryItem>>;
|
|
74
|
+
getEarningRewardHistory(): Record<string, EarningRewardHistoryItem>;
|
|
75
|
+
earningsRewardHistoryInterval: NodeJS.Timer | undefined;
|
|
76
|
+
runSubscribeEarningRewardHistoryInterval(): void;
|
|
77
|
+
runUnsubscribeEarningRewardHistoryInterval(): void;
|
|
78
|
+
/**
|
|
79
|
+
* @async
|
|
80
|
+
* @function getPoolTargets
|
|
81
|
+
* @param {string} slug - Pool's slug
|
|
82
|
+
* @return {Promise<YieldPoolTarget[]>} List of pool's target
|
|
83
|
+
* */
|
|
84
|
+
getPoolTargets(slug: string): Promise<YieldPoolTarget[]>;
|
|
85
|
+
earlyValidateJoin(request: RequestEarlyValidateYield): Promise<ResponseEarlyValidateYield>;
|
|
86
|
+
generateOptimalSteps(params: OptimalYieldPathParams): Promise<OptimalYieldPath>;
|
|
87
|
+
validateYieldJoin(params: ValidateYieldProcessParams): Promise<TransactionError[]>;
|
|
88
|
+
handleYieldJoin(params: HandleYieldStepParams): Promise<HandleYieldStepData>;
|
|
89
|
+
validateYieldLeave(params: RequestYieldLeave): Promise<TransactionError[]>;
|
|
90
|
+
handleYieldLeave(params: RequestYieldLeave): Promise<[ExtrinsicType, TransactionData]>;
|
|
91
|
+
handleYieldWithdraw(params: RequestYieldWithdrawal): Promise<TransactionData>;
|
|
92
|
+
handleYieldCancelUnstake(params: RequestStakeCancelWithdrawal): Promise<TransactionData>;
|
|
93
|
+
handleYieldClaimReward(params: RequestStakeClaimReward): Promise<TransactionData>;
|
|
94
|
+
}
|