@subwallet/extension-base 1.1.28-0 → 1.1.28-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 +92 -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 +9 -3
- 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 +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 +2 -0
- package/cjs/koni/background/handlers/Extension.js +323 -69
- package/cjs/koni/background/handlers/State.js +57 -4
- package/cjs/koni/background/handlers/index.js +4 -2
- package/cjs/koni/background/subscription.js +89 -19
- package/cjs/packageInfo.js +1 -1
- 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 +202 -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 +168 -0
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +196 -0
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +39 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +257 -0
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +180 -0
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +373 -0
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +359 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +426 -0
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +137 -0
- package/cjs/services/earning-service/handlers/native-staking/base.js +109 -0
- package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +361 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +512 -0
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +501 -0
- package/cjs/services/earning-service/handlers/special.js +387 -0
- package/cjs/services/earning-service/service.js +327 -0
- package/cjs/services/earning-service/utils/index.js +111 -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/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/index.js +4 -0
- 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 +47 -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/storage-service/index.js +241 -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 +180 -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 +37 -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 +34 -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/fetchStaticData.js +2 -1
- package/cjs/utils/index.js +89 -1
- package/cjs/utils/keyring.js +57 -0
- package/cjs/utils/object.js +12 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +2 -0
- 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.js +2 -0
- package/koni/background/handlers/Extension.d.ts +14 -1
- package/koni/background/handlers/Extension.js +282 -30
- package/koni/background/handlers/State.d.ts +18 -2
- package/koni/background/handlers/State.js +56 -4
- package/koni/background/handlers/index.js +4 -2
- package/koni/background/subscription.d.ts +5 -1
- package/koni/background/subscription.js +91 -21
- package/package.json +311 -8
- package/packageInfo.js +1 -1
- 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 +105 -0
- package/services/earning-service/handlers/base.js +195 -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 +22 -0
- package/services/earning-service/handlers/lending/interlay.js +160 -0
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +188 -0
- package/services/earning-service/handlers/liquid-staking/base.d.ts +8 -0
- package/services/earning-service/handlers/liquid-staking/base.js +31 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +44 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.js +246 -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 +27 -0
- package/services/earning-service/handlers/liquid-staking/parallel.js +172 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +36 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +363 -0
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +350 -0
- package/services/earning-service/handlers/native-staking/astar.d.ts +18 -0
- package/services/earning-service/handlers/native-staking/astar.js +416 -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 +19 -0
- package/services/earning-service/handlers/native-staking/base.js +101 -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 +353 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +503 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +33 -0
- package/services/earning-service/handlers/nomination-pool/index.js +492 -0
- package/services/earning-service/handlers/special.d.ts +56 -0
- package/services/earning-service/handlers/special.js +379 -0
- package/services/earning-service/service.d.ts +36 -0
- package/services/earning-service/service.js +320 -0
- package/services/earning-service/utils/index.d.ts +14 -0
- package/services/earning-service/utils/index.js +100 -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/index.js +4 -0
- 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 +17 -1
- package/services/storage-service/DatabaseService.js +47 -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 +2 -2
- 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 +178 -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 +75 -0
- package/types/yield/actions/join/step.js +34 -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 +60 -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 +112 -0
- package/types/yield/info/account/info.js +1 -0
- package/types/yield/info/account/reward.d.ts +41 -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 +28 -0
- package/types/yield/info/base.js +28 -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 +190 -0
- package/types/yield/info/chain/info.js +1 -0
- package/types/yield/info/chain/target.d.ts +33 -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,188 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { 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, YieldStepType } from '@subwallet/extension-base/types';
|
|
8
|
+
import fetch from 'cross-fetch';
|
|
9
|
+
import { BN, 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
|
+
/** @inner */
|
|
20
|
+
minAmountPercent = 0.98;
|
|
21
|
+
/** @inner */
|
|
22
|
+
allowDefaultUnstake = true;
|
|
23
|
+
constructor(state, chain) {
|
|
24
|
+
super(state, chain);
|
|
25
|
+
const chainInfo = this.chainInfo;
|
|
26
|
+
this.slug = `DOT___liquid_staking___${chain}`;
|
|
27
|
+
this.name = `${chainInfo.name} Liquid Staking`;
|
|
28
|
+
this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
|
|
29
|
+
this.description = 'Stake DOT to earn yield on LDOT';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Subscribe pool info */
|
|
33
|
+
|
|
34
|
+
async getPoolStat() {
|
|
35
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
36
|
+
const stakingMetaPromise = new Promise(function (resolve) {
|
|
37
|
+
fetch(GRAPHQL_API, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: {
|
|
40
|
+
'Content-Type': 'application/json'
|
|
41
|
+
},
|
|
42
|
+
body: JSON.stringify({
|
|
43
|
+
query: EXCHANGE_RATE_REQUEST
|
|
44
|
+
})
|
|
45
|
+
}).then(res => {
|
|
46
|
+
resolve(res.json());
|
|
47
|
+
}).catch(console.error);
|
|
48
|
+
});
|
|
49
|
+
const [_toBondPool, _totalStakingBonded, _stakingMeta] = await Promise.all([substrateApi.api.query.homa.toBondPool(), substrateApi.api.query.homa.totalStakingBonded(), stakingMetaPromise]);
|
|
50
|
+
const stakingMeta = _stakingMeta;
|
|
51
|
+
const stakingMetaList = stakingMeta.data.dailySummaries.nodes;
|
|
52
|
+
const latestExchangeRate = parseInt(stakingMetaList[0].exchangeRate);
|
|
53
|
+
const decimals = 10 ** 10;
|
|
54
|
+
const endingBalance = parseInt(stakingMetaList[0].exchangeRate);
|
|
55
|
+
const beginBalance = parseInt(stakingMetaList[29].exchangeRate);
|
|
56
|
+
const diff = endingBalance / beginBalance;
|
|
57
|
+
const apy = diff ** (365 / 30) - 1;
|
|
58
|
+
const toBondPool = new BN(_toBondPool.toString());
|
|
59
|
+
const totalStakingBonded = new BN(_totalStakingBonded.toString());
|
|
60
|
+
return {
|
|
61
|
+
...this.defaultInfo,
|
|
62
|
+
description: this.description,
|
|
63
|
+
type: this.type,
|
|
64
|
+
metadata: {
|
|
65
|
+
...this.baseMetadata,
|
|
66
|
+
isAvailable: true,
|
|
67
|
+
allowCancelUnstaking: false,
|
|
68
|
+
assetEarning: [{
|
|
69
|
+
slug: this.rewardAssets[0],
|
|
70
|
+
apy: apy * 100,
|
|
71
|
+
exchangeRate: latestExchangeRate / decimals
|
|
72
|
+
}],
|
|
73
|
+
maxCandidatePerFarmer: 1,
|
|
74
|
+
maxWithdrawalRequestPerFarmer: 1,
|
|
75
|
+
minJoinPool: '50000000000',
|
|
76
|
+
minWithdrawal: '50000000000',
|
|
77
|
+
totalApy: apy * 100,
|
|
78
|
+
tvl: totalStakingBonded.add(toBondPool).toString()
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* Subscribe pool info */
|
|
84
|
+
|
|
85
|
+
/* Subscribe pool position */
|
|
86
|
+
|
|
87
|
+
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
88
|
+
let cancel = false;
|
|
89
|
+
const substrateApi = this.substrateApi;
|
|
90
|
+
await substrateApi.isReady;
|
|
91
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
92
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
93
|
+
const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, _getTokenOnChainInfo(derivativeTokenInfo)]), _balances => {
|
|
94
|
+
if (cancel) {
|
|
95
|
+
unsub();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const balances = _balances;
|
|
99
|
+
for (let i = 0; i < balances.length; i++) {
|
|
100
|
+
const balanceItem = balances[i];
|
|
101
|
+
const address = useAddresses[i];
|
|
102
|
+
const bnTotalBalance = balanceItem.free || BN_ZERO;
|
|
103
|
+
const totalBalance = bnTotalBalance.toString();
|
|
104
|
+
const result = {
|
|
105
|
+
...this.defaultInfo,
|
|
106
|
+
type: this.type,
|
|
107
|
+
address,
|
|
108
|
+
balanceToken: this.inputAsset,
|
|
109
|
+
totalStake: totalBalance,
|
|
110
|
+
activeStake: totalBalance,
|
|
111
|
+
unstakeBalance: '0',
|
|
112
|
+
status: EarningStatus.EARNING_REWARD,
|
|
113
|
+
derivativeToken: derivativeTokenSlug,
|
|
114
|
+
isBondedBefore: bnTotalBalance.gt(BN_ZERO),
|
|
115
|
+
nominations: [],
|
|
116
|
+
unstakings: []
|
|
117
|
+
};
|
|
118
|
+
resultCallback(result);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return () => {
|
|
122
|
+
cancel = true;
|
|
123
|
+
unsub();
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* Subscribe pool position */
|
|
128
|
+
|
|
129
|
+
/* Join pool action */
|
|
130
|
+
|
|
131
|
+
get submitJoinStepInfo() {
|
|
132
|
+
return {
|
|
133
|
+
name: 'Mint LDOT',
|
|
134
|
+
type: YieldStepType.MINT_LDOT
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
async getSubmitStepFee(params) {
|
|
138
|
+
const poolOriginSubstrateApi = await this.substrateApi.isReady;
|
|
139
|
+
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
140
|
+
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.homa.mint(params.amount).paymentInfo(fakeAddress);
|
|
141
|
+
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
142
|
+
return {
|
|
143
|
+
amount: mintFeeInfo.partialFee.toString(),
|
|
144
|
+
slug: defaultFeeTokenSlug
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
async handleSubmitStep(data, path) {
|
|
148
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
149
|
+
const extrinsic = substrateApi.api.tx.homa.mint(data.amount);
|
|
150
|
+
return {
|
|
151
|
+
txChain: this.chain,
|
|
152
|
+
extrinsicType: ExtrinsicType.MINT_LDOT,
|
|
153
|
+
extrinsic,
|
|
154
|
+
txData: data,
|
|
155
|
+
transferNativeAmount: '0'
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* Join pool action */
|
|
160
|
+
|
|
161
|
+
/* Leave pool action */
|
|
162
|
+
|
|
163
|
+
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
164
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
165
|
+
const weightedMinAmount = await this.createParamToRedeem(amount, address);
|
|
166
|
+
const extrinsic = substrateApi.api.tx.aggregatedDex.swapWithExactSupply(
|
|
167
|
+
// Swap path
|
|
168
|
+
[{
|
|
169
|
+
Taiga: [0, /* pool id */
|
|
170
|
+
1, /* supply asset */
|
|
171
|
+
0 /* target asset */]
|
|
172
|
+
}],
|
|
173
|
+
// Supply amount
|
|
174
|
+
amount,
|
|
175
|
+
// Min target amount
|
|
176
|
+
weightedMinAmount // should always set a min target to prevent unexpected result
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
return [ExtrinsicType.REDEEM_QDOT, extrinsic];
|
|
180
|
+
}
|
|
181
|
+
async handleYieldUnstake(amount, address, selectedTarget) {
|
|
182
|
+
const chainApi = await this.substrateApi.isReady;
|
|
183
|
+
const extrinsic = chainApi.api.tx.homa.requestRedeem(amount, false);
|
|
184
|
+
return [ExtrinsicType.UNSTAKE_QDOT, extrinsic];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* Leave pool action */
|
|
188
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
2
|
+
import BaseSpecialStakingPoolHandler from '../special';
|
|
3
|
+
export default abstract class BaseLiquidStakingPoolHandler extends BaseSpecialStakingPoolHandler {
|
|
4
|
+
readonly type = YieldPoolType.LIQUID_STAKING;
|
|
5
|
+
/** Rate convert token when redeem */
|
|
6
|
+
protected readonly minAmountPercent: number;
|
|
7
|
+
createParamToRedeem(amount: string, address: string): Promise<number>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
|
+
import { BasicTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
+
import { convertDerivativeToOriginToken } from '@subwallet/extension-base/koni/api/yield/helper/utils';
|
|
7
|
+
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
8
|
+
import BaseSpecialStakingPoolHandler from "../special.js";
|
|
9
|
+
export default class BaseLiquidStakingPoolHandler extends BaseSpecialStakingPoolHandler {
|
|
10
|
+
type = YieldPoolType.LIQUID_STAKING;
|
|
11
|
+
/** Rate convert token when redeem */
|
|
12
|
+
minAmountPercent = 0.98;
|
|
13
|
+
|
|
14
|
+
/* Leave pool action */
|
|
15
|
+
|
|
16
|
+
async createParamToRedeem(amount, address) {
|
|
17
|
+
const yieldPositionInfo = await this.getPoolPosition(address);
|
|
18
|
+
const poolInfo = await this.getPoolInfo();
|
|
19
|
+
const originTokenSlug = this.inputAsset;
|
|
20
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
21
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
22
|
+
const originTokenInfo = this.state.getAssetBySlug(originTokenSlug);
|
|
23
|
+
if (!yieldPositionInfo || !poolInfo) {
|
|
24
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.INVALID_PARAMS));
|
|
25
|
+
}
|
|
26
|
+
const formattedMinAmount = convertDerivativeToOriginToken(amount, poolInfo, derivativeTokenInfo, originTokenInfo);
|
|
27
|
+
return Math.floor(this.minAmountPercent * formattedMinAmount);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* Leave pool action */
|
|
31
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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, 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
|
+
protected readonly description: 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
|
+
/** @inner */
|
|
35
|
+
protected readonly minAmountPercent = 0.99;
|
|
36
|
+
slug: string;
|
|
37
|
+
constructor(state: KoniState, chain: string);
|
|
38
|
+
getPoolStat(): Promise<LiquidYieldPoolInfo>;
|
|
39
|
+
subscribePoolPosition(useAddresses: string[], resultCallback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
40
|
+
get submitJoinStepInfo(): BaseYieldStepDetail;
|
|
41
|
+
getSubmitStepFee(params: OptimalYieldPathParams): Promise<YieldTokenBaseInfo>;
|
|
42
|
+
handleSubmitStep(data: SubmitYieldJoinData, path: OptimalYieldPath): Promise<HandleYieldStepData>;
|
|
43
|
+
handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
|
+
import { _getAssetDecimals, _getTokenOnChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
+
import { fakeAddress } from '@subwallet/extension-base/services/earning-service/constants';
|
|
8
|
+
import { EarningStatus, UnstakingStatus, YieldStepType } from '@subwallet/extension-base/types';
|
|
9
|
+
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
10
|
+
import fetch from 'cross-fetch';
|
|
11
|
+
import { BN, BN_ZERO } from '@polkadot/util';
|
|
12
|
+
import BaseLiquidStakingPoolHandler from "./base.js";
|
|
13
|
+
const STATS_URL = 'https://api.bifrost.app/api/site';
|
|
14
|
+
const BIFROST_GRAPHQL_ENDPOINT = 'https://bifrost-subsql.liebi.com/v1/graphql';
|
|
15
|
+
const BIFROST_EXCHANGE_RATE_REQUEST = 'query MyQuery{slp_polkadot_ratio(limit:1 where:{key:{_eq:"0"}} order_by:{timestamp:desc_nulls_first}){ratio key timestamp total_issuance token_pool}}';
|
|
16
|
+
export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPoolHandler {
|
|
17
|
+
altInputAsset = 'polkadot-NATIVE-DOT';
|
|
18
|
+
derivativeAssets = ['bifrost_dot-LOCAL-vDOT'];
|
|
19
|
+
inputAsset = 'bifrost_dot-LOCAL-DOT';
|
|
20
|
+
rewardAssets = ['bifrost_dot-LOCAL-DOT'];
|
|
21
|
+
feeAssets = ['bifrost_dot-NATIVE-BNC', 'bifrost_dot-LOCAL-DOT'];
|
|
22
|
+
/** @inner */
|
|
23
|
+
minAmountPercent = 0.99;
|
|
24
|
+
constructor(state, chain) {
|
|
25
|
+
super(state, chain);
|
|
26
|
+
const chainInfo = this.chainInfo;
|
|
27
|
+
this.slug = `DOT___liquid_staking___${chain}`;
|
|
28
|
+
this.name = `${chainInfo.name} Liquid Staking`;
|
|
29
|
+
this.description = 'Stake DOT to earn yield on vDOT';
|
|
30
|
+
this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* Subscribe pool info */
|
|
34
|
+
|
|
35
|
+
async getPoolStat() {
|
|
36
|
+
const stakingMetaPromise = new Promise(function (resolve) {
|
|
37
|
+
fetch(STATS_URL, {
|
|
38
|
+
method: 'GET'
|
|
39
|
+
}).then(res => {
|
|
40
|
+
resolve(res.json());
|
|
41
|
+
}).catch(console.error);
|
|
42
|
+
});
|
|
43
|
+
const exchangeRatePromise = new Promise(function (resolve) {
|
|
44
|
+
fetch(BIFROST_GRAPHQL_ENDPOINT, {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: {
|
|
47
|
+
'Content-Type': 'application/json'
|
|
48
|
+
},
|
|
49
|
+
body: JSON.stringify({
|
|
50
|
+
query: BIFROST_EXCHANGE_RATE_REQUEST
|
|
51
|
+
})
|
|
52
|
+
}).then(resp => {
|
|
53
|
+
resolve(resp.json());
|
|
54
|
+
}).catch(console.error);
|
|
55
|
+
});
|
|
56
|
+
const [_stakingMeta, _exchangeRate] = await Promise.all([stakingMetaPromise, exchangeRatePromise]);
|
|
57
|
+
const stakingMeta = _stakingMeta;
|
|
58
|
+
const exchangeRate = _exchangeRate;
|
|
59
|
+
const vDOTStats = stakingMeta.vDOT;
|
|
60
|
+
const assetInfo = this.state.getAssetBySlug(this.inputAsset);
|
|
61
|
+
const assetDecimals = 10 ** _getAssetDecimals(assetInfo);
|
|
62
|
+
return {
|
|
63
|
+
...this.defaultInfo,
|
|
64
|
+
description: this.description,
|
|
65
|
+
type: this.type,
|
|
66
|
+
metadata: {
|
|
67
|
+
...this.baseMetadata,
|
|
68
|
+
isAvailable: true,
|
|
69
|
+
allowCancelUnstaking: false,
|
|
70
|
+
assetEarning: [{
|
|
71
|
+
slug: this.rewardAssets[0],
|
|
72
|
+
apy: parseFloat(vDOTStats.apyBase),
|
|
73
|
+
exchangeRate: parseFloat(exchangeRate.data.slp_polkadot_ratio[0].ratio)
|
|
74
|
+
}],
|
|
75
|
+
maxCandidatePerFarmer: 1,
|
|
76
|
+
maxWithdrawalRequestPerFarmer: 1,
|
|
77
|
+
minJoinPool: '5000000000',
|
|
78
|
+
minWithdrawal: '4000000000',
|
|
79
|
+
totalApy: parseFloat(vDOTStats.apyBase),
|
|
80
|
+
tvl: (vDOTStats.tvm * assetDecimals).toString()
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Subscribe pool info */
|
|
86
|
+
|
|
87
|
+
/* Subscribe pool position */
|
|
88
|
+
|
|
89
|
+
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
90
|
+
let cancel = false;
|
|
91
|
+
const substrateApi = this.substrateApi;
|
|
92
|
+
await substrateApi.isReady;
|
|
93
|
+
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
96
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
97
|
+
const inputTokenSlug = this.inputAsset;
|
|
98
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
99
|
+
const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, _getTokenOnChainInfo(derivativeTokenInfo)]), async _balance => {
|
|
100
|
+
if (cancel) {
|
|
101
|
+
unsub();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const balances = _balance;
|
|
105
|
+
const [_unlockLedgerList, _currentRelayEra] = await Promise.all([substrateApi.api.query.vtokenMinting.userUnlockLedger.multi(useAddresses.map(address => [address, _getTokenOnChainInfo(inputTokenInfo)])), substrateApi.api.query.vtokenMinting.ongoingTimeUnit(_getTokenOnChainInfo(inputTokenInfo))]);
|
|
106
|
+
const currentRelayEraObj = _currentRelayEra.toPrimitive();
|
|
107
|
+
const currentRelayEra = currentRelayEraObj.Era;
|
|
108
|
+
const unlockLedgerList = [];
|
|
109
|
+
const activeBalanceMap = {};
|
|
110
|
+
for (let i = 0; i < balances.length; i++) {
|
|
111
|
+
const balanceItem = balances[i];
|
|
112
|
+
const address = useAddresses[i];
|
|
113
|
+
const formattedAddress = reformatAddress(address);
|
|
114
|
+
activeBalanceMap[formattedAddress] = balanceItem.free || BN_ZERO;
|
|
115
|
+
const _unlockLedger = _unlockLedgerList[i];
|
|
116
|
+
const unlockLedger = _unlockLedger.toPrimitive();
|
|
117
|
+
if (unlockLedger) {
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
120
|
+
const unstakingLedgerIds = unlockLedger[1];
|
|
121
|
+
unstakingLedgerIds.forEach(ledgerId => {
|
|
122
|
+
unlockLedgerList.push({
|
|
123
|
+
address: formattedAddress,
|
|
124
|
+
ledgerId
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// const bnTotalBalance = bnActiveBalance.add(bnUnstakingBalance);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const unlockingMap = {};
|
|
133
|
+
const _unlockInfoList = await substrateApi.api.query.vtokenMinting.tokenUnlockLedger.multi(unlockLedgerList.map(({
|
|
134
|
+
ledgerId
|
|
135
|
+
}) => [_getTokenOnChainInfo(inputTokenInfo), ledgerId]));
|
|
136
|
+
for (let i = 0; i < _unlockInfoList.length; i++) {
|
|
137
|
+
const unlockInfo = _unlockInfoList[i].toPrimitive();
|
|
138
|
+
const owner = reformatAddress(unlockInfo[0]);
|
|
139
|
+
const amount = unlockInfo[1].toString();
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
const withdrawalEra = unlockInfo[2].era;
|
|
142
|
+
if (owner in unlockingMap) {
|
|
143
|
+
unlockingMap[owner].push({
|
|
144
|
+
balance: amount,
|
|
145
|
+
era: withdrawalEra
|
|
146
|
+
});
|
|
147
|
+
} else {
|
|
148
|
+
unlockingMap[owner] = [{
|
|
149
|
+
balance: amount,
|
|
150
|
+
era: withdrawalEra
|
|
151
|
+
}];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const unstakingList = [];
|
|
155
|
+
useAddresses.forEach(address => {
|
|
156
|
+
const formattedAddress = reformatAddress(address);
|
|
157
|
+
const bnActiveBalance = activeBalanceMap[formattedAddress];
|
|
158
|
+
const unlockings = unlockingMap[formattedAddress];
|
|
159
|
+
let unlockBalance = BN_ZERO;
|
|
160
|
+
if (unlockings) {
|
|
161
|
+
unlockings.forEach(unlocking => {
|
|
162
|
+
const isClaimable = unlocking.era - currentRelayEra < 0;
|
|
163
|
+
const remainingEra = unlocking.era - currentRelayEra;
|
|
164
|
+
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[this.chain];
|
|
165
|
+
unlockBalance = unlockBalance.add(new BN(unlocking.balance));
|
|
166
|
+
unstakingList.push({
|
|
167
|
+
chain: this.chain,
|
|
168
|
+
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
169
|
+
claimable: unlocking.balance,
|
|
170
|
+
waitingTime: waitingTime
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const totalBalance = bnActiveBalance.add(unlockBalance);
|
|
175
|
+
const result = {
|
|
176
|
+
...this.defaultInfo,
|
|
177
|
+
type: this.type,
|
|
178
|
+
address,
|
|
179
|
+
balanceToken: this.inputAsset,
|
|
180
|
+
derivativeToken: derivativeTokenSlug,
|
|
181
|
+
totalStake: totalBalance.toString(),
|
|
182
|
+
activeStake: bnActiveBalance.toString(),
|
|
183
|
+
unstakeBalance: unlockBalance.toString(),
|
|
184
|
+
status: bnActiveBalance.eq(BN_ZERO) ? EarningStatus.NOT_EARNING : EarningStatus.EARNING_REWARD,
|
|
185
|
+
isBondedBefore: totalBalance.gt(BN_ZERO),
|
|
186
|
+
nominations: [],
|
|
187
|
+
unstakings: unstakingList
|
|
188
|
+
};
|
|
189
|
+
resultCallback(result);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
return () => {
|
|
193
|
+
cancel = true;
|
|
194
|
+
unsub();
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/* Subscribe pool position */
|
|
199
|
+
|
|
200
|
+
/* Join pool action */
|
|
201
|
+
|
|
202
|
+
get submitJoinStepInfo() {
|
|
203
|
+
return {
|
|
204
|
+
name: 'Mint vDOT',
|
|
205
|
+
type: YieldStepType.MINT_VDOT
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
async getSubmitStepFee(params) {
|
|
209
|
+
const poolOriginSubstrateApi = await this.substrateApi.isReady;
|
|
210
|
+
const inputTokenSlug = this.inputAsset;
|
|
211
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
212
|
+
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
213
|
+
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.vtokenMinting.mint(_getTokenOnChainInfo(inputTokenInfo), params.amount, null).paymentInfo(fakeAddress);
|
|
214
|
+
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
215
|
+
return {
|
|
216
|
+
amount: mintFeeInfo.partialFee.toString(),
|
|
217
|
+
slug: defaultFeeTokenSlug
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
async handleSubmitStep(data, path) {
|
|
221
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
222
|
+
const inputTokenSlug = this.inputAsset;
|
|
223
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
224
|
+
const extrinsic = substrateApi.api.tx.vtokenMinting.mint(_getTokenOnChainInfo(inputTokenInfo), data.amount, undefined);
|
|
225
|
+
return {
|
|
226
|
+
txChain: this.chain,
|
|
227
|
+
extrinsicType: ExtrinsicType.MINT_VDOT,
|
|
228
|
+
extrinsic,
|
|
229
|
+
txData: data,
|
|
230
|
+
transferNativeAmount: '0'
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* Join pool action */
|
|
235
|
+
|
|
236
|
+
/* Leave pool action */
|
|
237
|
+
|
|
238
|
+
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
239
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
240
|
+
const weightedMinAmount = await this.createParamToRedeem(amount, address);
|
|
241
|
+
const extrinsic = substrateApi.api.tx.stablePool.swap(0, 1, 0, amount, weightedMinAmount);
|
|
242
|
+
return [ExtrinsicType.REDEEM_VDOT, extrinsic];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/* Leave pool action */
|
|
246
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as AcalaLiquidStakingPoolHandler } from './acala';
|
|
2
|
+
export { default as BifrostLiquidStakingPoolHandler } from './bifrost';
|
|
3
|
+
export { default as ParallelLiquidStakingPoolHandler } from './parallel';
|
|
4
|
+
export { default as StellaSwapLiquidStakingPoolHandler } from './stella-swap';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export { default as AcalaLiquidStakingPoolHandler } from "./acala.js";
|
|
5
|
+
export { default as BifrostLiquidStakingPoolHandler } from "./bifrost.js";
|
|
6
|
+
export { default as ParallelLiquidStakingPoolHandler } from "./parallel.js";
|
|
7
|
+
export { default as StellaSwapLiquidStakingPoolHandler } from "./stella-swap.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
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, YieldPositionInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
|
|
4
|
+
import BaseLiquidStakingPoolHandler from './base';
|
|
5
|
+
export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingPoolHandler {
|
|
6
|
+
protected readonly description: string;
|
|
7
|
+
protected readonly name: string;
|
|
8
|
+
protected readonly shortName: string;
|
|
9
|
+
protected readonly altInputAsset: string;
|
|
10
|
+
protected readonly derivativeAssets: string[];
|
|
11
|
+
protected readonly inputAsset: string;
|
|
12
|
+
protected readonly rewardAssets: string[];
|
|
13
|
+
protected readonly feeAssets: string[];
|
|
14
|
+
/** @inner */
|
|
15
|
+
protected readonly minAmountPercent = 0.97;
|
|
16
|
+
/** @inner */
|
|
17
|
+
protected readonly allowDefaultUnstake = true;
|
|
18
|
+
slug: string;
|
|
19
|
+
constructor(state: KoniState, chain: string);
|
|
20
|
+
getPoolStat(): Promise<LiquidYieldPoolInfo>;
|
|
21
|
+
subscribePoolPosition(useAddresses: string[], resultCallback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
22
|
+
get submitJoinStepInfo(): BaseYieldStepDetail;
|
|
23
|
+
getSubmitStepFee(params: OptimalYieldPathParams): Promise<YieldTokenBaseInfo>;
|
|
24
|
+
handleSubmitStep(data: SubmitYieldJoinData, path: OptimalYieldPath): Promise<HandleYieldStepData>;
|
|
25
|
+
handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
26
|
+
handleYieldUnstake(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
27
|
+
}
|