@subwallet/extension-base 1.1.32-0 → 1.1.32-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +112 -69
- package/background/KoniTypes.js +19 -13
- package/background/errors/TransactionError.js +9 -0
- package/cjs/background/KoniTypes.js +20 -16
- package/cjs/background/errors/TransactionError.js +9 -0
- package/cjs/constants/index.js +19 -4
- package/cjs/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 +3 -21
- package/cjs/koni/background/handlers/Extension.js +368 -69
- package/cjs/koni/background/handlers/State.js +18 -12
- package/cjs/koni/background/handlers/index.js +4 -2
- package/cjs/koni/background/subscription.js +7 -104
- package/cjs/services/campaign-service/index.js +28 -6
- package/cjs/services/chain-service/constants.js +1 -15
- package/cjs/services/chain-service/index.js +3 -2
- 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 +262 -0
- package/cjs/services/earning-service/handlers/index.js +60 -0
- package/cjs/services/earning-service/handlers/lending/base.js +81 -0
- package/cjs/services/earning-service/handlers/lending/index.js +13 -0
- package/cjs/services/earning-service/handlers/lending/interlay.js +192 -0
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +240 -0
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +97 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +298 -0
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +227 -0
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +404 -0
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +389 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +466 -0
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +146 -0
- package/cjs/services/earning-service/handlers/native-staking/base.js +161 -0
- package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +390 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +567 -0
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +566 -0
- package/cjs/services/earning-service/handlers/special.js +493 -0
- package/cjs/services/earning-service/service.js +720 -0
- package/cjs/services/earning-service/utils/index.js +128 -0
- package/cjs/services/event-service/index.js +5 -0
- package/cjs/services/keyring-service/index.js +14 -2
- package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
- package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
- package/cjs/services/migration-service/scripts/MigrateEthProvider.js +17 -0
- package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +17 -0
- package/cjs/services/migration-service/scripts/MigrateProvider.js +29 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +21 -0
- package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +21 -0
- package/cjs/services/migration-service/scripts/index.js +6 -1
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
- package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
- package/cjs/services/mint-campaign-service/constants.js +11 -0
- package/cjs/services/mint-campaign-service/index.js +18 -0
- package/cjs/services/notification-service/NotificationService.js +1 -1
- package/cjs/services/storage-service/DatabaseService.js +66 -0
- package/cjs/services/storage-service/databases/index.js +4 -0
- package/cjs/services/storage-service/db-stores/Campaign.js +9 -3
- package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/cjs/services/storage-service/db-stores/YieldPoolStore.js +36 -0
- package/cjs/services/storage-service/db-stores/YieldPositionStore.js +71 -0
- package/cjs/services/storage-service/index.js +241 -0
- package/cjs/services/subscan-service/index.js +16 -0
- package/cjs/services/transaction-service/event-parser/index.js +58 -0
- package/cjs/services/transaction-service/helpers/index.js +3 -1
- package/cjs/services/transaction-service/index.js +245 -75
- package/cjs/services/transaction-service/utils.js +1 -0
- package/cjs/types/campaigns/index.js +16 -0
- package/cjs/types/campaigns/unlock-dot.js +1 -0
- package/cjs/types/index.js +44 -0
- package/cjs/types/ordinal.js +1 -0
- package/cjs/types/transaction.js +1 -0
- package/cjs/types/yield/actions/index.js +27 -0
- package/cjs/types/yield/actions/join/index.js +38 -0
- package/cjs/types/yield/actions/join/step.js +47 -0
- package/cjs/types/yield/actions/join/submit.js +1 -0
- package/cjs/types/yield/actions/join/validate.js +16 -0
- package/cjs/types/yield/actions/others.js +1 -0
- package/cjs/types/yield/index.js +27 -0
- package/cjs/types/yield/info/account/index.js +49 -0
- package/cjs/types/yield/info/account/info.js +1 -0
- package/cjs/types/yield/info/account/reward.js +1 -0
- package/cjs/types/yield/info/account/target.js +32 -0
- package/cjs/types/yield/info/account/unstake.js +27 -0
- package/cjs/types/yield/info/base.js +41 -0
- package/cjs/types/yield/info/chain/index.js +27 -0
- package/cjs/types/yield/info/chain/info.js +1 -0
- package/cjs/types/yield/info/chain/target.js +1 -0
- package/cjs/types/yield/info/index.js +49 -0
- package/cjs/types/yield/info/pallet.js +15 -0
- package/cjs/types.js +1 -0
- package/cjs/utils/address.js +34 -0
- package/cjs/utils/fetchStaticData.js +2 -1
- package/cjs/utils/index.js +89 -1
- package/cjs/utils/keyring.js +57 -0
- package/cjs/utils/number.js +6 -2
- package/cjs/utils/object.js +12 -0
- package/constants/index.d.ts +6 -1
- package/constants/index.js +6 -1
- package/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 +0 -4
- package/koni/background/cron.js +4 -22
- package/koni/background/handlers/Extension.d.ts +17 -1
- package/koni/background/handlers/Extension.js +327 -30
- package/koni/background/handlers/State.d.ts +6 -1
- package/koni/background/handlers/State.js +17 -12
- package/koni/background/handlers/index.js +4 -2
- package/koni/background/subscription.d.ts +1 -6
- package/koni/background/subscription.js +8 -104
- package/package.json +316 -3
- package/services/campaign-service/index.js +28 -6
- package/services/chain-service/constants.d.ts +0 -11
- package/services/chain-service/constants.js +0 -13
- package/services/chain-service/index.js +3 -2
- 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 +113 -0
- package/services/earning-service/handlers/base.js +256 -0
- package/services/earning-service/handlers/index.d.ts +5 -0
- package/services/earning-service/handlers/index.js +8 -0
- package/services/earning-service/handlers/lending/base.d.ts +8 -0
- package/services/earning-service/handlers/lending/base.js +73 -0
- package/services/earning-service/handlers/lending/index.d.ts +1 -0
- package/services/earning-service/handlers/lending/index.js +4 -0
- package/services/earning-service/handlers/lending/interlay.d.ts +24 -0
- package/services/earning-service/handlers/lending/interlay.js +184 -0
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +232 -0
- package/services/earning-service/handlers/liquid-staking/base.d.ts +11 -0
- package/services/earning-service/handlers/liquid-staking/base.js +89 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +46 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.js +287 -0
- package/services/earning-service/handlers/liquid-staking/index.d.ts +4 -0
- package/services/earning-service/handlers/liquid-staking/index.js +7 -0
- package/services/earning-service/handlers/liquid-staking/parallel.d.ts +26 -0
- package/services/earning-service/handlers/liquid-staking/parallel.js +219 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +34 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +394 -0
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +380 -0
- package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
- package/services/earning-service/handlers/native-staking/astar.js +456 -0
- package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
- package/services/earning-service/handlers/native-staking/base-para.js +138 -0
- package/services/earning-service/handlers/native-staking/base.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/base.js +152 -0
- package/services/earning-service/handlers/native-staking/index.d.ts +4 -0
- package/services/earning-service/handlers/native-staking/index.js +7 -0
- package/services/earning-service/handlers/native-staking/para-chain.d.ts +15 -0
- package/services/earning-service/handlers/native-staking/para-chain.js +382 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +558 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +36 -0
- package/services/earning-service/handlers/nomination-pool/index.js +556 -0
- package/services/earning-service/handlers/special.d.ts +64 -0
- package/services/earning-service/handlers/special.js +485 -0
- package/services/earning-service/service.d.ts +93 -0
- package/services/earning-service/service.js +709 -0
- package/services/earning-service/utils/index.d.ts +18 -0
- package/services/earning-service/utils/index.js +112 -0
- package/services/event-service/index.d.ts +2 -0
- package/services/event-service/index.js +5 -0
- package/services/event-service/types.d.ts +9 -0
- package/services/keyring-service/index.d.ts +2 -1
- package/services/keyring-service/index.js +14 -2
- package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
- package/services/migration-service/scripts/DeleteEarningData.js +13 -0
- package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
- package/services/migration-service/scripts/EnableEarningChains.js +13 -0
- package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningHistory.js +13 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.js +13 -0
- package/services/migration-service/scripts/index.js +6 -1
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
- package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
- package/services/mint-campaign-service/campaigns/index.js +4 -0
- package/services/mint-campaign-service/constants.d.ts +1 -0
- package/services/mint-campaign-service/constants.js +4 -0
- package/services/mint-campaign-service/index.d.ts +7 -0
- package/services/mint-campaign-service/index.js +11 -0
- package/services/notification-service/NotificationService.js +1 -1
- package/services/storage-service/DatabaseService.d.ts +23 -1
- package/services/storage-service/DatabaseService.js +66 -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/Campaign.js +9 -3
- package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/services/storage-service/db-stores/YieldPoolStore.d.ts +10 -0
- package/services/storage-service/db-stores/YieldPoolStore.js +28 -0
- package/services/storage-service/db-stores/YieldPositionStore.d.ts +11 -0
- package/services/storage-service/db-stores/YieldPositionStore.js +63 -0
- package/services/subscan-service/index.d.ts +3 -2
- package/services/subscan-service/index.js +15 -0
- package/services/subscan-service/types.d.ts +20 -0
- package/services/transaction-service/event-parser/index.d.ts +3 -1
- package/services/transaction-service/event-parser/index.js +57 -1
- package/services/transaction-service/helpers/index.js +3 -1
- package/services/transaction-service/index.d.ts +4 -15
- package/services/transaction-service/index.js +243 -73
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.js +1 -0
- package/types/campaigns/index.d.ts +1 -0
- package/types/campaigns/index.js +4 -0
- package/types/campaigns/unlock-dot.d.ts +71 -0
- package/types/campaigns/unlock-dot.js +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.js +5 -1
- package/types/ordinal.d.ts +69 -0
- package/types/ordinal.js +1 -0
- package/types/transaction.d.ts +3 -0
- package/types/transaction.js +1 -0
- package/types/yield/actions/index.d.ts +2 -0
- package/types/yield/actions/index.js +5 -0
- package/types/yield/actions/join/index.d.ts +3 -0
- package/types/yield/actions/join/index.js +6 -0
- package/types/yield/actions/join/step.d.ts +95 -0
- package/types/yield/actions/join/step.js +46 -0
- package/types/yield/actions/join/submit.d.ts +58 -0
- package/types/yield/actions/join/submit.js +1 -0
- package/types/yield/actions/join/validate.d.ts +18 -0
- package/types/yield/actions/join/validate.js +10 -0
- package/types/yield/actions/others.d.ts +85 -0
- package/types/yield/actions/others.js +1 -0
- package/types/yield/index.d.ts +2 -0
- package/types/yield/index.js +5 -0
- package/types/yield/info/account/index.d.ts +4 -0
- package/types/yield/info/account/index.js +7 -0
- package/types/yield/info/account/info.d.ts +92 -0
- package/types/yield/info/account/info.js +1 -0
- package/types/yield/info/account/reward.d.ts +47 -0
- package/types/yield/info/account/reward.js +1 -0
- package/types/yield/info/account/target.d.ts +43 -0
- package/types/yield/info/account/target.js +27 -0
- package/types/yield/info/account/unstake.d.ts +31 -0
- package/types/yield/info/account/unstake.js +22 -0
- package/types/yield/info/base.d.ts +45 -0
- package/types/yield/info/base.js +36 -0
- package/types/yield/info/chain/index.d.ts +2 -0
- package/types/yield/info/chain/index.js +5 -0
- package/types/yield/info/chain/info.d.ts +251 -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/number.d.ts +2 -1
- package/utils/number.js +2 -1
- package/utils/object.d.ts +1 -0
- package/utils/object.js +6 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
|
+
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
10
|
+
var _constants = require("@subwallet/extension-base/services/earning-service/constants");
|
|
11
|
+
var _types = require("@subwallet/extension-base/types");
|
|
12
|
+
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
13
|
+
var _util = require("@polkadot/util");
|
|
14
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
15
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
|
|
18
|
+
const GRAPHQL_API = 'https://api.polkawallet.io/acala-liquid-staking-subql';
|
|
19
|
+
const EXCHANGE_RATE_REQUEST = 'query { dailySummaries(first:30, orderBy:TIMESTAMP_DESC) {nodes { exchangeRate timestamp }}}';
|
|
20
|
+
class AcalaLiquidStakingPoolHandler extends _base.default {
|
|
21
|
+
altInputAsset = 'polkadot-NATIVE-DOT';
|
|
22
|
+
derivativeAssets = ['acala-LOCAL-LDOT'];
|
|
23
|
+
inputAsset = 'acala-LOCAL-DOT';
|
|
24
|
+
rewardAssets = ['acala-LOCAL-DOT'];
|
|
25
|
+
feeAssets = ['acala-NATIVE-ACA', 'acala-LOCAL-DOT'];
|
|
26
|
+
minAmountPercent = 0.98;
|
|
27
|
+
rateDecimals = 10;
|
|
28
|
+
availableMethod = {
|
|
29
|
+
join: true,
|
|
30
|
+
defaultUnstake: true,
|
|
31
|
+
fastUnstake: true,
|
|
32
|
+
cancelUnstake: false,
|
|
33
|
+
withdraw: true,
|
|
34
|
+
claimReward: false
|
|
35
|
+
};
|
|
36
|
+
constructor(state, chain) {
|
|
37
|
+
super(state, chain);
|
|
38
|
+
const chainInfo = this.chainInfo;
|
|
39
|
+
this.slug = `DOT___liquid_staking___${chain}`;
|
|
40
|
+
this.name = `${chainInfo.name} Liquid Staking`;
|
|
41
|
+
this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
|
|
42
|
+
}
|
|
43
|
+
getDescription() {
|
|
44
|
+
return 'Stake DOT to earn yield on LDOT';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* Subscribe pool info */
|
|
48
|
+
|
|
49
|
+
async getPoolStat() {
|
|
50
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
51
|
+
const stakingMetaPromise = new Promise(function (resolve) {
|
|
52
|
+
(0, _crossFetch.default)(GRAPHQL_API, {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: {
|
|
55
|
+
'Content-Type': 'application/json'
|
|
56
|
+
},
|
|
57
|
+
body: JSON.stringify({
|
|
58
|
+
query: EXCHANGE_RATE_REQUEST
|
|
59
|
+
})
|
|
60
|
+
}).then(res => {
|
|
61
|
+
resolve(res.json());
|
|
62
|
+
}).catch(console.error);
|
|
63
|
+
});
|
|
64
|
+
const [_toBondPool, _totalStakingBonded, _stakingMeta] = await Promise.all([substrateApi.api.query.homa.toBondPool(), substrateApi.api.query.homa.totalStakingBonded(), stakingMetaPromise]);
|
|
65
|
+
const mintThreshold = substrateApi.api.consts.homa.mintThreshold.toString();
|
|
66
|
+
const redeemThreshold = substrateApi.api.consts.homa.redeemThreshold.toString();
|
|
67
|
+
const stakingMeta = _stakingMeta;
|
|
68
|
+
const stakingMetaList = stakingMeta.data.dailySummaries.nodes;
|
|
69
|
+
const latestExchangeRate = parseInt(stakingMetaList[0].exchangeRate);
|
|
70
|
+
const decimals = 10 ** this.rateDecimals;
|
|
71
|
+
this.updateExchangeRate(latestExchangeRate);
|
|
72
|
+
const endingBalance = parseInt(stakingMetaList[0].exchangeRate);
|
|
73
|
+
const beginBalance = parseInt(stakingMetaList[29].exchangeRate);
|
|
74
|
+
const diff = endingBalance / beginBalance;
|
|
75
|
+
const apy = diff ** (365 / 30) - 1;
|
|
76
|
+
const toBondPool = new _util.BN(_toBondPool.toString());
|
|
77
|
+
const totalStakingBonded = new _util.BN(_totalStakingBonded.toString());
|
|
78
|
+
return {
|
|
79
|
+
...this.baseInfo,
|
|
80
|
+
type: this.type,
|
|
81
|
+
metadata: {
|
|
82
|
+
...this.metadataInfo,
|
|
83
|
+
description: this.getDescription()
|
|
84
|
+
},
|
|
85
|
+
statistic: {
|
|
86
|
+
assetEarning: [{
|
|
87
|
+
slug: this.rewardAssets[0],
|
|
88
|
+
apy: apy * 100,
|
|
89
|
+
exchangeRate: latestExchangeRate / decimals
|
|
90
|
+
}],
|
|
91
|
+
unstakingPeriod: 24 * 28,
|
|
92
|
+
maxCandidatePerFarmer: 1,
|
|
93
|
+
maxWithdrawalRequestPerFarmer: 1,
|
|
94
|
+
earningThreshold: {
|
|
95
|
+
join: mintThreshold,
|
|
96
|
+
defaultUnstake: redeemThreshold,
|
|
97
|
+
fastUnstake: '0'
|
|
98
|
+
},
|
|
99
|
+
totalApy: apy * 100,
|
|
100
|
+
tvl: totalStakingBonded.add(toBondPool).toString()
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* Subscribe pool info */
|
|
106
|
+
|
|
107
|
+
/* Subscribe pool position */
|
|
108
|
+
|
|
109
|
+
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
110
|
+
let cancel = false;
|
|
111
|
+
const substrateApi = this.substrateApi;
|
|
112
|
+
await substrateApi.isReady;
|
|
113
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
114
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
115
|
+
const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, (0, _utils._getTokenOnChainInfo)(derivativeTokenInfo)]), async _balances => {
|
|
116
|
+
if (cancel) {
|
|
117
|
+
unsub();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const balances = _balances;
|
|
121
|
+
const redeemRequests = await substrateApi.api.query.homa.redeemRequests.multi(useAddresses);
|
|
122
|
+
const exchangeRate = await this.getExchangeRate();
|
|
123
|
+
const decimals = _util.BN_TEN.pow(new _util.BN(this.rateDecimals));
|
|
124
|
+
for (let i = 0; i < balances.length; i++) {
|
|
125
|
+
const balanceItem = balances[i];
|
|
126
|
+
const address = useAddresses[i];
|
|
127
|
+
const activeTotalBalance = balanceItem.free || _util.BN_ZERO;
|
|
128
|
+
let totalBalance = activeTotalBalance.mul(new _util.BN(exchangeRate)).div(decimals);
|
|
129
|
+
let unlockingBalance = _util.BN_ZERO;
|
|
130
|
+
const unstakings = [];
|
|
131
|
+
const redeemRequest = redeemRequests[i].toPrimitive();
|
|
132
|
+
if (redeemRequest) {
|
|
133
|
+
const [redeemAmount, withdrawable] = redeemRequest;
|
|
134
|
+
const amount = new _util.BN(redeemAmount);
|
|
135
|
+
totalBalance = totalBalance.add(amount);
|
|
136
|
+
unlockingBalance = unlockingBalance.add(amount);
|
|
137
|
+
unstakings.push({
|
|
138
|
+
chain: this.chain,
|
|
139
|
+
status: withdrawable ? _types.UnstakingStatus.CLAIMABLE : _types.UnstakingStatus.UNLOCKING,
|
|
140
|
+
claimable: redeemAmount.toString()
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const result = {
|
|
144
|
+
...this.baseInfo,
|
|
145
|
+
type: this.type,
|
|
146
|
+
address,
|
|
147
|
+
balanceToken: this.inputAsset,
|
|
148
|
+
totalStake: totalBalance.toString(),
|
|
149
|
+
activeStake: activeTotalBalance.toString(),
|
|
150
|
+
unstakeBalance: unlockingBalance.toString(),
|
|
151
|
+
status: activeTotalBalance.gt(_util.BN_ZERO) ? _types.EarningStatus.EARNING_REWARD : _types.EarningStatus.NOT_EARNING,
|
|
152
|
+
derivativeToken: derivativeTokenSlug,
|
|
153
|
+
isBondedBefore: totalBalance.gt(_util.BN_ZERO),
|
|
154
|
+
nominations: [],
|
|
155
|
+
unstakings: unstakings
|
|
156
|
+
};
|
|
157
|
+
resultCallback(result);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return () => {
|
|
161
|
+
cancel = true;
|
|
162
|
+
unsub();
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* Subscribe pool position */
|
|
167
|
+
|
|
168
|
+
/* Join pool action */
|
|
169
|
+
|
|
170
|
+
get submitJoinStepInfo() {
|
|
171
|
+
return {
|
|
172
|
+
name: 'Mint LDOT',
|
|
173
|
+
type: _types.YieldStepType.MINT_LDOT
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
async getSubmitStepFee(params) {
|
|
177
|
+
const poolOriginSubstrateApi = await this.substrateApi.isReady;
|
|
178
|
+
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
179
|
+
if (new _util.BN(params.amount).gt(_util.BN_ZERO)) {
|
|
180
|
+
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.homa.mint(params.amount).paymentInfo(_constants.fakeAddress);
|
|
181
|
+
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
182
|
+
return {
|
|
183
|
+
amount: mintFeeInfo.partialFee.toString(),
|
|
184
|
+
slug: defaultFeeTokenSlug
|
|
185
|
+
};
|
|
186
|
+
} else {
|
|
187
|
+
return {
|
|
188
|
+
amount: '0',
|
|
189
|
+
slug: defaultFeeTokenSlug
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async handleSubmitStep(data, path) {
|
|
194
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
195
|
+
const extrinsic = substrateApi.api.tx.homa.mint(data.amount);
|
|
196
|
+
return {
|
|
197
|
+
txChain: this.chain,
|
|
198
|
+
extrinsicType: _KoniTypes.ExtrinsicType.MINT_LDOT,
|
|
199
|
+
extrinsic,
|
|
200
|
+
txData: data,
|
|
201
|
+
transferNativeAmount: '0',
|
|
202
|
+
chainType: _KoniTypes.ChainType.SUBSTRATE
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/* Join pool action */
|
|
207
|
+
|
|
208
|
+
/* Leave pool action */
|
|
209
|
+
|
|
210
|
+
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
211
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
212
|
+
const weightedMinAmount = await this.createParamToRedeem(amount, address);
|
|
213
|
+
const extrinsic = substrateApi.api.tx.aggregatedDex.swapWithExactSupply(
|
|
214
|
+
// Swap path
|
|
215
|
+
[{
|
|
216
|
+
Taiga: [0, /* pool id */
|
|
217
|
+
1, /* supply asset */
|
|
218
|
+
0 /* target asset */]
|
|
219
|
+
}],
|
|
220
|
+
// Supply amount
|
|
221
|
+
amount,
|
|
222
|
+
// Min target amount
|
|
223
|
+
weightedMinAmount // should always set a min target to prevent unexpected result
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
return [_KoniTypes.ExtrinsicType.REDEEM_LDOT, extrinsic];
|
|
227
|
+
}
|
|
228
|
+
async handleYieldUnstake(amount, address, selectedTarget) {
|
|
229
|
+
const chainApi = await this.substrateApi.isReady;
|
|
230
|
+
const extrinsic = chainApi.api.tx.homa.requestRedeem(amount, false);
|
|
231
|
+
return [_KoniTypes.ExtrinsicType.UNSTAKE_LDOT, extrinsic];
|
|
232
|
+
}
|
|
233
|
+
async handleYieldWithdraw(address, unstakingInfo) {
|
|
234
|
+
const chainApi = await this.substrateApi.isReady;
|
|
235
|
+
return chainApi.api.tx.homa.claimRedemption(address);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/* Leave pool action */
|
|
239
|
+
}
|
|
240
|
+
exports.default = AcalaLiquidStakingPoolHandler;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
9
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
|
+
var _utils = require("@subwallet/extension-base/koni/api/yield/helper/utils");
|
|
11
|
+
var _types = require("@subwallet/extension-base/types");
|
|
12
|
+
var _utils2 = require("@subwallet/extension-base/utils");
|
|
13
|
+
var _i18next = require("i18next");
|
|
14
|
+
var _util = require("@polkadot/util");
|
|
15
|
+
var _special = _interopRequireDefault(require("../special"));
|
|
16
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
17
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
|
|
19
|
+
const DEFAULT_MIN_AMOUNT_PERCENT = 0.98;
|
|
20
|
+
class BaseLiquidStakingPoolHandler extends _special.default {
|
|
21
|
+
type = _types.YieldPoolType.LIQUID_STAKING;
|
|
22
|
+
/** Rate convert token when redeem */
|
|
23
|
+
minAmountPercent = DEFAULT_MIN_AMOUNT_PERCENT;
|
|
24
|
+
static get defaultMinAmountPercent() {
|
|
25
|
+
return DEFAULT_MIN_AMOUNT_PERCENT;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Leave pool action */
|
|
29
|
+
|
|
30
|
+
async createParamToRedeem(amount, address) {
|
|
31
|
+
const yieldPositionInfo = await this.getPoolPosition(address);
|
|
32
|
+
const poolInfo = await this.getPoolInfo();
|
|
33
|
+
const originTokenSlug = this.inputAsset;
|
|
34
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
35
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
36
|
+
const originTokenInfo = this.state.getAssetBySlug(originTokenSlug);
|
|
37
|
+
if (!yieldPositionInfo || !poolInfo) {
|
|
38
|
+
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INVALID_PARAMS));
|
|
39
|
+
}
|
|
40
|
+
const formattedMinAmount = (0, _utils.convertDerivativeToOriginToken)(amount, poolInfo, derivativeTokenInfo, originTokenInfo);
|
|
41
|
+
return Math.floor(this.minAmountPercent * formattedMinAmount);
|
|
42
|
+
}
|
|
43
|
+
async validateYieldLeave(amount, address, fastLeave, selectedTarget) {
|
|
44
|
+
const poolInfo = await this.getPoolInfo();
|
|
45
|
+
const poolPosition = await this.getPoolPosition(address);
|
|
46
|
+
if (!poolInfo || !poolInfo.statistic || !poolPosition) {
|
|
47
|
+
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
|
|
48
|
+
}
|
|
49
|
+
if (!this.availableMethod.defaultUnstake && !fastLeave) {
|
|
50
|
+
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
|
|
51
|
+
}
|
|
52
|
+
if (!this.availableMethod.fastUnstake && fastLeave) {
|
|
53
|
+
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
|
|
54
|
+
}
|
|
55
|
+
const errors = [];
|
|
56
|
+
const bnActiveStake = new _util.BN(poolPosition.activeStake);
|
|
57
|
+
const bnAmount = new _util.BN(amount);
|
|
58
|
+
const bnRemainingStake = bnActiveStake.sub(bnAmount);
|
|
59
|
+
const minStake = new _util.BN(poolInfo.statistic.earningThreshold.join || '0');
|
|
60
|
+
const minUnstake = new _util.BN((fastLeave ? poolInfo.statistic.earningThreshold.fastUnstake : poolInfo.statistic.earningThreshold.defaultUnstake) || '0');
|
|
61
|
+
const maxUnstakeRequest = poolInfo.statistic.maxWithdrawalRequestPerFarmer;
|
|
62
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
|
|
63
|
+
if (bnAmount.lte(_util.BN_ZERO)) {
|
|
64
|
+
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INVALID_PARAMS, (0, _i18next.t)('Amount must be greater than 0'))];
|
|
65
|
+
}
|
|
66
|
+
if (bnAmount.lt(minUnstake)) {
|
|
67
|
+
const minUnstakeStr = (0, _utils2.formatNumber)(minUnstake.toString(), derivativeTokenInfo.decimals || 0);
|
|
68
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_UNSTAKE, (0, _i18next.t)('You need to unstake at least {{amount}} {{token}}', {
|
|
69
|
+
replace: {
|
|
70
|
+
amount: minUnstakeStr,
|
|
71
|
+
token: derivativeTokenInfo.symbol
|
|
72
|
+
}
|
|
73
|
+
})));
|
|
74
|
+
}
|
|
75
|
+
if (!fastLeave) {
|
|
76
|
+
if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
|
|
77
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE)); // TODO
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (poolPosition.unstakings.length > maxUnstakeRequest) {
|
|
81
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_UNSTAKING, (0, _i18next.t)('You cannot unstake more than {{number}} times', {
|
|
82
|
+
replace: {
|
|
83
|
+
number: maxUnstakeRequest
|
|
84
|
+
}
|
|
85
|
+
})));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (bnRemainingStake.lt(_util.BN_ZERO)) {
|
|
89
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE)); // TODO
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return Promise.resolve(errors);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Leave pool action */
|
|
96
|
+
}
|
|
97
|
+
exports.default = BaseLiquidStakingPoolHandler;
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
|
+
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
10
|
+
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
11
|
+
var _constants2 = require("@subwallet/extension-base/services/earning-service/constants");
|
|
12
|
+
var _types = require("@subwallet/extension-base/types");
|
|
13
|
+
var _utils2 = require("@subwallet/extension-base/utils");
|
|
14
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
15
|
+
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
16
|
+
var _util = require("@polkadot/util");
|
|
17
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
18
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
19
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
20
|
+
|
|
21
|
+
const STATS_URL = 'https://api.bifrost.app/api/site';
|
|
22
|
+
const BIFROST_GRAPHQL_ENDPOINT = 'https://bifrost-subsql.liebi.com/v1/graphql';
|
|
23
|
+
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}}';
|
|
24
|
+
class BifrostLiquidStakingPoolHandler extends _base.default {
|
|
25
|
+
altInputAsset = 'polkadot-NATIVE-DOT';
|
|
26
|
+
derivativeAssets = ['bifrost_dot-LOCAL-vDOT'];
|
|
27
|
+
inputAsset = 'bifrost_dot-LOCAL-DOT';
|
|
28
|
+
rewardAssets = ['bifrost_dot-LOCAL-DOT'];
|
|
29
|
+
feeAssets = ['bifrost_dot-NATIVE-BNC', 'bifrost_dot-LOCAL-DOT'];
|
|
30
|
+
minAmountPercent = 0.99;
|
|
31
|
+
availableMethod = {
|
|
32
|
+
join: true,
|
|
33
|
+
defaultUnstake: true,
|
|
34
|
+
fastUnstake: true,
|
|
35
|
+
cancelUnstake: false,
|
|
36
|
+
withdraw: false,
|
|
37
|
+
claimReward: false
|
|
38
|
+
};
|
|
39
|
+
rateDecimals = 0;
|
|
40
|
+
constructor(state, chain) {
|
|
41
|
+
super(state, chain);
|
|
42
|
+
const chainInfo = this.chainInfo;
|
|
43
|
+
this.slug = `DOT___liquid_staking___${chain}`;
|
|
44
|
+
this.name = `${chainInfo.name} Liquid Staking`;
|
|
45
|
+
this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
|
|
46
|
+
}
|
|
47
|
+
getDescription() {
|
|
48
|
+
return 'Stake DOT to earn yield on vDOT';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Subscribe pool info */
|
|
52
|
+
|
|
53
|
+
async getPoolStat() {
|
|
54
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
55
|
+
const stakingMetaPromise = new Promise(function (resolve) {
|
|
56
|
+
(0, _crossFetch.default)(STATS_URL, {
|
|
57
|
+
method: 'GET'
|
|
58
|
+
}).then(res => {
|
|
59
|
+
resolve(res.json());
|
|
60
|
+
}).catch(console.error);
|
|
61
|
+
});
|
|
62
|
+
const exchangeRatePromise = new Promise(function (resolve) {
|
|
63
|
+
(0, _crossFetch.default)(BIFROST_GRAPHQL_ENDPOINT, {
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: {
|
|
66
|
+
'Content-Type': 'application/json'
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify({
|
|
69
|
+
query: BIFROST_EXCHANGE_RATE_REQUEST
|
|
70
|
+
})
|
|
71
|
+
}).then(resp => {
|
|
72
|
+
resolve(resp.json());
|
|
73
|
+
}).catch(console.error);
|
|
74
|
+
});
|
|
75
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
|
|
76
|
+
const inputTokenInfo = this.state.getAssetBySlug(this.inputAsset);
|
|
77
|
+
const [_stakingMeta, _exchangeRate, _minimumRedeem, _minimumMint] = await Promise.all([stakingMetaPromise, exchangeRatePromise, substrateApi.api.query.vtokenMinting.minimumRedeem((0, _utils._getTokenOnChainInfo)(derivativeTokenInfo)), substrateApi.api.query.vtokenMinting.minimumMint((0, _utils._getTokenOnChainInfo)(inputTokenInfo))]);
|
|
78
|
+
const minimumRedeem = _minimumRedeem.toString();
|
|
79
|
+
const minimumMint = _minimumMint.toString();
|
|
80
|
+
const stakingMeta = _stakingMeta;
|
|
81
|
+
const exchangeRate = _exchangeRate;
|
|
82
|
+
const vDOTStats = stakingMeta.vDOT;
|
|
83
|
+
const assetInfo = this.state.getAssetBySlug(this.inputAsset);
|
|
84
|
+
const assetDecimals = 10 ** (0, _utils._getAssetDecimals)(assetInfo);
|
|
85
|
+
const rate = parseFloat(exchangeRate.data.slp_polkadot_ratio[0].ratio);
|
|
86
|
+
this.updateExchangeRate(rate);
|
|
87
|
+
return {
|
|
88
|
+
...this.baseInfo,
|
|
89
|
+
type: this.type,
|
|
90
|
+
metadata: {
|
|
91
|
+
...this.metadataInfo,
|
|
92
|
+
description: this.getDescription()
|
|
93
|
+
},
|
|
94
|
+
statistic: {
|
|
95
|
+
assetEarning: [{
|
|
96
|
+
slug: this.rewardAssets[0],
|
|
97
|
+
apy: parseFloat(vDOTStats.apyBase),
|
|
98
|
+
exchangeRate: rate
|
|
99
|
+
}],
|
|
100
|
+
unstakingPeriod: 24 * 28,
|
|
101
|
+
maxCandidatePerFarmer: 1,
|
|
102
|
+
maxWithdrawalRequestPerFarmer: 1,
|
|
103
|
+
earningThreshold: {
|
|
104
|
+
join: minimumMint,
|
|
105
|
+
defaultUnstake: minimumRedeem,
|
|
106
|
+
fastUnstake: '0'
|
|
107
|
+
},
|
|
108
|
+
totalApy: parseFloat(vDOTStats.apyBase),
|
|
109
|
+
tvl: (vDOTStats.tvm * assetDecimals).toString()
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* Subscribe pool info */
|
|
115
|
+
|
|
116
|
+
/* Subscribe pool position */
|
|
117
|
+
|
|
118
|
+
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
119
|
+
let cancel = false;
|
|
120
|
+
const substrateApi = this.substrateApi;
|
|
121
|
+
await substrateApi.isReady;
|
|
122
|
+
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
125
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
126
|
+
const inputTokenSlug = this.inputAsset;
|
|
127
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
128
|
+
const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, (0, _utils._getTokenOnChainInfo)(derivativeTokenInfo)]), async _balance => {
|
|
129
|
+
if (cancel) {
|
|
130
|
+
unsub();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const balances = _balance;
|
|
134
|
+
const [_unlockLedgerList, _currentRelayEra, rate] = await Promise.all([substrateApi.api.query.vtokenMinting.userUnlockLedger.multi(useAddresses.map(address => [address, (0, _utils._getTokenOnChainInfo)(inputTokenInfo)])), substrateApi.api.query.vtokenMinting.ongoingTimeUnit((0, _utils._getTokenOnChainInfo)(inputTokenInfo)), this.getExchangeRate()]);
|
|
135
|
+
const exchangeRate = new _bignumber.default(rate);
|
|
136
|
+
const currentRelayEraObj = _currentRelayEra.toPrimitive();
|
|
137
|
+
const currentRelayEra = currentRelayEraObj.Era;
|
|
138
|
+
const unlockLedgerList = [];
|
|
139
|
+
const activeBalanceMap = {};
|
|
140
|
+
for (let i = 0; i < balances.length; i++) {
|
|
141
|
+
const balanceItem = balances[i];
|
|
142
|
+
const address = useAddresses[i];
|
|
143
|
+
const formattedAddress = (0, _utils2.reformatAddress)(address);
|
|
144
|
+
activeBalanceMap[formattedAddress] = balanceItem.free || _util.BN_ZERO;
|
|
145
|
+
const _unlockLedger = _unlockLedgerList[i];
|
|
146
|
+
const unlockLedger = _unlockLedger.toPrimitive();
|
|
147
|
+
if (unlockLedger) {
|
|
148
|
+
// @ts-ignore
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
150
|
+
const unstakingLedgerIds = unlockLedger[1];
|
|
151
|
+
unstakingLedgerIds.forEach(ledgerId => {
|
|
152
|
+
unlockLedgerList.push({
|
|
153
|
+
address: formattedAddress,
|
|
154
|
+
ledgerId
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// const bnTotalBalance = bnActiveBalance.add(bnUnstakingBalance);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const unlockingMap = {};
|
|
163
|
+
|
|
164
|
+
// TODO: review unstaking info vtokenMinting.userUnlockLedger
|
|
165
|
+
const _unlockInfoList = await substrateApi.api.query.vtokenMinting.tokenUnlockLedger.multi(unlockLedgerList.map(_ref => {
|
|
166
|
+
let {
|
|
167
|
+
ledgerId
|
|
168
|
+
} = _ref;
|
|
169
|
+
return [(0, _utils._getTokenOnChainInfo)(inputTokenInfo), ledgerId];
|
|
170
|
+
}));
|
|
171
|
+
for (let i = 0; i < _unlockInfoList.length; i++) {
|
|
172
|
+
const unlockInfo = _unlockInfoList[i].toPrimitive();
|
|
173
|
+
const owner = (0, _utils2.reformatAddress)(unlockInfo[0]);
|
|
174
|
+
const amount = unlockInfo[1].toString();
|
|
175
|
+
// @ts-ignore
|
|
176
|
+
const withdrawalEra = unlockInfo[2].era;
|
|
177
|
+
if (owner in unlockingMap) {
|
|
178
|
+
unlockingMap[owner].push({
|
|
179
|
+
balance: amount,
|
|
180
|
+
era: withdrawalEra
|
|
181
|
+
});
|
|
182
|
+
} else {
|
|
183
|
+
unlockingMap[owner] = [{
|
|
184
|
+
balance: amount,
|
|
185
|
+
era: withdrawalEra
|
|
186
|
+
}];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const unstakingList = [];
|
|
190
|
+
useAddresses.forEach(address => {
|
|
191
|
+
const formattedAddress = (0, _utils2.reformatAddress)(address);
|
|
192
|
+
const bnActiveBalance = activeBalanceMap[formattedAddress];
|
|
193
|
+
const unlockings = unlockingMap[formattedAddress];
|
|
194
|
+
let unlockBalance = _util.BN_ZERO;
|
|
195
|
+
if (unlockings) {
|
|
196
|
+
unlockings.forEach(unlocking => {
|
|
197
|
+
const isClaimable = unlocking.era - currentRelayEra < 0;
|
|
198
|
+
const remainingEra = unlocking.era - currentRelayEra;
|
|
199
|
+
const waitingTime = remainingEra * _constants._STAKING_ERA_LENGTH_MAP[this.chain];
|
|
200
|
+
unlockBalance = unlockBalance.add(new _util.BN(unlocking.balance));
|
|
201
|
+
unstakingList.push({
|
|
202
|
+
chain: this.chain,
|
|
203
|
+
status: isClaimable ? _types.UnstakingStatus.CLAIMABLE : _types.UnstakingStatus.UNLOCKING,
|
|
204
|
+
claimable: unlocking.balance,
|
|
205
|
+
waitingTime: waitingTime
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
const activeToTotalBalance = exchangeRate.multipliedBy(bnActiveBalance.toString());
|
|
210
|
+
const totalBalance = activeToTotalBalance.plus(unlockBalance.toString());
|
|
211
|
+
const result = {
|
|
212
|
+
...this.baseInfo,
|
|
213
|
+
type: this.type,
|
|
214
|
+
address,
|
|
215
|
+
balanceToken: this.inputAsset,
|
|
216
|
+
derivativeToken: derivativeTokenSlug,
|
|
217
|
+
totalStake: totalBalance.toString(),
|
|
218
|
+
activeStake: bnActiveBalance.toString(),
|
|
219
|
+
unstakeBalance: unlockBalance.toString(),
|
|
220
|
+
status: bnActiveBalance.gt(_util.BN_ZERO) ? _types.EarningStatus.EARNING_REWARD : _types.EarningStatus.NOT_EARNING,
|
|
221
|
+
isBondedBefore: totalBalance.gt(_util.BN_ZERO.toString()),
|
|
222
|
+
nominations: [],
|
|
223
|
+
unstakings: unstakingList
|
|
224
|
+
};
|
|
225
|
+
resultCallback(result);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
return () => {
|
|
229
|
+
cancel = true;
|
|
230
|
+
unsub();
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* Subscribe pool position */
|
|
235
|
+
|
|
236
|
+
/* Join pool action */
|
|
237
|
+
|
|
238
|
+
get submitJoinStepInfo() {
|
|
239
|
+
return {
|
|
240
|
+
name: 'Mint vDOT',
|
|
241
|
+
type: _types.YieldStepType.MINT_VDOT
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
async getSubmitStepFee(params) {
|
|
245
|
+
const poolOriginSubstrateApi = await this.substrateApi.isReady;
|
|
246
|
+
const inputTokenSlug = this.inputAsset;
|
|
247
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
248
|
+
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
249
|
+
if (new _util.BN(params.amount).gt(_util.BN_ZERO)) {
|
|
250
|
+
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.vtokenMinting.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), params.amount, null).paymentInfo(_constants2.fakeAddress);
|
|
251
|
+
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
252
|
+
return {
|
|
253
|
+
amount: mintFeeInfo.partialFee.toString(),
|
|
254
|
+
slug: defaultFeeTokenSlug
|
|
255
|
+
};
|
|
256
|
+
} else {
|
|
257
|
+
return {
|
|
258
|
+
amount: '0',
|
|
259
|
+
slug: defaultFeeTokenSlug
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async handleSubmitStep(data, path) {
|
|
264
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
265
|
+
const inputTokenSlug = this.inputAsset;
|
|
266
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
267
|
+
const extrinsic = substrateApi.api.tx.vtokenMinting.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), data.amount, undefined);
|
|
268
|
+
return {
|
|
269
|
+
txChain: this.chain,
|
|
270
|
+
extrinsicType: _KoniTypes.ExtrinsicType.MINT_VDOT,
|
|
271
|
+
extrinsic,
|
|
272
|
+
txData: data,
|
|
273
|
+
transferNativeAmount: '0',
|
|
274
|
+
chainType: _KoniTypes.ChainType.SUBSTRATE
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/* Join pool action */
|
|
279
|
+
|
|
280
|
+
/* Leave pool action */
|
|
281
|
+
|
|
282
|
+
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
283
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
284
|
+
const weightedMinAmount = await this.createParamToRedeem(amount, address);
|
|
285
|
+
const extrinsic = substrateApi.api.tx.stablePool.swap(0, 1, 0, amount, weightedMinAmount);
|
|
286
|
+
return [_KoniTypes.ExtrinsicType.REDEEM_VDOT, extrinsic];
|
|
287
|
+
}
|
|
288
|
+
async handleYieldUnstake(amount, address, selectedTarget) {
|
|
289
|
+
const chainApi = await this.substrateApi.isReady;
|
|
290
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
291
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
292
|
+
const extrinsic = chainApi.api.tx.vtokenMinting.redeem((0, _utils._getTokenOnChainInfo)(derivativeTokenInfo), amount);
|
|
293
|
+
return [_KoniTypes.ExtrinsicType.UNSTAKE_VDOT, extrinsic];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/* Leave pool action */
|
|
297
|
+
}
|
|
298
|
+
exports.default = BifrostLiquidStakingPoolHandler;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "AcalaLiquidStakingPoolHandler", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _acala.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "BifrostLiquidStakingPoolHandler", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _bifrost.default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "ParallelLiquidStakingPoolHandler", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _parallel.default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "StellaSwapLiquidStakingPoolHandler", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _stellaSwap.default;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var _acala = _interopRequireDefault(require("./acala"));
|
|
32
|
+
var _bifrost = _interopRequireDefault(require("./bifrost"));
|
|
33
|
+
var _parallel = _interopRequireDefault(require("./parallel"));
|
|
34
|
+
var _stellaSwap = _interopRequireDefault(require("./stella-swap"));
|