@subwallet/extension-base 1.1.33-beta.0 → 1.1.34-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 +69 -111
- package/background/KoniTypes.js +13 -19
- package/background/errors/TransactionError.js +0 -9
- package/cjs/background/KoniTypes.js +16 -20
- package/cjs/background/errors/TransactionError.js +0 -9
- package/cjs/constants/index.js +4 -19
- package/cjs/koni/api/nft/config.js +23 -33
- package/cjs/koni/api/nft/index.js +0 -14
- package/cjs/koni/api/nft/nft.js +22 -1
- package/cjs/koni/api/staking/bonding/amplitude.js +16 -19
- package/cjs/koni/api/staking/bonding/astar.js +10 -11
- package/cjs/koni/api/staking/bonding/index.js +1 -4
- package/cjs/koni/api/staking/bonding/paraChain.js +23 -25
- package/cjs/koni/api/staking/bonding/relayChain.js +45 -48
- package/cjs/koni/api/staking/bonding/utils.js +86 -104
- package/cjs/koni/api/staking/index.js +5 -6
- package/cjs/koni/api/staking/paraChain.js +17 -10
- package/cjs/koni/api/staking/relayChain.js +2 -3
- package/cjs/koni/background/cron.js +21 -3
- package/cjs/koni/background/handlers/Extension.js +69 -368
- package/cjs/koni/background/handlers/State.js +12 -18
- package/cjs/koni/background/handlers/index.js +2 -4
- package/cjs/koni/background/subscription.js +104 -7
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +1 -3
- package/cjs/services/campaign-service/index.js +6 -9
- package/cjs/services/chain-service/constants.js +19 -2
- package/cjs/services/chain-service/handler/SubstrateApi.js +10 -5
- package/cjs/services/chain-service/index.js +101 -40
- package/cjs/services/chain-service/utils.js +69 -7
- package/cjs/services/event-service/index.js +0 -5
- package/cjs/services/keyring-service/index.js +2 -14
- 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/index.js +1 -6
- package/cjs/services/notification-service/NotificationService.js +1 -1
- package/cjs/services/storage-service/DatabaseService.js +0 -63
- package/cjs/services/storage-service/databases/index.js +0 -4
- package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/cjs/services/subscan-service/index.js +0 -16
- package/cjs/services/transaction-service/event-parser/index.js +0 -58
- package/cjs/services/transaction-service/helpers/index.js +1 -3
- package/cjs/services/transaction-service/index.js +75 -249
- package/cjs/services/transaction-service/utils.js +0 -1
- package/cjs/types/index.js +0 -44
- package/cjs/utils/fetchStaticData.js +1 -2
- package/cjs/utils/index.js +1 -89
- package/cjs/utils/number.js +2 -6
- package/constants/index.d.ts +1 -6
- package/constants/index.js +1 -6
- package/koni/api/nft/config.js +23 -33
- package/koni/api/nft/index.js +1 -15
- package/koni/api/nft/nft.js +23 -2
- package/koni/api/staking/bonding/amplitude.js +10 -13
- package/koni/api/staking/bonding/astar.js +8 -9
- package/koni/api/staking/bonding/index.d.ts +1 -1
- package/koni/api/staking/bonding/index.js +1 -5
- package/koni/api/staking/bonding/paraChain.js +10 -12
- package/koni/api/staking/bonding/relayChain.d.ts +2 -2
- package/koni/api/staking/bonding/relayChain.js +30 -33
- package/koni/api/staking/bonding/utils.d.ts +38 -15
- package/koni/api/staking/bonding/utils.js +69 -85
- package/koni/api/staking/index.js +1 -2
- package/koni/api/staking/paraChain.js +18 -11
- package/koni/api/staking/relayChain.js +3 -4
- package/koni/background/cron.d.ts +4 -0
- package/koni/background/cron.js +22 -4
- package/koni/background/handlers/Extension.d.ts +1 -17
- package/koni/background/handlers/Extension.js +30 -327
- package/koni/background/handlers/State.d.ts +1 -6
- package/koni/background/handlers/State.js +12 -17
- package/koni/background/handlers/index.js +2 -4
- package/koni/background/subscription.d.ts +6 -1
- package/koni/background/subscription.js +104 -8
- package/package.json +7 -320
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +2 -4
- package/services/campaign-service/index.js +6 -9
- package/services/chain-service/constants.d.ts +13 -0
- package/services/chain-service/constants.js +15 -0
- package/services/chain-service/handler/SubstrateApi.js +10 -5
- package/services/chain-service/index.d.ts +9 -1
- package/services/chain-service/index.js +97 -37
- package/services/chain-service/utils.d.ts +10 -2
- package/services/chain-service/utils.js +67 -6
- package/services/event-service/index.d.ts +0 -2
- package/services/event-service/index.js +0 -5
- package/services/event-service/types.d.ts +0 -9
- package/services/keyring-service/index.d.ts +1 -2
- package/services/keyring-service/index.js +2 -14
- package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/services/migration-service/scripts/index.js +1 -6
- package/services/notification-service/NotificationService.js +1 -1
- package/services/storage-service/DatabaseService.d.ts +1 -22
- package/services/storage-service/DatabaseService.js +0 -63
- package/services/storage-service/databases/index.d.ts +1 -3
- package/services/storage-service/databases/index.js +0 -4
- package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/services/subscan-service/index.d.ts +2 -3
- package/services/subscan-service/index.js +0 -15
- package/services/subscan-service/types.d.ts +0 -20
- package/services/transaction-service/event-parser/index.d.ts +1 -3
- package/services/transaction-service/event-parser/index.js +1 -57
- package/services/transaction-service/helpers/index.js +1 -3
- package/services/transaction-service/index.d.ts +13 -6
- package/services/transaction-service/index.js +73 -247
- package/services/transaction-service/types.d.ts +0 -2
- package/services/transaction-service/utils.js +0 -1
- package/types/index.d.ts +0 -5
- package/types/index.js +1 -5
- package/utils/fetchStaticData.js +1 -2
- package/utils/index.d.ts +0 -5
- package/utils/index.js +0 -52
- package/utils/number.d.ts +1 -2
- package/utils/number.js +1 -2
- package/cjs/koni/api/dotsama/balance.js +0 -464
- package/cjs/koni/api/nft/ordinal_nft/constants.js +0 -21
- package/cjs/koni/api/nft/ordinal_nft/index.js +0 -121
- package/cjs/koni/api/nft/ordinal_nft/utils.js +0 -41
- package/cjs/koni/api/yield/helper/utils.js +0 -46
- package/cjs/services/earning-service/constants/chains.js +0 -30
- package/cjs/services/earning-service/constants/index.js +0 -27
- package/cjs/services/earning-service/constants/step.js +0 -18
- package/cjs/services/earning-service/handlers/base.js +0 -262
- package/cjs/services/earning-service/handlers/index.js +0 -60
- package/cjs/services/earning-service/handlers/lending/base.js +0 -81
- package/cjs/services/earning-service/handlers/lending/index.js +0 -13
- package/cjs/services/earning-service/handlers/lending/interlay.js +0 -192
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +0 -240
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +0 -97
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +0 -298
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +0 -34
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +0 -227
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -404
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +0 -434
- package/cjs/services/earning-service/handlers/native-staking/astar.js +0 -466
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +0 -146
- package/cjs/services/earning-service/handlers/native-staking/base.js +0 -161
- package/cjs/services/earning-service/handlers/native-staking/index.js +0 -34
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +0 -390
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +0 -567
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +0 -566
- package/cjs/services/earning-service/handlers/special.js +0 -493
- package/cjs/services/earning-service/service.js +0 -740
- package/cjs/services/earning-service/utils/index.js +0 -128
- package/cjs/services/migration-service/scripts/DeleteEarningData.js +0 -21
- package/cjs/services/migration-service/scripts/EnableEarningChains.js +0 -21
- package/cjs/services/migration-service/scripts/MigrateEthProvider.js +0 -17
- package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +0 -17
- package/cjs/services/migration-service/scripts/MigrateProvider.js +0 -29
- package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +0 -21
- package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +0 -21
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +0 -149
- package/cjs/services/mint-campaign-service/campaigns/index.js +0 -13
- package/cjs/services/mint-campaign-service/constants.js +0 -11
- package/cjs/services/mint-campaign-service/index.js +0 -18
- package/cjs/services/storage-service/db-stores/YieldPoolStore.js +0 -36
- package/cjs/services/storage-service/db-stores/YieldPositionStore.js +0 -71
- package/cjs/services/storage-service/index.js +0 -241
- package/cjs/types/campaigns/index.js +0 -16
- package/cjs/types/campaigns/unlock-dot.js +0 -1
- package/cjs/types/ordinal.js +0 -1
- package/cjs/types/transaction.js +0 -1
- package/cjs/types/yield/actions/index.js +0 -27
- package/cjs/types/yield/actions/join/index.js +0 -38
- package/cjs/types/yield/actions/join/step.js +0 -47
- package/cjs/types/yield/actions/join/submit.js +0 -1
- package/cjs/types/yield/actions/join/validate.js +0 -16
- package/cjs/types/yield/actions/others.js +0 -1
- package/cjs/types/yield/index.js +0 -27
- package/cjs/types/yield/info/account/index.js +0 -49
- package/cjs/types/yield/info/account/info.js +0 -1
- package/cjs/types/yield/info/account/reward.js +0 -1
- package/cjs/types/yield/info/account/target.js +0 -32
- package/cjs/types/yield/info/account/unstake.js +0 -27
- package/cjs/types/yield/info/base.js +0 -41
- package/cjs/types/yield/info/chain/index.js +0 -27
- package/cjs/types/yield/info/chain/info.js +0 -1
- package/cjs/types/yield/info/chain/target.js +0 -1
- package/cjs/types/yield/info/index.js +0 -49
- package/cjs/types/yield/info/pallet.js +0 -15
- package/cjs/types.js +0 -1
- package/cjs/utils/address.js +0 -34
- package/cjs/utils/keyring.js +0 -57
- package/cjs/utils/object.js +0 -12
- package/koni/api/nft/ordinal_nft/constants.d.ts +0 -9
- package/koni/api/nft/ordinal_nft/constants.js +0 -12
- package/koni/api/nft/ordinal_nft/index.d.ts +0 -8
- package/koni/api/nft/ordinal_nft/index.js +0 -114
- package/koni/api/nft/ordinal_nft/utils.d.ts +0 -2
- package/koni/api/nft/ordinal_nft/utils.js +0 -33
- package/koni/api/yield/helper/utils.d.ts +0 -10
- package/koni/api/yield/helper/utils.js +0 -32
- package/services/earning-service/constants/abis/compound_finance_v2_abi.json +0 -1235
- package/services/earning-service/constants/abis/st_liquid_token_abi.json +0 -1355
- package/services/earning-service/constants/chains.d.ts +0 -15
- package/services/earning-service/constants/chains.js +0 -22
- package/services/earning-service/constants/index.d.ts +0 -2
- package/services/earning-service/constants/index.js +0 -5
- package/services/earning-service/constants/step.d.ts +0 -3
- package/services/earning-service/constants/step.js +0 -10
- package/services/earning-service/handlers/base.d.ts +0 -113
- package/services/earning-service/handlers/base.js +0 -256
- package/services/earning-service/handlers/index.d.ts +0 -5
- package/services/earning-service/handlers/index.js +0 -8
- package/services/earning-service/handlers/lending/base.d.ts +0 -8
- package/services/earning-service/handlers/lending/base.js +0 -73
- package/services/earning-service/handlers/lending/index.d.ts +0 -1
- package/services/earning-service/handlers/lending/index.js +0 -4
- package/services/earning-service/handlers/lending/interlay.d.ts +0 -24
- package/services/earning-service/handlers/lending/interlay.js +0 -184
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +0 -27
- package/services/earning-service/handlers/liquid-staking/acala.js +0 -232
- package/services/earning-service/handlers/liquid-staking/base.d.ts +0 -11
- package/services/earning-service/handlers/liquid-staking/base.js +0 -89
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +0 -46
- package/services/earning-service/handlers/liquid-staking/bifrost.js +0 -287
- package/services/earning-service/handlers/liquid-staking/index.d.ts +0 -4
- package/services/earning-service/handlers/liquid-staking/index.js +0 -7
- package/services/earning-service/handlers/liquid-staking/parallel.d.ts +0 -26
- package/services/earning-service/handlers/liquid-staking/parallel.js +0 -219
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +0 -34
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -394
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +0 -22
- package/services/earning-service/handlers/native-staking/amplitude.js +0 -425
- package/services/earning-service/handlers/native-staking/astar.d.ts +0 -19
- package/services/earning-service/handlers/native-staking/astar.js +0 -456
- package/services/earning-service/handlers/native-staking/base-para.d.ts +0 -11
- package/services/earning-service/handlers/native-staking/base-para.js +0 -138
- package/services/earning-service/handlers/native-staking/base.d.ts +0 -21
- package/services/earning-service/handlers/native-staking/base.js +0 -152
- package/services/earning-service/handlers/native-staking/index.d.ts +0 -4
- package/services/earning-service/handlers/native-staking/index.js +0 -7
- package/services/earning-service/handlers/native-staking/para-chain.d.ts +0 -15
- package/services/earning-service/handlers/native-staking/para-chain.js +0 -382
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +0 -21
- package/services/earning-service/handlers/native-staking/relay-chain.js +0 -558
- package/services/earning-service/handlers/nomination-pool/index.d.ts +0 -36
- package/services/earning-service/handlers/nomination-pool/index.js +0 -556
- package/services/earning-service/handlers/special.d.ts +0 -64
- package/services/earning-service/handlers/special.js +0 -485
- package/services/earning-service/service.d.ts +0 -94
- package/services/earning-service/service.js +0 -729
- package/services/earning-service/utils/index.d.ts +0 -18
- package/services/earning-service/utils/index.js +0 -112
- package/services/migration-service/scripts/DeleteEarningData.d.ts +0 -4
- package/services/migration-service/scripts/DeleteEarningData.js +0 -13
- package/services/migration-service/scripts/EnableEarningChains.d.ts +0 -4
- package/services/migration-service/scripts/EnableEarningChains.js +0 -13
- package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +0 -4
- package/services/migration-service/scripts/databases/MigrateEarningHistory.js +0 -13
- package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +0 -4
- package/services/migration-service/scripts/databases/MigrateEarningVersion.js +0 -13
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +0 -13
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +0 -139
- package/services/mint-campaign-service/campaigns/index.d.ts +0 -1
- package/services/mint-campaign-service/campaigns/index.js +0 -4
- package/services/mint-campaign-service/constants.d.ts +0 -1
- package/services/mint-campaign-service/constants.js +0 -4
- package/services/mint-campaign-service/index.d.ts +0 -7
- package/services/mint-campaign-service/index.js +0 -11
- package/services/storage-service/db-stores/YieldPoolStore.d.ts +0 -10
- package/services/storage-service/db-stores/YieldPoolStore.js +0 -28
- package/services/storage-service/db-stores/YieldPositionStore.d.ts +0 -11
- package/services/storage-service/db-stores/YieldPositionStore.js +0 -63
- package/types/campaigns/index.d.ts +0 -1
- package/types/campaigns/index.js +0 -4
- package/types/campaigns/unlock-dot.d.ts +0 -71
- package/types/campaigns/unlock-dot.js +0 -1
- package/types/ordinal.d.ts +0 -69
- package/types/ordinal.js +0 -1
- package/types/transaction.d.ts +0 -3
- package/types/transaction.js +0 -1
- package/types/yield/actions/index.d.ts +0 -2
- package/types/yield/actions/index.js +0 -5
- package/types/yield/actions/join/index.d.ts +0 -3
- package/types/yield/actions/join/index.js +0 -6
- package/types/yield/actions/join/step.d.ts +0 -95
- package/types/yield/actions/join/step.js +0 -46
- package/types/yield/actions/join/submit.d.ts +0 -58
- package/types/yield/actions/join/submit.js +0 -1
- package/types/yield/actions/join/validate.d.ts +0 -18
- package/types/yield/actions/join/validate.js +0 -10
- package/types/yield/actions/others.d.ts +0 -85
- package/types/yield/actions/others.js +0 -1
- package/types/yield/index.d.ts +0 -2
- package/types/yield/index.js +0 -5
- package/types/yield/info/account/index.d.ts +0 -4
- package/types/yield/info/account/index.js +0 -7
- package/types/yield/info/account/info.d.ts +0 -92
- package/types/yield/info/account/info.js +0 -1
- package/types/yield/info/account/reward.d.ts +0 -47
- package/types/yield/info/account/reward.js +0 -1
- package/types/yield/info/account/target.d.ts +0 -43
- package/types/yield/info/account/target.js +0 -27
- package/types/yield/info/account/unstake.d.ts +0 -31
- package/types/yield/info/account/unstake.js +0 -22
- package/types/yield/info/base.d.ts +0 -45
- package/types/yield/info/base.js +0 -36
- package/types/yield/info/chain/index.d.ts +0 -2
- package/types/yield/info/chain/index.js +0 -5
- package/types/yield/info/chain/info.d.ts +0 -252
- package/types/yield/info/chain/info.js +0 -1
- package/types/yield/info/chain/target.d.ts +0 -37
- package/types/yield/info/chain/target.js +0 -1
- package/types/yield/info/index.d.ts +0 -4
- package/types/yield/info/index.js +0 -7
- package/types/yield/info/pallet.d.ts +0 -143
- package/types/yield/info/pallet.js +0 -9
- package/utils/object.d.ts +0 -1
- package/utils/object.js +0 -6
|
@@ -1,184 +0,0 @@
|
|
|
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, ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
-
import { _getTokenOnChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
-
import { EarningStatus, YieldStepType } from '@subwallet/extension-base/types';
|
|
8
|
-
import { BN, BN_TEN, BN_ZERO } from '@polkadot/util';
|
|
9
|
-
import { fakeAddress } from "../../constants/index.js";
|
|
10
|
-
import BaseLendingPoolHandler from "./base.js";
|
|
11
|
-
export default class InterlayLendingPoolHandler extends BaseLendingPoolHandler {
|
|
12
|
-
altInputAsset = 'polkadot-NATIVE-DOT';
|
|
13
|
-
derivativeAssets = ['interlay-LOCAL-qDOT'];
|
|
14
|
-
inputAsset = 'interlay-LOCAL-DOT';
|
|
15
|
-
rewardAssets = ['interlay-LOCAL-DOT'];
|
|
16
|
-
feeAssets = ['interlay-NATIVE-INTR', 'interlay-LOCAL-DOT'];
|
|
17
|
-
availableMethod = {
|
|
18
|
-
join: true,
|
|
19
|
-
defaultUnstake: false,
|
|
20
|
-
fastUnstake: true,
|
|
21
|
-
cancelUnstake: false,
|
|
22
|
-
withdraw: false,
|
|
23
|
-
claimReward: false
|
|
24
|
-
};
|
|
25
|
-
rateDecimals = 18;
|
|
26
|
-
constructor(state, chain) {
|
|
27
|
-
super(state, chain);
|
|
28
|
-
const chainInfo = this.chainInfo;
|
|
29
|
-
this.slug = `DOT___lending___${chain}`;
|
|
30
|
-
this.name = `${chainInfo.name} Lending`;
|
|
31
|
-
this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
|
|
32
|
-
}
|
|
33
|
-
getDescription() {
|
|
34
|
-
return 'Earn rewards by lending DOT';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/* Subscribe pool info */
|
|
38
|
-
|
|
39
|
-
async getPoolStat() {
|
|
40
|
-
const substrateApi = await this.substrateApi.isReady;
|
|
41
|
-
const inputTokenSlug = this.inputAsset;
|
|
42
|
-
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
43
|
-
const _exchangeRate = await substrateApi.api.query.loans.exchangeRate(_getTokenOnChainInfo(inputTokenInfo));
|
|
44
|
-
const exchangeRate = _exchangeRate.toPrimitive();
|
|
45
|
-
const decimals = 10 ** this.rateDecimals;
|
|
46
|
-
this.updateExchangeRate(exchangeRate);
|
|
47
|
-
return {
|
|
48
|
-
...this.baseInfo,
|
|
49
|
-
type: this.type,
|
|
50
|
-
metadata: {
|
|
51
|
-
...this.metadataInfo,
|
|
52
|
-
description: this.getDescription()
|
|
53
|
-
},
|
|
54
|
-
statistic: {
|
|
55
|
-
assetEarning: [{
|
|
56
|
-
slug: this.rewardAssets[0],
|
|
57
|
-
apr: 1.29,
|
|
58
|
-
exchangeRate: exchangeRate / decimals
|
|
59
|
-
}],
|
|
60
|
-
maxCandidatePerFarmer: 1,
|
|
61
|
-
maxWithdrawalRequestPerFarmer: 1,
|
|
62
|
-
earningThreshold: {
|
|
63
|
-
join: '10000000000',
|
|
64
|
-
defaultUnstake: '0',
|
|
65
|
-
fastUnstake: '0'
|
|
66
|
-
},
|
|
67
|
-
totalApr: 1.29,
|
|
68
|
-
tvl: '291890000000000'
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/* Subscribe pool info */
|
|
74
|
-
|
|
75
|
-
/* Subscribe pool position */
|
|
76
|
-
|
|
77
|
-
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
78
|
-
let cancel = false;
|
|
79
|
-
const substrateApi = this.substrateApi;
|
|
80
|
-
await substrateApi.isReady;
|
|
81
|
-
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
82
|
-
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
83
|
-
const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, _getTokenOnChainInfo(derivativeTokenInfo)]), async _balances => {
|
|
84
|
-
if (cancel) {
|
|
85
|
-
unsub();
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
const exchangeRate = await this.getExchangeRate();
|
|
89
|
-
const decimals = BN_TEN.pow(new BN(this.rateDecimals));
|
|
90
|
-
const balances = _balances;
|
|
91
|
-
for (let i = 0; i < balances.length; i++) {
|
|
92
|
-
const balanceItem = balances[i];
|
|
93
|
-
const address = useAddresses[i];
|
|
94
|
-
const bnActiveBalance = balanceItem.free || BN_ZERO;
|
|
95
|
-
const bnTotalBalance = bnActiveBalance.mul(new BN(exchangeRate)).div(decimals);
|
|
96
|
-
const result = {
|
|
97
|
-
...this.baseInfo,
|
|
98
|
-
type: this.type,
|
|
99
|
-
address,
|
|
100
|
-
balanceToken: this.inputAsset,
|
|
101
|
-
totalStake: bnTotalBalance.toString(),
|
|
102
|
-
activeStake: bnActiveBalance.toString(),
|
|
103
|
-
unstakeBalance: '0',
|
|
104
|
-
status: bnActiveBalance.gt(BN_ZERO) ? EarningStatus.EARNING_REWARD : EarningStatus.NOT_EARNING,
|
|
105
|
-
derivativeToken: derivativeTokenSlug,
|
|
106
|
-
isBondedBefore: bnTotalBalance.gt(BN_ZERO),
|
|
107
|
-
nominations: [],
|
|
108
|
-
unstakings: []
|
|
109
|
-
};
|
|
110
|
-
resultCallback(result);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
return () => {
|
|
114
|
-
cancel = true;
|
|
115
|
-
unsub();
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/* Subscribe pool position */
|
|
120
|
-
|
|
121
|
-
/* Join pool action */
|
|
122
|
-
|
|
123
|
-
get submitJoinStepInfo() {
|
|
124
|
-
return {
|
|
125
|
-
name: 'Mint qDOT',
|
|
126
|
-
type: YieldStepType.MINT_QDOT
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
async getSubmitStepFee(params) {
|
|
130
|
-
const poolOriginSubstrateApi = await this.substrateApi.isReady;
|
|
131
|
-
const inputTokenSlug = this.inputAsset;
|
|
132
|
-
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
133
|
-
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
134
|
-
if (new BN(params.amount).gt(BN_ZERO)) {
|
|
135
|
-
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.loans.mint(_getTokenOnChainInfo(inputTokenInfo), params.amount).paymentInfo(fakeAddress);
|
|
136
|
-
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
137
|
-
return {
|
|
138
|
-
amount: mintFeeInfo.partialFee.toString(),
|
|
139
|
-
slug: defaultFeeTokenSlug
|
|
140
|
-
};
|
|
141
|
-
} else {
|
|
142
|
-
return {
|
|
143
|
-
amount: '0',
|
|
144
|
-
slug: defaultFeeTokenSlug
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
async handleSubmitStep(data, path) {
|
|
149
|
-
const substrateApi = await this.substrateApi.isReady;
|
|
150
|
-
const inputTokenSlug = this.inputAsset;
|
|
151
|
-
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
152
|
-
const extrinsic = substrateApi.api.tx.loans.mint(_getTokenOnChainInfo(inputTokenInfo), data.amount);
|
|
153
|
-
return {
|
|
154
|
-
txChain: this.chain,
|
|
155
|
-
extrinsicType: ExtrinsicType.MINT_QDOT,
|
|
156
|
-
extrinsic,
|
|
157
|
-
txData: data,
|
|
158
|
-
transferNativeAmount: '0',
|
|
159
|
-
chainType: ChainType.SUBSTRATE
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/* Join pool action */
|
|
164
|
-
|
|
165
|
-
/* Leave pool action */
|
|
166
|
-
|
|
167
|
-
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
168
|
-
const substrateApi = await this.substrateApi.isReady;
|
|
169
|
-
// @ts-ignore
|
|
170
|
-
const inputTokenSlug = this.inputAsset;
|
|
171
|
-
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
172
|
-
const yieldPositionInfo = await this.getPoolPosition(address);
|
|
173
|
-
if (!yieldPositionInfo) {
|
|
174
|
-
return Promise.reject(new TransactionError(BasicTxErrorType.INVALID_PARAMS));
|
|
175
|
-
}
|
|
176
|
-
const bnAmount = new BN(amount);
|
|
177
|
-
const bnActiveBalance = new BN(yieldPositionInfo.activeStake);
|
|
178
|
-
const redeemAll = bnAmount.eq(bnActiveBalance);
|
|
179
|
-
const extrinsic = !redeemAll ? substrateApi.api.tx.loans.redeem(_getTokenOnChainInfo(inputTokenInfo), amount) : substrateApi.api.tx.loans.redeemAll(_getTokenOnChainInfo(inputTokenInfo));
|
|
180
|
-
return [ExtrinsicType.REDEEM_QDOT, extrinsic];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/* Leave pool action */
|
|
184
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
-
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
3
|
-
import { BaseYieldStepDetail, HandleYieldStepData, LiquidYieldPoolInfo, OptimalYieldPath, OptimalYieldPathParams, SubmitYieldJoinData, TransactionData, UnstakingInfo, YieldPoolMethodInfo, YieldPositionInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
|
|
4
|
-
import BaseLiquidStakingPoolHandler from './base';
|
|
5
|
-
export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPoolHandler {
|
|
6
|
-
protected readonly name: string;
|
|
7
|
-
protected readonly shortName: string;
|
|
8
|
-
protected readonly altInputAsset: string;
|
|
9
|
-
protected readonly derivativeAssets: string[];
|
|
10
|
-
protected readonly inputAsset: string;
|
|
11
|
-
protected readonly rewardAssets: string[];
|
|
12
|
-
protected readonly feeAssets: string[];
|
|
13
|
-
readonly minAmountPercent = 0.98;
|
|
14
|
-
protected readonly rateDecimals = 10;
|
|
15
|
-
protected readonly availableMethod: YieldPoolMethodInfo;
|
|
16
|
-
slug: string;
|
|
17
|
-
constructor(state: KoniState, chain: string);
|
|
18
|
-
protected getDescription(): string;
|
|
19
|
-
getPoolStat(): Promise<LiquidYieldPoolInfo>;
|
|
20
|
-
subscribePoolPosition(useAddresses: string[], resultCallback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
21
|
-
get submitJoinStepInfo(): BaseYieldStepDetail;
|
|
22
|
-
getSubmitStepFee(params: OptimalYieldPathParams): Promise<YieldTokenBaseInfo>;
|
|
23
|
-
handleSubmitStep(data: SubmitYieldJoinData, path: OptimalYieldPath): Promise<HandleYieldStepData>;
|
|
24
|
-
handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
25
|
-
handleYieldUnstake(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
26
|
-
handleYieldWithdraw(address: string, unstakingInfo: UnstakingInfo): Promise<TransactionData>;
|
|
27
|
-
}
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
-
import { _getTokenOnChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
|
-
import { fakeAddress } from '@subwallet/extension-base/services/earning-service/constants';
|
|
7
|
-
import { EarningStatus, UnstakingStatus, YieldStepType } from '@subwallet/extension-base/types';
|
|
8
|
-
import fetch from 'cross-fetch';
|
|
9
|
-
import { BN, BN_TEN, BN_ZERO } from '@polkadot/util';
|
|
10
|
-
import BaseLiquidStakingPoolHandler from "./base.js";
|
|
11
|
-
const GRAPHQL_API = 'https://api.polkawallet.io/acala-liquid-staking-subql';
|
|
12
|
-
const EXCHANGE_RATE_REQUEST = 'query { dailySummaries(first:30, orderBy:TIMESTAMP_DESC) {nodes { exchangeRate timestamp }}}';
|
|
13
|
-
export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPoolHandler {
|
|
14
|
-
altInputAsset = 'polkadot-NATIVE-DOT';
|
|
15
|
-
derivativeAssets = ['acala-LOCAL-LDOT'];
|
|
16
|
-
inputAsset = 'acala-LOCAL-DOT';
|
|
17
|
-
rewardAssets = ['acala-LOCAL-DOT'];
|
|
18
|
-
feeAssets = ['acala-NATIVE-ACA', 'acala-LOCAL-DOT'];
|
|
19
|
-
minAmountPercent = 0.98;
|
|
20
|
-
rateDecimals = 10;
|
|
21
|
-
availableMethod = {
|
|
22
|
-
join: true,
|
|
23
|
-
defaultUnstake: true,
|
|
24
|
-
fastUnstake: true,
|
|
25
|
-
cancelUnstake: false,
|
|
26
|
-
withdraw: true,
|
|
27
|
-
claimReward: false
|
|
28
|
-
};
|
|
29
|
-
constructor(state, chain) {
|
|
30
|
-
super(state, chain);
|
|
31
|
-
const chainInfo = this.chainInfo;
|
|
32
|
-
this.slug = `DOT___liquid_staking___${chain}`;
|
|
33
|
-
this.name = `${chainInfo.name} Liquid Staking`;
|
|
34
|
-
this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
|
|
35
|
-
}
|
|
36
|
-
getDescription() {
|
|
37
|
-
return 'Stake DOT to earn yield on LDOT';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/* Subscribe pool info */
|
|
41
|
-
|
|
42
|
-
async getPoolStat() {
|
|
43
|
-
const substrateApi = await this.substrateApi.isReady;
|
|
44
|
-
const stakingMetaPromise = new Promise(function (resolve) {
|
|
45
|
-
fetch(GRAPHQL_API, {
|
|
46
|
-
method: 'POST',
|
|
47
|
-
headers: {
|
|
48
|
-
'Content-Type': 'application/json'
|
|
49
|
-
},
|
|
50
|
-
body: JSON.stringify({
|
|
51
|
-
query: EXCHANGE_RATE_REQUEST
|
|
52
|
-
})
|
|
53
|
-
}).then(res => {
|
|
54
|
-
resolve(res.json());
|
|
55
|
-
}).catch(console.error);
|
|
56
|
-
});
|
|
57
|
-
const [_toBondPool, _totalStakingBonded, _stakingMeta] = await Promise.all([substrateApi.api.query.homa.toBondPool(), substrateApi.api.query.homa.totalStakingBonded(), stakingMetaPromise]);
|
|
58
|
-
const mintThreshold = substrateApi.api.consts.homa.mintThreshold.toString();
|
|
59
|
-
const redeemThreshold = substrateApi.api.consts.homa.redeemThreshold.toString();
|
|
60
|
-
const stakingMeta = _stakingMeta;
|
|
61
|
-
const stakingMetaList = stakingMeta.data.dailySummaries.nodes;
|
|
62
|
-
const latestExchangeRate = parseInt(stakingMetaList[0].exchangeRate);
|
|
63
|
-
const decimals = 10 ** this.rateDecimals;
|
|
64
|
-
this.updateExchangeRate(latestExchangeRate);
|
|
65
|
-
const endingBalance = parseInt(stakingMetaList[0].exchangeRate);
|
|
66
|
-
const beginBalance = parseInt(stakingMetaList[29].exchangeRate);
|
|
67
|
-
const diff = endingBalance / beginBalance;
|
|
68
|
-
const apy = diff ** (365 / 30) - 1;
|
|
69
|
-
const toBondPool = new BN(_toBondPool.toString());
|
|
70
|
-
const totalStakingBonded = new BN(_totalStakingBonded.toString());
|
|
71
|
-
return {
|
|
72
|
-
...this.baseInfo,
|
|
73
|
-
type: this.type,
|
|
74
|
-
metadata: {
|
|
75
|
-
...this.metadataInfo,
|
|
76
|
-
description: this.getDescription()
|
|
77
|
-
},
|
|
78
|
-
statistic: {
|
|
79
|
-
assetEarning: [{
|
|
80
|
-
slug: this.rewardAssets[0],
|
|
81
|
-
apy: apy * 100,
|
|
82
|
-
exchangeRate: latestExchangeRate / decimals
|
|
83
|
-
}],
|
|
84
|
-
unstakingPeriod: 24 * 28,
|
|
85
|
-
maxCandidatePerFarmer: 1,
|
|
86
|
-
maxWithdrawalRequestPerFarmer: 1,
|
|
87
|
-
earningThreshold: {
|
|
88
|
-
join: mintThreshold,
|
|
89
|
-
defaultUnstake: redeemThreshold,
|
|
90
|
-
fastUnstake: '0'
|
|
91
|
-
},
|
|
92
|
-
totalApy: apy * 100,
|
|
93
|
-
tvl: totalStakingBonded.add(toBondPool).toString()
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/* Subscribe pool info */
|
|
99
|
-
|
|
100
|
-
/* Subscribe pool position */
|
|
101
|
-
|
|
102
|
-
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
103
|
-
let cancel = false;
|
|
104
|
-
const substrateApi = this.substrateApi;
|
|
105
|
-
await substrateApi.isReady;
|
|
106
|
-
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
107
|
-
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
108
|
-
const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, _getTokenOnChainInfo(derivativeTokenInfo)]), async _balances => {
|
|
109
|
-
if (cancel) {
|
|
110
|
-
unsub();
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const balances = _balances;
|
|
114
|
-
const redeemRequests = await substrateApi.api.query.homa.redeemRequests.multi(useAddresses);
|
|
115
|
-
const exchangeRate = await this.getExchangeRate();
|
|
116
|
-
const decimals = BN_TEN.pow(new BN(this.rateDecimals));
|
|
117
|
-
for (let i = 0; i < balances.length; i++) {
|
|
118
|
-
const balanceItem = balances[i];
|
|
119
|
-
const address = useAddresses[i];
|
|
120
|
-
const activeTotalBalance = balanceItem.free || BN_ZERO;
|
|
121
|
-
let totalBalance = activeTotalBalance.mul(new BN(exchangeRate)).div(decimals);
|
|
122
|
-
let unlockingBalance = BN_ZERO;
|
|
123
|
-
const unstakings = [];
|
|
124
|
-
const redeemRequest = redeemRequests[i].toPrimitive();
|
|
125
|
-
if (redeemRequest) {
|
|
126
|
-
const [redeemAmount, withdrawable] = redeemRequest;
|
|
127
|
-
const amount = new BN(redeemAmount);
|
|
128
|
-
totalBalance = totalBalance.add(amount);
|
|
129
|
-
unlockingBalance = unlockingBalance.add(amount);
|
|
130
|
-
unstakings.push({
|
|
131
|
-
chain: this.chain,
|
|
132
|
-
status: withdrawable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
133
|
-
claimable: redeemAmount.toString()
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
const result = {
|
|
137
|
-
...this.baseInfo,
|
|
138
|
-
type: this.type,
|
|
139
|
-
address,
|
|
140
|
-
balanceToken: this.inputAsset,
|
|
141
|
-
totalStake: totalBalance.toString(),
|
|
142
|
-
activeStake: activeTotalBalance.toString(),
|
|
143
|
-
unstakeBalance: unlockingBalance.toString(),
|
|
144
|
-
status: activeTotalBalance.gt(BN_ZERO) ? EarningStatus.EARNING_REWARD : EarningStatus.NOT_EARNING,
|
|
145
|
-
derivativeToken: derivativeTokenSlug,
|
|
146
|
-
isBondedBefore: totalBalance.gt(BN_ZERO),
|
|
147
|
-
nominations: [],
|
|
148
|
-
unstakings: unstakings
|
|
149
|
-
};
|
|
150
|
-
resultCallback(result);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
return () => {
|
|
154
|
-
cancel = true;
|
|
155
|
-
unsub();
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/* Subscribe pool position */
|
|
160
|
-
|
|
161
|
-
/* Join pool action */
|
|
162
|
-
|
|
163
|
-
get submitJoinStepInfo() {
|
|
164
|
-
return {
|
|
165
|
-
name: 'Mint LDOT',
|
|
166
|
-
type: YieldStepType.MINT_LDOT
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
async getSubmitStepFee(params) {
|
|
170
|
-
const poolOriginSubstrateApi = await this.substrateApi.isReady;
|
|
171
|
-
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
172
|
-
if (new BN(params.amount).gt(BN_ZERO)) {
|
|
173
|
-
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.homa.mint(params.amount).paymentInfo(fakeAddress);
|
|
174
|
-
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
175
|
-
return {
|
|
176
|
-
amount: mintFeeInfo.partialFee.toString(),
|
|
177
|
-
slug: defaultFeeTokenSlug
|
|
178
|
-
};
|
|
179
|
-
} else {
|
|
180
|
-
return {
|
|
181
|
-
amount: '0',
|
|
182
|
-
slug: defaultFeeTokenSlug
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
async handleSubmitStep(data, path) {
|
|
187
|
-
const substrateApi = await this.substrateApi.isReady;
|
|
188
|
-
const extrinsic = substrateApi.api.tx.homa.mint(data.amount);
|
|
189
|
-
return {
|
|
190
|
-
txChain: this.chain,
|
|
191
|
-
extrinsicType: ExtrinsicType.MINT_LDOT,
|
|
192
|
-
extrinsic,
|
|
193
|
-
txData: data,
|
|
194
|
-
transferNativeAmount: '0',
|
|
195
|
-
chainType: ChainType.SUBSTRATE
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/* Join pool action */
|
|
200
|
-
|
|
201
|
-
/* Leave pool action */
|
|
202
|
-
|
|
203
|
-
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
204
|
-
const substrateApi = await this.substrateApi.isReady;
|
|
205
|
-
const weightedMinAmount = await this.createParamToRedeem(amount, address);
|
|
206
|
-
const extrinsic = substrateApi.api.tx.aggregatedDex.swapWithExactSupply(
|
|
207
|
-
// Swap path
|
|
208
|
-
[{
|
|
209
|
-
Taiga: [0, /* pool id */
|
|
210
|
-
1, /* supply asset */
|
|
211
|
-
0 /* target asset */]
|
|
212
|
-
}],
|
|
213
|
-
// Supply amount
|
|
214
|
-
amount,
|
|
215
|
-
// Min target amount
|
|
216
|
-
weightedMinAmount // should always set a min target to prevent unexpected result
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
return [ExtrinsicType.REDEEM_LDOT, extrinsic];
|
|
220
|
-
}
|
|
221
|
-
async handleYieldUnstake(amount, address, selectedTarget) {
|
|
222
|
-
const chainApi = await this.substrateApi.isReady;
|
|
223
|
-
const extrinsic = chainApi.api.tx.homa.requestRedeem(amount, false);
|
|
224
|
-
return [ExtrinsicType.UNSTAKE_LDOT, extrinsic];
|
|
225
|
-
}
|
|
226
|
-
async handleYieldWithdraw(address, unstakingInfo) {
|
|
227
|
-
const chainApi = await this.substrateApi.isReady;
|
|
228
|
-
return chainApi.api.tx.homa.claimRedemption(address);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/* Leave pool action */
|
|
232
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
2
|
-
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
3
|
-
import BaseSpecialStakingPoolHandler from '../special';
|
|
4
|
-
export default abstract class BaseLiquidStakingPoolHandler extends BaseSpecialStakingPoolHandler {
|
|
5
|
-
readonly type = YieldPoolType.LIQUID_STAKING;
|
|
6
|
-
/** Rate convert token when redeem */
|
|
7
|
-
readonly minAmountPercent: number;
|
|
8
|
-
static get defaultMinAmountPercent(): number;
|
|
9
|
-
createParamToRedeem(amount: string, address: string): Promise<number>;
|
|
10
|
-
validateYieldLeave(amount: string, address: string, fastLeave: boolean, selectedTarget?: string): Promise<TransactionError[]>;
|
|
11
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
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, StakingTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
-
import { convertDerivativeToOriginToken } from '@subwallet/extension-base/koni/api/yield/helper/utils';
|
|
7
|
-
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
8
|
-
import { formatNumber } from '@subwallet/extension-base/utils';
|
|
9
|
-
import { t } from 'i18next';
|
|
10
|
-
import { BN, BN_ZERO } from '@polkadot/util';
|
|
11
|
-
import BaseSpecialStakingPoolHandler from "../special.js";
|
|
12
|
-
const DEFAULT_MIN_AMOUNT_PERCENT = 0.98;
|
|
13
|
-
export default class BaseLiquidStakingPoolHandler extends BaseSpecialStakingPoolHandler {
|
|
14
|
-
type = YieldPoolType.LIQUID_STAKING;
|
|
15
|
-
/** Rate convert token when redeem */
|
|
16
|
-
minAmountPercent = DEFAULT_MIN_AMOUNT_PERCENT;
|
|
17
|
-
static get defaultMinAmountPercent() {
|
|
18
|
-
return DEFAULT_MIN_AMOUNT_PERCENT;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/* Leave pool action */
|
|
22
|
-
|
|
23
|
-
async createParamToRedeem(amount, address) {
|
|
24
|
-
const yieldPositionInfo = await this.getPoolPosition(address);
|
|
25
|
-
const poolInfo = await this.getPoolInfo();
|
|
26
|
-
const originTokenSlug = this.inputAsset;
|
|
27
|
-
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
28
|
-
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
29
|
-
const originTokenInfo = this.state.getAssetBySlug(originTokenSlug);
|
|
30
|
-
if (!yieldPositionInfo || !poolInfo) {
|
|
31
|
-
return Promise.reject(new TransactionError(BasicTxErrorType.INVALID_PARAMS));
|
|
32
|
-
}
|
|
33
|
-
const formattedMinAmount = convertDerivativeToOriginToken(amount, poolInfo, derivativeTokenInfo, originTokenInfo);
|
|
34
|
-
return Math.floor(this.minAmountPercent * formattedMinAmount);
|
|
35
|
-
}
|
|
36
|
-
async validateYieldLeave(amount, address, fastLeave, selectedTarget) {
|
|
37
|
-
const poolInfo = await this.getPoolInfo();
|
|
38
|
-
const poolPosition = await this.getPoolPosition(address);
|
|
39
|
-
if (!poolInfo || !poolInfo.statistic || !poolPosition) {
|
|
40
|
-
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
41
|
-
}
|
|
42
|
-
if (!this.availableMethod.defaultUnstake && !fastLeave) {
|
|
43
|
-
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
44
|
-
}
|
|
45
|
-
if (!this.availableMethod.fastUnstake && fastLeave) {
|
|
46
|
-
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
47
|
-
}
|
|
48
|
-
const errors = [];
|
|
49
|
-
const bnActiveStake = new BN(poolPosition.activeStake);
|
|
50
|
-
const bnAmount = new BN(amount);
|
|
51
|
-
const bnRemainingStake = bnActiveStake.sub(bnAmount);
|
|
52
|
-
const minStake = new BN(poolInfo.statistic.earningThreshold.join || '0');
|
|
53
|
-
const minUnstake = new BN((fastLeave ? poolInfo.statistic.earningThreshold.fastUnstake : poolInfo.statistic.earningThreshold.defaultUnstake) || '0');
|
|
54
|
-
const maxUnstakeRequest = poolInfo.statistic.maxWithdrawalRequestPerFarmer;
|
|
55
|
-
const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
|
|
56
|
-
if (bnAmount.lte(BN_ZERO)) {
|
|
57
|
-
return [new TransactionError(BasicTxErrorType.INVALID_PARAMS, t('Amount must be greater than 0'))];
|
|
58
|
-
}
|
|
59
|
-
if (bnAmount.lt(minUnstake)) {
|
|
60
|
-
const minUnstakeStr = formatNumber(minUnstake.toString(), derivativeTokenInfo.decimals || 0);
|
|
61
|
-
errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_UNSTAKE, t('You need to unstake at least {{amount}} {{token}}', {
|
|
62
|
-
replace: {
|
|
63
|
-
amount: minUnstakeStr,
|
|
64
|
-
token: derivativeTokenInfo.symbol
|
|
65
|
-
}
|
|
66
|
-
})));
|
|
67
|
-
}
|
|
68
|
-
if (!fastLeave) {
|
|
69
|
-
if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
|
|
70
|
-
errors.push(new TransactionError(StakingTxErrorType.INVALID_ACTIVE_STAKE)); // TODO
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (poolPosition.unstakings.length > maxUnstakeRequest) {
|
|
74
|
-
errors.push(new TransactionError(StakingTxErrorType.EXCEED_MAX_UNSTAKING, t('You cannot unstake more than {{number}} times', {
|
|
75
|
-
replace: {
|
|
76
|
-
number: maxUnstakeRequest
|
|
77
|
-
}
|
|
78
|
-
})));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (bnRemainingStake.lt(BN_ZERO)) {
|
|
82
|
-
errors.push(new TransactionError(StakingTxErrorType.INVALID_ACTIVE_STAKE)); // TODO
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return Promise.resolve(errors);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/* Leave pool action */
|
|
89
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
-
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
3
|
-
import { BaseYieldStepDetail, HandleYieldStepData, LiquidYieldPoolInfo, OptimalYieldPath, OptimalYieldPathParams, SubmitYieldJoinData, TransactionData, YieldPoolMethodInfo, YieldPositionInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
|
|
4
|
-
import BaseLiquidStakingPoolHandler from './base';
|
|
5
|
-
export interface BifrostLiquidStakingMeta {
|
|
6
|
-
apy: string;
|
|
7
|
-
apyBase: string;
|
|
8
|
-
apyReward: string;
|
|
9
|
-
tvl: number;
|
|
10
|
-
tvm: number;
|
|
11
|
-
holders: number;
|
|
12
|
-
}
|
|
13
|
-
export interface BifrostVtokenExchangeRateResp {
|
|
14
|
-
data: {
|
|
15
|
-
slp_polkadot_ratio: BifrostVtokenExchangeRate[];
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export interface BifrostVtokenExchangeRate {
|
|
19
|
-
ratio: string;
|
|
20
|
-
key: string;
|
|
21
|
-
timestamp: string;
|
|
22
|
-
total_issuance: number;
|
|
23
|
-
token_pool: number;
|
|
24
|
-
}
|
|
25
|
-
export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPoolHandler {
|
|
26
|
-
slug: string;
|
|
27
|
-
protected readonly name: string;
|
|
28
|
-
protected readonly shortName: string;
|
|
29
|
-
protected readonly altInputAsset: string;
|
|
30
|
-
protected readonly derivativeAssets: string[];
|
|
31
|
-
protected readonly inputAsset: string;
|
|
32
|
-
protected readonly rewardAssets: string[];
|
|
33
|
-
protected readonly feeAssets: string[];
|
|
34
|
-
readonly minAmountPercent = 0.99;
|
|
35
|
-
protected readonly availableMethod: YieldPoolMethodInfo;
|
|
36
|
-
protected readonly rateDecimals = 0;
|
|
37
|
-
constructor(state: KoniState, chain: string);
|
|
38
|
-
protected getDescription(): string;
|
|
39
|
-
getPoolStat(): Promise<LiquidYieldPoolInfo>;
|
|
40
|
-
subscribePoolPosition(useAddresses: string[], resultCallback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
41
|
-
get submitJoinStepInfo(): BaseYieldStepDetail;
|
|
42
|
-
getSubmitStepFee(params: OptimalYieldPathParams): Promise<YieldTokenBaseInfo>;
|
|
43
|
-
handleSubmitStep(data: SubmitYieldJoinData, path: OptimalYieldPath): Promise<HandleYieldStepData>;
|
|
44
|
-
handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
45
|
-
handleYieldUnstake(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
46
|
-
}
|