@subwallet/extension-base 1.1.29-0 → 1.1.29-beta.1
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 +95 -68
- package/background/KoniTypes.js +16 -13
- package/background/errors/TransactionError.js +9 -0
- package/cjs/background/KoniTypes.js +17 -16
- package/cjs/background/errors/TransactionError.js +9 -0
- package/cjs/constants/index.js +19 -4
- 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 +17 -15
- 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 +11 -1
- package/cjs/koni/background/handlers/Extension.js +362 -69
- package/cjs/koni/background/handlers/State.js +51 -3
- package/cjs/koni/background/handlers/index.js +4 -2
- package/cjs/koni/background/subscription.js +95 -37
- package/cjs/services/campaign-service/index.js +9 -6
- package/cjs/services/chain-service/constants.js +2 -16
- package/cjs/services/chain-service/utils.js +7 -1
- package/cjs/services/earning-service/constants/chains.js +29 -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 +232 -0
- package/cjs/services/earning-service/handlers/index.js +60 -0
- package/cjs/services/earning-service/handlers/lending/base.js +20 -0
- package/cjs/services/earning-service/handlers/lending/index.js +13 -0
- package/cjs/services/earning-service/handlers/lending/interlay.js +184 -0
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +217 -0
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +43 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +283 -0
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +196 -0
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +409 -0
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +382 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +459 -0
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +137 -0
- package/cjs/services/earning-service/handlers/native-staking/base.js +159 -0
- package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +383 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +542 -0
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +541 -0
- package/cjs/services/earning-service/handlers/special.js +411 -0
- package/cjs/services/earning-service/service.js +387 -0
- package/cjs/services/earning-service/utils/index.js +128 -0
- package/cjs/services/event-service/index.js +4 -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/MigrateLedgerAccount.js +1 -1
- 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 +7 -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 +1 -1
- package/cjs/services/storage-service/DatabaseService.js +51 -0
- package/cjs/services/storage-service/databases/index.js +4 -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 +65 -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 +185 -74
- 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/utils/fetchStaticData.js +2 -1
- package/cjs/utils/index.js +89 -1
- package/cjs/utils/object.js +12 -0
- package/cjs/utils/yield/index.js +3 -0
- package/constants/index.d.ts +6 -1
- package/constants/index.js +6 -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 +11 -9
- 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 +1 -0
- package/koni/background/cron.js +12 -2
- package/koni/background/handlers/Extension.d.ts +17 -1
- package/koni/background/handlers/Extension.js +321 -30
- package/koni/background/handlers/State.d.ts +18 -2
- package/koni/background/handlers/State.js +50 -3
- package/koni/background/handlers/index.js +4 -2
- package/koni/background/subscription.d.ts +6 -1
- package/koni/background/subscription.js +97 -38
- package/package.json +316 -3
- package/services/campaign-service/index.js +9 -6
- package/services/chain-service/constants.d.ts +0 -11
- package/services/chain-service/constants.js +1 -14
- 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 +14 -0
- package/services/earning-service/constants/chains.js +21 -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 +112 -0
- package/services/earning-service/handlers/base.js +226 -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 +6 -0
- package/services/earning-service/handlers/lending/base.js +12 -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 +23 -0
- package/services/earning-service/handlers/lending/interlay.js +176 -0
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +26 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +209 -0
- package/services/earning-service/handlers/liquid-staking/base.d.ts +9 -0
- package/services/earning-service/handlers/liquid-staking/base.js +35 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +45 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.js +272 -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 +25 -0
- package/services/earning-service/handlers/liquid-staking/parallel.js +188 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +34 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +399 -0
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +373 -0
- package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
- package/services/earning-service/handlers/native-staking/astar.js +449 -0
- package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
- package/services/earning-service/handlers/native-staking/base-para.js +129 -0
- package/services/earning-service/handlers/native-staking/base.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/base.js +150 -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 +375 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +533 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +35 -0
- package/services/earning-service/handlers/nomination-pool/index.js +531 -0
- package/services/earning-service/handlers/special.d.ts +56 -0
- package/services/earning-service/handlers/special.js +403 -0
- package/services/earning-service/service.d.ts +45 -0
- package/services/earning-service/service.js +379 -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 +1 -0
- package/services/event-service/index.js +4 -0
- package/services/event-service/types.d.ts +8 -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 +7 -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 +1 -1
- package/services/storage-service/DatabaseService.d.ts +18 -1
- package/services/storage-service/DatabaseService.js +51 -0
- package/services/storage-service/databases/index.d.ts +3 -1
- package/services/storage-service/databases/index.js +4 -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 +9 -0
- package/services/storage-service/db-stores/YieldPositionStore.js +57 -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 +4 -15
- package/services/transaction-service/index.js +183 -72
- 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 +94 -0
- package/types/yield/actions/join/step.js +46 -0
- package/types/yield/actions/join/submit.d.ts +53 -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 +63 -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 +45 -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 +243 -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/fetchStaticData.js +2 -1
- package/utils/index.d.ts +5 -0
- package/utils/index.js +53 -1
- package/utils/object.d.ts +1 -0
- package/utils/object.js +6 -0
|
@@ -0,0 +1,403 @@
|
|
|
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, ExtrinsicType, StakingTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
7
|
+
import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
|
|
8
|
+
import { YIELD_POOL_STAT_REFRESH_INTERVAL } from '@subwallet/extension-base/koni/api/yield/helper/utils';
|
|
9
|
+
import { _getChainNativeTokenSlug } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
|
+
import { YieldStepType, YieldValidationStatus } from '@subwallet/extension-base/types';
|
|
11
|
+
import { t } from 'i18next';
|
|
12
|
+
import { BN, BN_ZERO, noop } from '@polkadot/util';
|
|
13
|
+
import BasePoolHandler from "./base.js";
|
|
14
|
+
export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
|
|
15
|
+
/** Pool's type */
|
|
16
|
+
|
|
17
|
+
get metadataInfo() {
|
|
18
|
+
return {
|
|
19
|
+
altInputAssets: this.altInputAsset,
|
|
20
|
+
derivativeAssets: this.derivativeAssets,
|
|
21
|
+
inputAsset: this.inputAsset,
|
|
22
|
+
rewardAssets: this.rewardAssets,
|
|
23
|
+
feeAssets: this.feeAssets,
|
|
24
|
+
logo: this.logo,
|
|
25
|
+
shortName: this.shortName,
|
|
26
|
+
name: this.name,
|
|
27
|
+
isAvailable: true,
|
|
28
|
+
maintainAsset: this.nativeToken.slug,
|
|
29
|
+
maintainBalance: this.maintainBalance,
|
|
30
|
+
availableMethod: this.availableMethod
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
get isPoolSupportAlternativeFee() {
|
|
34
|
+
return this.feeAssets.length > 1;
|
|
35
|
+
}
|
|
36
|
+
get group() {
|
|
37
|
+
const inputAsset = this.state.getAssetBySlug(this.inputAsset);
|
|
38
|
+
const groupSlug = inputAsset.multiChainAsset;
|
|
39
|
+
return groupSlug || this.inputAsset;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* Subscribe pool info */
|
|
43
|
+
|
|
44
|
+
async subscribePoolInfo(callback) {
|
|
45
|
+
let cancel = false;
|
|
46
|
+
const getStatInterval = () => {
|
|
47
|
+
if (!this.isActive) {
|
|
48
|
+
if (!cancel) {
|
|
49
|
+
const rs = {
|
|
50
|
+
...this.baseInfo,
|
|
51
|
+
type: this.type,
|
|
52
|
+
metadata: {
|
|
53
|
+
...this.metadataInfo,
|
|
54
|
+
description: this.getDescription()
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
callback(rs);
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
this.getPoolStat().then(rs => {
|
|
61
|
+
if (!cancel) {
|
|
62
|
+
callback(rs);
|
|
63
|
+
}
|
|
64
|
+
}).catch(console.error);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
getStatInterval();
|
|
68
|
+
const interval = setInterval(() => {
|
|
69
|
+
if (cancel) {
|
|
70
|
+
clearInterval(interval);
|
|
71
|
+
} else {
|
|
72
|
+
getStatInterval();
|
|
73
|
+
}
|
|
74
|
+
}, YIELD_POOL_STAT_REFRESH_INTERVAL);
|
|
75
|
+
return new Promise(resolve => {
|
|
76
|
+
const rs = () => {
|
|
77
|
+
cancel = true;
|
|
78
|
+
clearInterval(interval);
|
|
79
|
+
};
|
|
80
|
+
resolve(rs);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* Subscribe pool info */
|
|
85
|
+
|
|
86
|
+
/* Get pool reward */
|
|
87
|
+
|
|
88
|
+
async getPoolReward() {
|
|
89
|
+
return new Promise(resolve => resolve(noop));
|
|
90
|
+
}
|
|
91
|
+
async getPoolRewardHistory() {
|
|
92
|
+
return new Promise(resolve => resolve(noop));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Get pool reward */
|
|
96
|
+
|
|
97
|
+
/* Get pool targets */
|
|
98
|
+
|
|
99
|
+
async getPoolTargets() {
|
|
100
|
+
return new Promise(resolve => resolve([]));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* Get pool targets */
|
|
104
|
+
|
|
105
|
+
/* Join pool action */
|
|
106
|
+
|
|
107
|
+
/* Generate steps */
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @async
|
|
111
|
+
* @function getXcmStep
|
|
112
|
+
* */
|
|
113
|
+
async getXcmStep(params) {
|
|
114
|
+
const {
|
|
115
|
+
address,
|
|
116
|
+
amount
|
|
117
|
+
} = params;
|
|
118
|
+
const bnAmount = new BN(amount);
|
|
119
|
+
const inputTokenSlug = this.inputAsset; // assume that the pool only has 1 input token, will update later
|
|
120
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
121
|
+
const inputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, inputTokenInfo.originChain, inputTokenSlug);
|
|
122
|
+
const bnInputTokenBalance = new BN(inputTokenBalance.value);
|
|
123
|
+
if (!bnInputTokenBalance.gte(bnAmount)) {
|
|
124
|
+
if (this.altInputAsset) {
|
|
125
|
+
const altInputTokenSlug = this.altInputAsset;
|
|
126
|
+
const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
|
|
127
|
+
const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, altInputTokenInfo.originChain, altInputTokenSlug);
|
|
128
|
+
const bnAltInputTokenBalance = new BN(altInputTokenBalance.value || '0');
|
|
129
|
+
if (bnAltInputTokenBalance.gt(BN_ZERO)) {
|
|
130
|
+
const step = {
|
|
131
|
+
metadata: {
|
|
132
|
+
sendingValue: bnAmount.toString(),
|
|
133
|
+
originTokenInfo: altInputTokenInfo,
|
|
134
|
+
destinationTokenInfo: inputTokenInfo
|
|
135
|
+
},
|
|
136
|
+
name: 'Transfer DOT from Polkadot',
|
|
137
|
+
type: YieldStepType.XCM
|
|
138
|
+
};
|
|
139
|
+
const xcmOriginSubstrateApi = await this.state.getSubstrateApi(altInputTokenInfo.originChain).isReady;
|
|
140
|
+
const xcmTransfer = await createXcmExtrinsic({
|
|
141
|
+
originTokenInfo: altInputTokenInfo,
|
|
142
|
+
destinationTokenInfo: inputTokenInfo,
|
|
143
|
+
sendingValue: bnAmount.toString(),
|
|
144
|
+
recipient: address,
|
|
145
|
+
chainInfoMap: this.state.getChainInfoMap(),
|
|
146
|
+
substrateApi: xcmOriginSubstrateApi
|
|
147
|
+
});
|
|
148
|
+
const _xcmFeeInfo = await xcmTransfer.paymentInfo(address);
|
|
149
|
+
const xcmFeeInfo = _xcmFeeInfo.toPrimitive();
|
|
150
|
+
// TODO: calculate fee for destination chain
|
|
151
|
+
|
|
152
|
+
const fee = {
|
|
153
|
+
slug: altInputTokenSlug,
|
|
154
|
+
amount: Math.round(xcmFeeInfo.partialFee * 1.2).toString() // TODO
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return [step, fee];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
get defaultSubmitStep() {
|
|
164
|
+
return [this.submitJoinStepInfo, {
|
|
165
|
+
slug: this.feeAssets[0],
|
|
166
|
+
amount: '0'
|
|
167
|
+
}];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @function submitJoinStepInfo
|
|
172
|
+
* @description Base info of submit step
|
|
173
|
+
* @return Fee of the submitting step
|
|
174
|
+
* */
|
|
175
|
+
|
|
176
|
+
async getSubmitStep(params) {
|
|
177
|
+
const fee = await this.getSubmitStepFee(params);
|
|
178
|
+
return [this.submitJoinStepInfo, fee];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/* Generate steps */
|
|
182
|
+
|
|
183
|
+
/* Validate join action */
|
|
184
|
+
|
|
185
|
+
async validateTokenApproveStep(params, path) {
|
|
186
|
+
return Promise.resolve([new TransactionError(BasicTxErrorType.UNSUPPORTED)]);
|
|
187
|
+
}
|
|
188
|
+
async validateXcmStep(params, path, bnInputTokenBalance) {
|
|
189
|
+
const processValidation = {
|
|
190
|
+
ok: true,
|
|
191
|
+
status: YieldValidationStatus.OK
|
|
192
|
+
};
|
|
193
|
+
const bnAmount = new BN(params.amount);
|
|
194
|
+
const altInputTokenSlug = this.altInputAsset || '';
|
|
195
|
+
const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
|
|
196
|
+
const altInputTokenBalance = await this.state.balanceService.getTokenFreeBalance(params.address, altInputTokenInfo.originChain, altInputTokenSlug);
|
|
197
|
+
const missingAmount = bnAmount.sub(bnInputTokenBalance); // TODO: what if input token is not LOCAL ??
|
|
198
|
+
const xcmFee = new BN(path.totalFee[1].amount || '0');
|
|
199
|
+
const xcmAmount = missingAmount.add(xcmFee);
|
|
200
|
+
const bnAltInputTokenBalance = new BN(altInputTokenBalance.value || '0');
|
|
201
|
+
const altInputTokenMinAmount = new BN(altInputTokenInfo.minAmount || '0');
|
|
202
|
+
if (!bnAltInputTokenBalance.sub(xcmAmount).gte(altInputTokenMinAmount)) {
|
|
203
|
+
processValidation.failedStep = path.steps[1];
|
|
204
|
+
processValidation.ok = false;
|
|
205
|
+
processValidation.status = YieldValidationStatus.NOT_ENOUGH_BALANCE;
|
|
206
|
+
return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_BALANCE, processValidation.message, processValidation)];
|
|
207
|
+
}
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
async validateJoinStep(id, params, path, bnInputTokenBalance, isXcmOk) {
|
|
211
|
+
const _poolInfo = await this.getPoolInfo();
|
|
212
|
+
if (!_poolInfo) {
|
|
213
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
214
|
+
}
|
|
215
|
+
const poolInfo = _poolInfo;
|
|
216
|
+
if (!poolInfo.statistic) {
|
|
217
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
218
|
+
}
|
|
219
|
+
const processValidation = {
|
|
220
|
+
ok: true,
|
|
221
|
+
status: YieldValidationStatus.OK
|
|
222
|
+
};
|
|
223
|
+
const feeTokenSlug = path.totalFee[id].slug;
|
|
224
|
+
const feeTokenInfo = this.state.getAssetBySlug(feeTokenSlug);
|
|
225
|
+
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
226
|
+
const bnAmount = new BN(params.amount);
|
|
227
|
+
if (this.feeAssets.length === 1 && feeTokenSlug === defaultFeeTokenSlug) {
|
|
228
|
+
var _path$totalFee$id;
|
|
229
|
+
const bnFeeAmount = new BN(((_path$totalFee$id = path.totalFee[id]) === null || _path$totalFee$id === void 0 ? void 0 : _path$totalFee$id.amount) || '0');
|
|
230
|
+
const feeTokenBalance = await this.state.balanceService.getTokenFreeBalance(params.address, feeTokenInfo.originChain, feeTokenSlug);
|
|
231
|
+
const bnFeeTokenBalance = new BN(feeTokenBalance.value || '0');
|
|
232
|
+
const bnFeeTokenMinAmount = new BN((feeTokenInfo === null || feeTokenInfo === void 0 ? void 0 : feeTokenInfo.minAmount) || '0');
|
|
233
|
+
if (!bnFeeTokenBalance.sub(bnFeeAmount).gte(bnFeeTokenMinAmount)) {
|
|
234
|
+
processValidation.failedStep = path.steps[id];
|
|
235
|
+
processValidation.ok = false;
|
|
236
|
+
processValidation.status = YieldValidationStatus.NOT_ENOUGH_FEE;
|
|
237
|
+
return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_FEE, processValidation.message, processValidation)];
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (!bnAmount.gte(new BN(poolInfo.statistic.minJoinPool || '0'))) {
|
|
241
|
+
processValidation.failedStep = path.steps[id];
|
|
242
|
+
processValidation.ok = false;
|
|
243
|
+
processValidation.status = YieldValidationStatus.NOT_ENOUGH_MIN_JOIN_POOL;
|
|
244
|
+
return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_MIN_JOIN_POOL, processValidation.message, processValidation)];
|
|
245
|
+
}
|
|
246
|
+
if (!isXcmOk && bnAmount.gt(bnInputTokenBalance)) {
|
|
247
|
+
processValidation.failedStep = path.steps[id];
|
|
248
|
+
processValidation.ok = false;
|
|
249
|
+
processValidation.status = YieldValidationStatus.NOT_ENOUGH_BALANCE;
|
|
250
|
+
return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_BALANCE, processValidation.message, processValidation)];
|
|
251
|
+
}
|
|
252
|
+
return [];
|
|
253
|
+
}
|
|
254
|
+
async validateYieldJoin(params, path) {
|
|
255
|
+
const inputTokenSlug = this.inputAsset;
|
|
256
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
257
|
+
const balanceService = this.state.balanceService;
|
|
258
|
+
const inputTokenBalance = await balanceService.getTokenFreeBalance(params.address, inputTokenInfo.originChain, inputTokenSlug);
|
|
259
|
+
const bnInputTokenBalance = new BN(inputTokenBalance.value || '0');
|
|
260
|
+
let isXcmOk = false;
|
|
261
|
+
for (const step of path.steps) {
|
|
262
|
+
const getErrors = async () => {
|
|
263
|
+
switch (step.type) {
|
|
264
|
+
case YieldStepType.DEFAULT:
|
|
265
|
+
return Promise.resolve([]);
|
|
266
|
+
case YieldStepType.XCM:
|
|
267
|
+
return this.validateXcmStep(params, path, bnInputTokenBalance);
|
|
268
|
+
case YieldStepType.TOKEN_APPROVAL:
|
|
269
|
+
return this.validateTokenApproveStep(params, path);
|
|
270
|
+
default:
|
|
271
|
+
return this.validateJoinStep(step.id, params, path, bnInputTokenBalance, isXcmOk);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
const errors = await getErrors();
|
|
275
|
+
if (errors.length) {
|
|
276
|
+
return errors;
|
|
277
|
+
} else if (step.type === YieldStepType.XCM) {
|
|
278
|
+
isXcmOk = true;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return [];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/* Validate join action */
|
|
285
|
+
|
|
286
|
+
/* Submit join action */
|
|
287
|
+
|
|
288
|
+
async handleTokenApproveStep(data, path) {
|
|
289
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
290
|
+
}
|
|
291
|
+
async handleXcmStep(data, path, xcmFee) {
|
|
292
|
+
const {
|
|
293
|
+
address,
|
|
294
|
+
amount
|
|
295
|
+
} = data;
|
|
296
|
+
const destinationTokenSlug = this.inputAsset;
|
|
297
|
+
const originChainInfo = this.state.getChainInfo(COMMON_CHAIN_SLUGS.POLKADOT);
|
|
298
|
+
const originTokenSlug = _getChainNativeTokenSlug(originChainInfo);
|
|
299
|
+
const originTokenInfo = this.state.getAssetBySlug(originTokenSlug);
|
|
300
|
+
const destinationTokenInfo = this.state.getAssetBySlug(destinationTokenSlug);
|
|
301
|
+
const substrateApi = this.state.getSubstrateApi(originChainInfo.slug);
|
|
302
|
+
const inputTokenBalance = await this.state.balanceService.getTokenFreeBalance(address, destinationTokenInfo.originChain, destinationTokenSlug);
|
|
303
|
+
const bnInputTokenBalance = new BN(inputTokenBalance.value);
|
|
304
|
+
const bnXcmFee = new BN(xcmFee);
|
|
305
|
+
const bnAmount = new BN(amount);
|
|
306
|
+
const bnTotalAmount = bnAmount.sub(bnInputTokenBalance).add(bnXcmFee);
|
|
307
|
+
const extrinsic = await createXcmExtrinsic({
|
|
308
|
+
chainInfoMap: this.state.getChainInfoMap(),
|
|
309
|
+
destinationTokenInfo,
|
|
310
|
+
originTokenInfo,
|
|
311
|
+
recipient: address,
|
|
312
|
+
sendingValue: bnTotalAmount.toString(),
|
|
313
|
+
substrateApi
|
|
314
|
+
});
|
|
315
|
+
const xcmData = {
|
|
316
|
+
originNetworkKey: originChainInfo.slug,
|
|
317
|
+
destinationNetworkKey: destinationTokenInfo.originChain,
|
|
318
|
+
from: address,
|
|
319
|
+
to: address,
|
|
320
|
+
value: bnTotalAmount.toString(),
|
|
321
|
+
tokenSlug: originTokenSlug,
|
|
322
|
+
showExtraWarning: true
|
|
323
|
+
};
|
|
324
|
+
return {
|
|
325
|
+
txChain: originChainInfo.slug,
|
|
326
|
+
extrinsicType: ExtrinsicType.TRANSFER_XCM,
|
|
327
|
+
extrinsic,
|
|
328
|
+
txData: xcmData,
|
|
329
|
+
transferNativeAmount: bnTotalAmount.toString()
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
handleYieldJoin(data, path, currentStep) {
|
|
333
|
+
const type = path.steps[currentStep].type;
|
|
334
|
+
switch (type) {
|
|
335
|
+
case YieldStepType.DEFAULT:
|
|
336
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
337
|
+
case YieldStepType.TOKEN_APPROVAL:
|
|
338
|
+
return this.handleTokenApproveStep(data, path);
|
|
339
|
+
case YieldStepType.XCM:
|
|
340
|
+
{
|
|
341
|
+
const xcmFee = path.totalFee[currentStep].amount || '0';
|
|
342
|
+
return this.handleXcmStep(data, path, xcmFee);
|
|
343
|
+
}
|
|
344
|
+
default:
|
|
345
|
+
return this.handleSubmitStep(data, path);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/* Submit join action */
|
|
350
|
+
|
|
351
|
+
/* Join pool action */
|
|
352
|
+
|
|
353
|
+
/* Leave pool action */
|
|
354
|
+
|
|
355
|
+
async validateYieldLeave(amount, address, fastLeave, selectedTarget) {
|
|
356
|
+
const poolInfo = await this.getPoolInfo();
|
|
357
|
+
const poolPosition = await this.getPoolPosition(address);
|
|
358
|
+
if (!poolInfo || !poolInfo.statistic || !poolPosition) {
|
|
359
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
360
|
+
}
|
|
361
|
+
if (!this.availableMethod.defaultUnstake && !fastLeave) {
|
|
362
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
363
|
+
}
|
|
364
|
+
if (!this.availableMethod.fastUnstake && fastLeave) {
|
|
365
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
366
|
+
}
|
|
367
|
+
const errors = [];
|
|
368
|
+
const bnActiveStake = new BN(poolPosition.activeStake);
|
|
369
|
+
const bnRemainingStake = bnActiveStake.sub(new BN(amount));
|
|
370
|
+
const minStake = new BN(poolInfo.statistic.minJoinPool || '0');
|
|
371
|
+
const maxUnstake = poolInfo.statistic.maxWithdrawalRequestPerFarmer;
|
|
372
|
+
if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
|
|
373
|
+
errors.push(new TransactionError(StakingTxErrorType.INVALID_ACTIVE_STAKE));
|
|
374
|
+
}
|
|
375
|
+
if (poolPosition.unstakings.length > maxUnstake) {
|
|
376
|
+
errors.push(new TransactionError(StakingTxErrorType.EXCEED_MAX_UNSTAKING, t('You cannot unstake more than {{number}} times', {
|
|
377
|
+
replace: {
|
|
378
|
+
number: maxUnstake
|
|
379
|
+
}
|
|
380
|
+
})));
|
|
381
|
+
}
|
|
382
|
+
return Promise.resolve(errors);
|
|
383
|
+
}
|
|
384
|
+
handleYieldUnstake(amount, address, selectedTarget) {
|
|
385
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/* Leave pool action */
|
|
389
|
+
|
|
390
|
+
/* Other action */
|
|
391
|
+
|
|
392
|
+
handleYieldCancelUnstake() {
|
|
393
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
394
|
+
}
|
|
395
|
+
handleYieldClaimReward(address, bondReward) {
|
|
396
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
397
|
+
}
|
|
398
|
+
handleYieldWithdraw(address, unstakingInfo) {
|
|
399
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/* Other actions */
|
|
403
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
2
|
+
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
+
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
4
|
+
import { EarningRewardHistoryItem, EarningRewardItem, EarningRewardJson, HandleYieldStepData, HandleYieldStepParams, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, RequestStakeCancelWithdrawal, RequestStakeClaimReward, RequestYieldLeave, RequestYieldWithdrawal, ResponseEarlyValidateYield, TransactionData, ValidateYieldProcessParams, YieldPoolInfo, YieldPoolTarget, YieldPositionInfo } from '@subwallet/extension-base/types';
|
|
5
|
+
import { BehaviorSubject } from 'rxjs';
|
|
6
|
+
import { BasePoolHandler } from './handlers';
|
|
7
|
+
export default class EarningService {
|
|
8
|
+
protected readonly state: KoniState;
|
|
9
|
+
protected handlers: Record<string, BasePoolHandler>;
|
|
10
|
+
private earningRewardSubject;
|
|
11
|
+
private earningRewardHistorySubject;
|
|
12
|
+
private minAmountPercentSubject;
|
|
13
|
+
constructor(state: KoniState);
|
|
14
|
+
private initHandlers;
|
|
15
|
+
getPoolHandler(slug: string): BasePoolHandler | undefined;
|
|
16
|
+
isPoolSupportAlternativeFee(slug: string): boolean;
|
|
17
|
+
subscribeMinAmountPercent(): BehaviorSubject<Record<string, number>>;
|
|
18
|
+
getMinAmountPercent(): Record<string, number>;
|
|
19
|
+
subscribePoolsInfo(callback: (rs: YieldPoolInfo) => void): Promise<VoidFunction>;
|
|
20
|
+
subscribePoolPositions(addresses: string[], callback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
21
|
+
updateEarningReward(stakingRewardData: EarningRewardItem): void;
|
|
22
|
+
getPoolReward(addresses: string[], callback: (result: EarningRewardItem) => void): Promise<VoidFunction>;
|
|
23
|
+
subscribeEarningReward(): BehaviorSubject<EarningRewardJson>;
|
|
24
|
+
getEarningRewards(): EarningRewardJson;
|
|
25
|
+
fetchPoolRewardHistory(addresses: string[], callback: (result: EarningRewardHistoryItem) => void): Promise<VoidFunction>;
|
|
26
|
+
updateEarningRewardHistory(earningRewardHistory: EarningRewardHistoryItem): void;
|
|
27
|
+
subscribeEarningRewardHistory(): BehaviorSubject<Record<string, EarningRewardHistoryItem>>;
|
|
28
|
+
getEarningRewardHistory(): Record<string, EarningRewardHistoryItem>;
|
|
29
|
+
/**
|
|
30
|
+
* @async
|
|
31
|
+
* @function getPoolTargets
|
|
32
|
+
* @param {string} slug - Pool's slug
|
|
33
|
+
* @return {Promise<YieldPoolTarget[]>} List of pool's target
|
|
34
|
+
* */
|
|
35
|
+
getPoolTargets(slug: string): Promise<YieldPoolTarget[]>;
|
|
36
|
+
earlyValidateJoin(request: RequestEarlyValidateYield): Promise<ResponseEarlyValidateYield>;
|
|
37
|
+
generateOptimalSteps(params: OptimalYieldPathParams): Promise<OptimalYieldPath>;
|
|
38
|
+
validateYieldJoin(params: ValidateYieldProcessParams): Promise<TransactionError[]>;
|
|
39
|
+
handleYieldJoin(params: HandleYieldStepParams): Promise<HandleYieldStepData>;
|
|
40
|
+
validateYieldLeave(params: RequestYieldLeave): Promise<TransactionError[]>;
|
|
41
|
+
handleYieldLeave(params: RequestYieldLeave): Promise<[ExtrinsicType, TransactionData]>;
|
|
42
|
+
handleYieldWithdraw(params: RequestYieldWithdrawal): Promise<TransactionData>;
|
|
43
|
+
handleYieldCancelUnstake(params: RequestStakeCancelWithdrawal): Promise<TransactionData>;
|
|
44
|
+
handleYieldClaimReward(params: RequestStakeClaimReward): Promise<TransactionData>;
|
|
45
|
+
}
|