@subwallet/extension-base 1.1.29-0 → 1.1.29-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +95 -68
- package/background/KoniTypes.js +16 -13
- package/background/errors/TransactionError.js +9 -0
- package/cjs/background/KoniTypes.js +17 -16
- package/cjs/background/errors/TransactionError.js +9 -0
- package/cjs/constants/index.js +19 -4
- package/cjs/koni/api/nft/config.js +33 -23
- package/cjs/koni/api/nft/index.js +14 -0
- package/cjs/koni/api/nft/nft.js +1 -22
- package/cjs/koni/api/nft/ordinal_nft/constants.js +21 -0
- package/cjs/koni/api/nft/ordinal_nft/index.js +121 -0
- package/cjs/koni/api/nft/ordinal_nft/utils.js +41 -0
- package/cjs/koni/api/staking/bonding/amplitude.js +17 -15
- package/cjs/koni/api/staking/bonding/astar.js +11 -10
- package/cjs/koni/api/staking/bonding/index.js +4 -1
- package/cjs/koni/api/staking/bonding/paraChain.js +25 -23
- package/cjs/koni/api/staking/bonding/relayChain.js +48 -45
- package/cjs/koni/api/staking/bonding/utils.js +104 -86
- package/cjs/koni/api/staking/index.js +6 -5
- package/cjs/koni/api/staking/paraChain.js +6 -5
- package/cjs/koni/api/staking/relayChain.js +3 -2
- package/cjs/koni/api/yield/helper/utils.js +46 -0
- package/cjs/koni/background/cron.js +11 -1
- package/cjs/koni/background/handlers/Extension.js +362 -69
- package/cjs/koni/background/handlers/State.js +51 -3
- package/cjs/koni/background/handlers/index.js +4 -2
- package/cjs/koni/background/subscription.js +95 -37
- package/cjs/services/campaign-service/index.js +9 -6
- package/cjs/services/chain-service/constants.js +2 -16
- package/cjs/services/chain-service/utils.js +7 -1
- package/cjs/services/earning-service/constants/chains.js +29 -0
- package/cjs/services/earning-service/constants/index.js +27 -0
- package/cjs/services/earning-service/constants/step.js +18 -0
- package/cjs/services/earning-service/handlers/base.js +232 -0
- package/cjs/services/earning-service/handlers/index.js +60 -0
- package/cjs/services/earning-service/handlers/lending/base.js +20 -0
- package/cjs/services/earning-service/handlers/lending/index.js +13 -0
- package/cjs/services/earning-service/handlers/lending/interlay.js +184 -0
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +217 -0
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +43 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +283 -0
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +196 -0
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +409 -0
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +382 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +459 -0
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +137 -0
- package/cjs/services/earning-service/handlers/native-staking/base.js +159 -0
- package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +383 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +542 -0
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +541 -0
- package/cjs/services/earning-service/handlers/special.js +411 -0
- package/cjs/services/earning-service/service.js +387 -0
- package/cjs/services/earning-service/utils/index.js +128 -0
- package/cjs/services/event-service/index.js +4 -0
- package/cjs/services/keyring-service/index.js +14 -2
- package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
- package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
- package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +21 -0
- package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +21 -0
- package/cjs/services/migration-service/scripts/index.js +7 -1
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
- package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
- package/cjs/services/mint-campaign-service/constants.js +11 -0
- package/cjs/services/mint-campaign-service/index.js +18 -0
- package/cjs/services/notification-service/NotificationService.js +1 -1
- package/cjs/services/storage-service/DatabaseService.js +51 -0
- package/cjs/services/storage-service/databases/index.js +4 -0
- package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/cjs/services/storage-service/db-stores/YieldPoolStore.js +36 -0
- package/cjs/services/storage-service/db-stores/YieldPositionStore.js +65 -0
- package/cjs/services/subscan-service/index.js +16 -0
- package/cjs/services/transaction-service/event-parser/index.js +58 -0
- package/cjs/services/transaction-service/helpers/index.js +3 -1
- package/cjs/services/transaction-service/index.js +185 -74
- package/cjs/services/transaction-service/utils.js +1 -0
- package/cjs/types/campaigns/index.js +16 -0
- package/cjs/types/campaigns/unlock-dot.js +1 -0
- package/cjs/types/index.js +44 -0
- package/cjs/types/ordinal.js +1 -0
- package/cjs/types/transaction.js +1 -0
- package/cjs/types/yield/actions/index.js +27 -0
- package/cjs/types/yield/actions/join/index.js +38 -0
- package/cjs/types/yield/actions/join/step.js +47 -0
- package/cjs/types/yield/actions/join/submit.js +1 -0
- package/cjs/types/yield/actions/join/validate.js +16 -0
- package/cjs/types/yield/actions/others.js +1 -0
- package/cjs/types/yield/index.js +27 -0
- package/cjs/types/yield/info/account/index.js +49 -0
- package/cjs/types/yield/info/account/info.js +1 -0
- package/cjs/types/yield/info/account/reward.js +1 -0
- package/cjs/types/yield/info/account/target.js +32 -0
- package/cjs/types/yield/info/account/unstake.js +27 -0
- package/cjs/types/yield/info/base.js +41 -0
- package/cjs/types/yield/info/chain/index.js +27 -0
- package/cjs/types/yield/info/chain/info.js +1 -0
- package/cjs/types/yield/info/chain/target.js +1 -0
- package/cjs/types/yield/info/index.js +49 -0
- package/cjs/types/yield/info/pallet.js +15 -0
- package/cjs/utils/fetchStaticData.js +2 -1
- package/cjs/utils/index.js +89 -1
- package/cjs/utils/object.js +12 -0
- package/cjs/utils/yield/index.js +3 -0
- package/constants/index.d.ts +6 -1
- package/constants/index.js +6 -1
- package/koni/api/nft/config.js +33 -23
- package/koni/api/nft/index.js +15 -1
- package/koni/api/nft/nft.js +2 -23
- package/koni/api/nft/ordinal_nft/constants.d.ts +9 -0
- package/koni/api/nft/ordinal_nft/constants.js +12 -0
- package/koni/api/nft/ordinal_nft/index.d.ts +8 -0
- package/koni/api/nft/ordinal_nft/index.js +114 -0
- package/koni/api/nft/ordinal_nft/utils.d.ts +2 -0
- package/koni/api/nft/ordinal_nft/utils.js +33 -0
- package/koni/api/staking/bonding/amplitude.js +11 -9
- package/koni/api/staking/bonding/astar.js +9 -8
- package/koni/api/staking/bonding/index.d.ts +1 -1
- package/koni/api/staking/bonding/index.js +5 -1
- package/koni/api/staking/bonding/paraChain.js +12 -10
- package/koni/api/staking/bonding/relayChain.d.ts +2 -2
- package/koni/api/staking/bonding/relayChain.js +33 -30
- package/koni/api/staking/bonding/utils.d.ts +15 -38
- package/koni/api/staking/bonding/utils.js +85 -69
- package/koni/api/staking/index.js +2 -1
- package/koni/api/staking/paraChain.js +7 -6
- package/koni/api/staking/relayChain.js +4 -3
- package/koni/api/yield/helper/utils.d.ts +10 -0
- package/koni/api/yield/helper/utils.js +32 -0
- package/koni/background/cron.d.ts +1 -0
- package/koni/background/cron.js +12 -2
- package/koni/background/handlers/Extension.d.ts +17 -1
- package/koni/background/handlers/Extension.js +321 -30
- package/koni/background/handlers/State.d.ts +18 -2
- package/koni/background/handlers/State.js +50 -3
- package/koni/background/handlers/index.js +4 -2
- package/koni/background/subscription.d.ts +6 -1
- package/koni/background/subscription.js +97 -38
- package/package.json +316 -3
- package/services/campaign-service/index.js +9 -6
- package/services/chain-service/constants.d.ts +0 -11
- package/services/chain-service/constants.js +1 -14
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +5 -1
- package/services/earning-service/constants/abis/compound_finance_v2_abi.json +1235 -0
- package/services/earning-service/constants/abis/st_liquid_token_abi.json +1355 -0
- package/services/earning-service/constants/chains.d.ts +14 -0
- package/services/earning-service/constants/chains.js +21 -0
- package/services/earning-service/constants/index.d.ts +2 -0
- package/services/earning-service/constants/index.js +5 -0
- package/services/earning-service/constants/step.d.ts +3 -0
- package/services/earning-service/constants/step.js +10 -0
- package/services/earning-service/handlers/base.d.ts +112 -0
- package/services/earning-service/handlers/base.js +226 -0
- package/services/earning-service/handlers/index.d.ts +5 -0
- package/services/earning-service/handlers/index.js +8 -0
- package/services/earning-service/handlers/lending/base.d.ts +6 -0
- package/services/earning-service/handlers/lending/base.js +12 -0
- package/services/earning-service/handlers/lending/index.d.ts +1 -0
- package/services/earning-service/handlers/lending/index.js +4 -0
- package/services/earning-service/handlers/lending/interlay.d.ts +23 -0
- package/services/earning-service/handlers/lending/interlay.js +176 -0
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +26 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +209 -0
- package/services/earning-service/handlers/liquid-staking/base.d.ts +9 -0
- package/services/earning-service/handlers/liquid-staking/base.js +35 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +45 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.js +272 -0
- package/services/earning-service/handlers/liquid-staking/index.d.ts +4 -0
- package/services/earning-service/handlers/liquid-staking/index.js +7 -0
- package/services/earning-service/handlers/liquid-staking/parallel.d.ts +25 -0
- package/services/earning-service/handlers/liquid-staking/parallel.js +188 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +34 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +399 -0
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +373 -0
- package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
- package/services/earning-service/handlers/native-staking/astar.js +449 -0
- package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
- package/services/earning-service/handlers/native-staking/base-para.js +129 -0
- package/services/earning-service/handlers/native-staking/base.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/base.js +150 -0
- package/services/earning-service/handlers/native-staking/index.d.ts +4 -0
- package/services/earning-service/handlers/native-staking/index.js +7 -0
- package/services/earning-service/handlers/native-staking/para-chain.d.ts +15 -0
- package/services/earning-service/handlers/native-staking/para-chain.js +375 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +533 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +35 -0
- package/services/earning-service/handlers/nomination-pool/index.js +531 -0
- package/services/earning-service/handlers/special.d.ts +56 -0
- package/services/earning-service/handlers/special.js +403 -0
- package/services/earning-service/service.d.ts +45 -0
- package/services/earning-service/service.js +379 -0
- package/services/earning-service/utils/index.d.ts +18 -0
- package/services/earning-service/utils/index.js +112 -0
- package/services/event-service/index.d.ts +1 -0
- package/services/event-service/index.js +4 -0
- package/services/event-service/types.d.ts +8 -0
- package/services/keyring-service/index.d.ts +2 -1
- package/services/keyring-service/index.js +14 -2
- package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
- package/services/migration-service/scripts/DeleteEarningData.js +13 -0
- package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
- package/services/migration-service/scripts/EnableEarningChains.js +13 -0
- package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningHistory.js +13 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.js +13 -0
- package/services/migration-service/scripts/index.js +7 -1
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
- package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
- package/services/mint-campaign-service/campaigns/index.js +4 -0
- package/services/mint-campaign-service/constants.d.ts +1 -0
- package/services/mint-campaign-service/constants.js +4 -0
- package/services/mint-campaign-service/index.d.ts +7 -0
- package/services/mint-campaign-service/index.js +11 -0
- package/services/notification-service/NotificationService.js +1 -1
- package/services/storage-service/DatabaseService.d.ts +18 -1
- package/services/storage-service/DatabaseService.js +51 -0
- package/services/storage-service/databases/index.d.ts +3 -1
- package/services/storage-service/databases/index.js +4 -0
- package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/services/storage-service/db-stores/YieldPoolStore.d.ts +10 -0
- package/services/storage-service/db-stores/YieldPoolStore.js +28 -0
- package/services/storage-service/db-stores/YieldPositionStore.d.ts +9 -0
- package/services/storage-service/db-stores/YieldPositionStore.js +57 -0
- package/services/subscan-service/index.d.ts +3 -2
- package/services/subscan-service/index.js +15 -0
- package/services/subscan-service/types.d.ts +20 -0
- package/services/transaction-service/event-parser/index.d.ts +3 -1
- package/services/transaction-service/event-parser/index.js +57 -1
- package/services/transaction-service/helpers/index.js +3 -1
- package/services/transaction-service/index.d.ts +4 -15
- package/services/transaction-service/index.js +183 -72
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.js +1 -0
- package/types/campaigns/index.d.ts +1 -0
- package/types/campaigns/index.js +4 -0
- package/types/campaigns/unlock-dot.d.ts +71 -0
- package/types/campaigns/unlock-dot.js +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.js +5 -1
- package/types/ordinal.d.ts +69 -0
- package/types/ordinal.js +1 -0
- package/types/transaction.d.ts +3 -0
- package/types/transaction.js +1 -0
- package/types/yield/actions/index.d.ts +2 -0
- package/types/yield/actions/index.js +5 -0
- package/types/yield/actions/join/index.d.ts +3 -0
- package/types/yield/actions/join/index.js +6 -0
- package/types/yield/actions/join/step.d.ts +94 -0
- package/types/yield/actions/join/step.js +46 -0
- package/types/yield/actions/join/submit.d.ts +53 -0
- package/types/yield/actions/join/submit.js +1 -0
- package/types/yield/actions/join/validate.d.ts +18 -0
- package/types/yield/actions/join/validate.js +10 -0
- package/types/yield/actions/others.d.ts +63 -0
- package/types/yield/actions/others.js +1 -0
- package/types/yield/index.d.ts +2 -0
- package/types/yield/index.js +5 -0
- package/types/yield/info/account/index.d.ts +4 -0
- package/types/yield/info/account/index.js +7 -0
- package/types/yield/info/account/info.d.ts +92 -0
- package/types/yield/info/account/info.js +1 -0
- package/types/yield/info/account/reward.d.ts +45 -0
- package/types/yield/info/account/reward.js +1 -0
- package/types/yield/info/account/target.d.ts +43 -0
- package/types/yield/info/account/target.js +27 -0
- package/types/yield/info/account/unstake.d.ts +31 -0
- package/types/yield/info/account/unstake.js +22 -0
- package/types/yield/info/base.d.ts +45 -0
- package/types/yield/info/base.js +36 -0
- package/types/yield/info/chain/index.d.ts +2 -0
- package/types/yield/info/chain/index.js +5 -0
- package/types/yield/info/chain/info.d.ts +243 -0
- package/types/yield/info/chain/info.js +1 -0
- package/types/yield/info/chain/target.d.ts +37 -0
- package/types/yield/info/chain/target.js +1 -0
- package/types/yield/info/index.d.ts +4 -0
- package/types/yield/info/index.js +7 -0
- package/types/yield/info/pallet.d.ts +143 -0
- package/types/yield/info/pallet.js +9 -0
- package/utils/fetchStaticData.js +2 -1
- package/utils/index.d.ts +5 -0
- package/utils/index.js +53 -1
- package/utils/object.d.ts +1 -0
- package/utils/object.js +6 -0
|
@@ -0,0 +1,196 @@
|
|
|
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 _util = require("@polkadot/util");
|
|
13
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
14
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
class ParallelLiquidStakingPoolHandler extends _base.default {
|
|
18
|
+
altInputAsset = 'polkadot-NATIVE-DOT';
|
|
19
|
+
derivativeAssets = ['parallel-LOCAL-sDOT'];
|
|
20
|
+
inputAsset = 'parallel-LOCAL-DOT';
|
|
21
|
+
rewardAssets = ['parallel-LOCAL-DOT'];
|
|
22
|
+
feeAssets = ['parallel-NATIVE-PARA'];
|
|
23
|
+
minAmountPercent = 0.97;
|
|
24
|
+
availableMethod = {
|
|
25
|
+
join: true,
|
|
26
|
+
defaultUnstake: true,
|
|
27
|
+
fastUnstake: true,
|
|
28
|
+
cancelUnstake: false,
|
|
29
|
+
withdraw: false,
|
|
30
|
+
claimReward: false
|
|
31
|
+
};
|
|
32
|
+
constructor(state, chain) {
|
|
33
|
+
super(state, chain);
|
|
34
|
+
const chainInfo = this.chainInfo;
|
|
35
|
+
this.slug = `DOT___liquid_staking___${chain}`;
|
|
36
|
+
this.name = `${chainInfo.name} Liquid Staking`;
|
|
37
|
+
this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
|
|
38
|
+
}
|
|
39
|
+
getDescription() {
|
|
40
|
+
return 'Stake DOT to earn yield on sDOT';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* Subscribe pool info */
|
|
44
|
+
|
|
45
|
+
async getPoolStat() {
|
|
46
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
47
|
+
const [_exchangeRate, _currentBlockHeader, _currentTimestamp, _stakingLedgers] = await Promise.all([substrateApi.api.query.liquidStaking.exchangeRate(), substrateApi.api.rpc.chain.getHeader(), substrateApi.api.query.timestamp.now(), substrateApi.api.query.liquidStaking.stakingLedgers.entries()]);
|
|
48
|
+
let tvl = _util.BN_ZERO;
|
|
49
|
+
for (const _stakingLedger of _stakingLedgers) {
|
|
50
|
+
const _ledger = _stakingLedger[1];
|
|
51
|
+
const ledger = _ledger.toPrimitive();
|
|
52
|
+
tvl = tvl.add(new _util.BN(ledger.total.toString()));
|
|
53
|
+
}
|
|
54
|
+
const exchangeRate = _exchangeRate.toPrimitive();
|
|
55
|
+
const currentBlockHeader = _currentBlockHeader.toPrimitive();
|
|
56
|
+
const currentTimestamp = _currentTimestamp.toPrimitive();
|
|
57
|
+
const beginBlock = currentBlockHeader.number - 24 * 60 * 60 / 6 * 14;
|
|
58
|
+
const _beginBlockHash = await substrateApi.api.rpc.chain.getBlockHash(beginBlock);
|
|
59
|
+
const beginBlockHash = _beginBlockHash.toString();
|
|
60
|
+
const [_beginTimestamp, _beginExchangeRate] = await Promise.all([substrateApi.api.query.timestamp.now.at(beginBlockHash), substrateApi.api.query.liquidStaking.exchangeRate.at(beginBlockHash)]);
|
|
61
|
+
const beginTimestamp = _beginTimestamp.toPrimitive();
|
|
62
|
+
const beginExchangeRate = _beginExchangeRate.toPrimitive();
|
|
63
|
+
const decimals = 10 ** 18;
|
|
64
|
+
const apy = (exchangeRate / beginExchangeRate) ** (365 * 24 * 60 * 60000 / (currentTimestamp - beginTimestamp)) - 1;
|
|
65
|
+
return {
|
|
66
|
+
...this.baseInfo,
|
|
67
|
+
type: this.type,
|
|
68
|
+
metadata: {
|
|
69
|
+
...this.metadataInfo,
|
|
70
|
+
description: this.getDescription()
|
|
71
|
+
},
|
|
72
|
+
statistic: {
|
|
73
|
+
assetEarning: [{
|
|
74
|
+
slug: this.rewardAssets[0],
|
|
75
|
+
apy: apy * 100,
|
|
76
|
+
exchangeRate: exchangeRate / decimals
|
|
77
|
+
}],
|
|
78
|
+
unstakingPeriod: 24 * 28,
|
|
79
|
+
maxCandidatePerFarmer: 1,
|
|
80
|
+
maxWithdrawalRequestPerFarmer: 1,
|
|
81
|
+
minJoinPool: '10000000000',
|
|
82
|
+
minWithdrawal: '5000000000',
|
|
83
|
+
totalApy: apy * 100,
|
|
84
|
+
tvl: tvl.toString()
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* Subscribe pool info */
|
|
90
|
+
|
|
91
|
+
/* Subscribe pool position */
|
|
92
|
+
|
|
93
|
+
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
94
|
+
let cancel = false;
|
|
95
|
+
const substrateApi = this.substrateApi;
|
|
96
|
+
await substrateApi.isReady;
|
|
97
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
98
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
99
|
+
const unsub = await substrateApi.api.query.assets.account.multi(useAddresses.map(address => [(0, _utils._getTokenOnChainAssetId)(derivativeTokenInfo), address]), balances => {
|
|
100
|
+
if (cancel) {
|
|
101
|
+
unsub();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
for (let i = 0; i < balances.length; i++) {
|
|
105
|
+
const b = balances[i];
|
|
106
|
+
const address = useAddresses[i];
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
|
|
109
|
+
const bdata = b === null || b === void 0 ? void 0 : b.toHuman();
|
|
110
|
+
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
|
|
113
|
+
const bnTotalBalance = bdata && bdata.balance ? new _util.BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance).replaceAll(',', '') || '0') : _util.BN_ZERO;
|
|
114
|
+
const totalBalance = bnTotalBalance.toString();
|
|
115
|
+
const result = {
|
|
116
|
+
...this.baseInfo,
|
|
117
|
+
type: this.type,
|
|
118
|
+
address,
|
|
119
|
+
balanceToken: this.inputAsset,
|
|
120
|
+
totalStake: totalBalance,
|
|
121
|
+
activeStake: totalBalance,
|
|
122
|
+
unstakeBalance: '0',
|
|
123
|
+
status: _types.EarningStatus.EARNING_REWARD,
|
|
124
|
+
derivativeToken: derivativeTokenSlug,
|
|
125
|
+
isBondedBefore: bnTotalBalance.gt(_util.BN_ZERO),
|
|
126
|
+
nominations: [],
|
|
127
|
+
// TODO: add unstaking info from liquidStaking.unlockings
|
|
128
|
+
unstakings: []
|
|
129
|
+
};
|
|
130
|
+
resultCallback(result);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
return () => {
|
|
134
|
+
cancel = true;
|
|
135
|
+
unsub();
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* Subscribe pool position */
|
|
140
|
+
|
|
141
|
+
/* Join pool action */
|
|
142
|
+
|
|
143
|
+
get submitJoinStepInfo() {
|
|
144
|
+
return {
|
|
145
|
+
name: 'Mint sDOT',
|
|
146
|
+
type: _types.YieldStepType.MINT_SDOT
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
async getSubmitStepFee(params) {
|
|
150
|
+
const poolOriginSubstrateApi = await this.substrateApi.isReady;
|
|
151
|
+
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
152
|
+
if (new _util.BN(params.amount).gt(_util.BN_ZERO)) {
|
|
153
|
+
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.liquidStaking.stake(params.amount).paymentInfo(_constants.fakeAddress);
|
|
154
|
+
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
155
|
+
return {
|
|
156
|
+
amount: mintFeeInfo.partialFee.toString(),
|
|
157
|
+
slug: defaultFeeTokenSlug
|
|
158
|
+
};
|
|
159
|
+
} else {
|
|
160
|
+
return {
|
|
161
|
+
amount: '0',
|
|
162
|
+
slug: defaultFeeTokenSlug
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async handleSubmitStep(data, path) {
|
|
167
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
168
|
+
const extrinsic = substrateApi.api.tx.liquidStaking.stake(data.amount);
|
|
169
|
+
return {
|
|
170
|
+
txChain: this.chain,
|
|
171
|
+
extrinsicType: _KoniTypes.ExtrinsicType.MINT_SDOT,
|
|
172
|
+
extrinsic,
|
|
173
|
+
txData: data,
|
|
174
|
+
transferNativeAmount: '0'
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* Join pool action */
|
|
179
|
+
|
|
180
|
+
/* Leave pool action */
|
|
181
|
+
|
|
182
|
+
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
183
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
184
|
+
const weightedMinAmount = await this.createParamToRedeem(amount, address);
|
|
185
|
+
const extrinsic = substrateApi.api.tx.ammRoute.swapExactTokensForTokens(['1001', '101'], amount, weightedMinAmount);
|
|
186
|
+
return [_KoniTypes.ExtrinsicType.REDEEM_SDOT, extrinsic];
|
|
187
|
+
}
|
|
188
|
+
async handleYieldUnstake(amount, address, selectedTarget) {
|
|
189
|
+
const chainApi = await this.substrateApi.isReady;
|
|
190
|
+
const extrinsic = chainApi.api.tx.liquidStaking.unstake(amount, 'RelayChain');
|
|
191
|
+
return [_KoniTypes.ExtrinsicType.UNSTAKE_SDOT, extrinsic];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* Leave pool action */
|
|
195
|
+
}
|
|
196
|
+
exports.default = ParallelLiquidStakingPoolHandler;
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getStellaswapLiquidStakingContract = 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 _web = require("@subwallet/extension-base/koni/api/tokens/evm/web3");
|
|
11
|
+
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
12
|
+
var _types = require("@subwallet/extension-base/types");
|
|
13
|
+
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
14
|
+
var _util = require("@polkadot/util");
|
|
15
|
+
var _constants = require("../../constants");
|
|
16
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
17
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
18
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
19
|
+
|
|
20
|
+
const getStellaswapLiquidStakingContract = function (networkKey, assetAddress, evmApi) {
|
|
21
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
24
|
+
return new evmApi.api.eth.Contract(_constants.ST_LIQUID_TOKEN_ABI, assetAddress, options);
|
|
25
|
+
};
|
|
26
|
+
exports.getStellaswapLiquidStakingContract = getStellaswapLiquidStakingContract;
|
|
27
|
+
const APR_STATS_URL = 'https://apr-api.stellaswap.com/api/v1/stdot';
|
|
28
|
+
const SUBWALLET_REFERRAL = '0x7e6815f45E624768548d085231f2d453f16FD7DD';
|
|
29
|
+
const MAX_INT = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
30
|
+
class StellaSwapLiquidStakingPoolHandler extends _base.default {
|
|
31
|
+
inputAsset = 'moonbeam-LOCAL-xcDOT';
|
|
32
|
+
altInputAsset = '';
|
|
33
|
+
derivativeAssets = ['moonbeam-ERC20-stDOT-0xbc7E02c4178a7dF7d3E564323a5c359dc96C4db4'];
|
|
34
|
+
rewardAssets = ['moonbeam-LOCAL-xcDOT'];
|
|
35
|
+
feeAssets = ['moonbeam-NATIVE-GLMR'];
|
|
36
|
+
transactionChainType = _KoniTypes.ChainType.EVM;
|
|
37
|
+
availableMethod = {
|
|
38
|
+
join: true,
|
|
39
|
+
defaultUnstake: true,
|
|
40
|
+
fastUnstake: true,
|
|
41
|
+
cancelUnstake: false,
|
|
42
|
+
withdraw: true,
|
|
43
|
+
claimReward: false
|
|
44
|
+
};
|
|
45
|
+
constructor(state, chain) {
|
|
46
|
+
super(state, chain);
|
|
47
|
+
this.slug = 'xcDOT___liquid_staking___stellaswap';
|
|
48
|
+
this.name = 'Stellaswap Liquid Staking';
|
|
49
|
+
this._logo = 'stellaswap';
|
|
50
|
+
this.shortName = 'Stellaswap';
|
|
51
|
+
}
|
|
52
|
+
getDescription() {
|
|
53
|
+
return 'Earn rewards by staking xcDOT for stDOT';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* Subscribe pool info */
|
|
57
|
+
|
|
58
|
+
async getPoolStat() {
|
|
59
|
+
const evmApi = this.evmApi;
|
|
60
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
61
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
62
|
+
const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
|
|
63
|
+
const aprPromise = new Promise(function (resolve) {
|
|
64
|
+
(0, _crossFetch.default)(APR_STATS_URL, {
|
|
65
|
+
method: 'GET'
|
|
66
|
+
}).then(res => {
|
|
67
|
+
resolve(res.json());
|
|
68
|
+
}).catch(console.error);
|
|
69
|
+
});
|
|
70
|
+
const sampleTokenShare = 10 ** (0, _utils._getAssetDecimals)(derivativeTokenInfo);
|
|
71
|
+
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
73
|
+
const tvlCall = stakingContract.methods.fundRaisedBalance();
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
75
|
+
const exchangeRateCall = stakingContract.methods.getPooledTokenByShares(sampleTokenShare);
|
|
76
|
+
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
78
|
+
const [aprObject, tvl, equivalentTokenShare] = await Promise.all([aprPromise,
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
80
|
+
tvlCall.call(),
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
82
|
+
exchangeRateCall.call()]);
|
|
83
|
+
const exchangeRate = equivalentTokenShare / 10 ** (0, _utils._getAssetDecimals)(derivativeTokenInfo);
|
|
84
|
+
return {
|
|
85
|
+
...this.baseInfo,
|
|
86
|
+
type: this.type,
|
|
87
|
+
metadata: {
|
|
88
|
+
...this.metadataInfo,
|
|
89
|
+
description: this.getDescription()
|
|
90
|
+
},
|
|
91
|
+
statistic: {
|
|
92
|
+
assetEarning: [{
|
|
93
|
+
slug: this.rewardAssets[0],
|
|
94
|
+
apr: aprObject.result,
|
|
95
|
+
exchangeRate: exchangeRate
|
|
96
|
+
}],
|
|
97
|
+
unstakingPeriod: 24 * 28,
|
|
98
|
+
maxCandidatePerFarmer: 1,
|
|
99
|
+
maxWithdrawalRequestPerFarmer: 1,
|
|
100
|
+
minJoinPool: '0',
|
|
101
|
+
minWithdrawal: '0',
|
|
102
|
+
totalApr: aprObject.result,
|
|
103
|
+
tvl: tvl.toString()
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* Subscribe pool info */
|
|
109
|
+
|
|
110
|
+
/* Subscribe pool position */
|
|
111
|
+
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
113
|
+
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
114
|
+
var _this$derivativeAsset;
|
|
115
|
+
let cancel = false;
|
|
116
|
+
const evmApi = this.evmApi;
|
|
117
|
+
const derivativeTokenSlug = ((_this$derivativeAsset = this.derivativeAssets) === null || _this$derivativeAsset === void 0 ? void 0 : _this$derivativeAsset[0]) || '';
|
|
118
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
119
|
+
const contract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
|
|
120
|
+
const getTokenBalance = () => {
|
|
121
|
+
if (!cancel) {
|
|
122
|
+
useAddresses.map(async address => {
|
|
123
|
+
if (!cancel) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
128
|
+
const balance = await contract.methods.balanceOf(address).call();
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
130
|
+
const unbondedObject = await contract.methods.getUnbonded(address).call();
|
|
131
|
+
const unstakings = [];
|
|
132
|
+
let unlockBalance = _util.BN_ZERO;
|
|
133
|
+
if (parseInt(unbondedObject.unbonded) > 0) {
|
|
134
|
+
unlockBalance = unlockBalance.add(new _util.BN(unbondedObject.unbonded));
|
|
135
|
+
unstakings.push({
|
|
136
|
+
chain: this.chain,
|
|
137
|
+
claimable: unbondedObject.unbonded,
|
|
138
|
+
status: _types.UnstakingStatus.CLAIMABLE,
|
|
139
|
+
waitingTime: 0
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (parseInt(unbondedObject.waiting) > 0) {
|
|
143
|
+
unlockBalance = unlockBalance.add(new _util.BN(unbondedObject.waiting));
|
|
144
|
+
unstakings.push({
|
|
145
|
+
chain: this.chain,
|
|
146
|
+
claimable: unbondedObject.waiting,
|
|
147
|
+
status: _types.UnstakingStatus.UNLOCKING
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const totalBalance = new _util.BN(balance).add(unlockBalance);
|
|
151
|
+
const result = {
|
|
152
|
+
...this.baseInfo,
|
|
153
|
+
type: this.type,
|
|
154
|
+
address,
|
|
155
|
+
balanceToken: this.inputAsset,
|
|
156
|
+
totalStake: totalBalance.toString(),
|
|
157
|
+
activeStake: balance.toString(),
|
|
158
|
+
unstakeBalance: unlockBalance.toString(),
|
|
159
|
+
isBondedBefore: totalBalance.gt(_util.BN_ZERO),
|
|
160
|
+
derivativeToken: derivativeTokenSlug,
|
|
161
|
+
status: _types.EarningStatus.EARNING_REWARD,
|
|
162
|
+
nominations: [],
|
|
163
|
+
unstakings
|
|
164
|
+
};
|
|
165
|
+
resultCallback(result);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
getTokenBalance();
|
|
170
|
+
const interval = setInterval(getTokenBalance, 30000);
|
|
171
|
+
return () => {
|
|
172
|
+
cancel = true;
|
|
173
|
+
clearInterval(interval);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* Subscribe pool position */
|
|
178
|
+
|
|
179
|
+
/* Join pool action */
|
|
180
|
+
|
|
181
|
+
get submitJoinStepInfo() {
|
|
182
|
+
return {
|
|
183
|
+
name: 'Mint stDOT',
|
|
184
|
+
type: _types.YieldStepType.MINT_STDOT
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
async getTokenApproveStep(params) {
|
|
188
|
+
const evmApi = this.evmApi;
|
|
189
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
190
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
191
|
+
const inputTokenSlug = this.inputAsset;
|
|
192
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
193
|
+
const inputTokenContract = (0, _web.getERC20Contract)(this.chain, (0, _utils._getContractAddressOfToken)(inputTokenInfo), this.state.getEvmApiMap());
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
195
|
+
const allowanceCall = inputTokenContract.methods.allowance(params.address, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo));
|
|
196
|
+
const [allowance, gasPrice] = await Promise.all([
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
198
|
+
await allowanceCall.call(), evmApi.api.eth.getGasPrice()]);
|
|
199
|
+
if (!allowance || parseInt(allowance) <= 0) {
|
|
200
|
+
const step = {
|
|
201
|
+
name: 'Authorize token approval',
|
|
202
|
+
type: _types.YieldStepType.TOKEN_APPROVAL
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
206
|
+
const estimatedGas = await allowanceCall.estimateGas();
|
|
207
|
+
const fee = {
|
|
208
|
+
slug: this.feeAssets[0],
|
|
209
|
+
amount: (estimatedGas * parseInt(gasPrice)).toString()
|
|
210
|
+
};
|
|
211
|
+
return [step, fee];
|
|
212
|
+
}
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
async getSubmitStepFee(params) {
|
|
216
|
+
const evmApi = this.evmApi;
|
|
217
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
218
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
219
|
+
if (new _util.BN(params.amount).gt(_util.BN_ZERO)) {
|
|
220
|
+
const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
|
|
221
|
+
|
|
222
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
223
|
+
const depositCall = stakingContract.methods.deposit(params.amount);
|
|
224
|
+
|
|
225
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
226
|
+
const estimatedDepositGas = await depositCall.estimateGas();
|
|
227
|
+
const gasPrice = await evmApi.api.eth.getGasPrice();
|
|
228
|
+
return {
|
|
229
|
+
slug: this.feeAssets[0],
|
|
230
|
+
amount: (estimatedDepositGas * parseInt(gasPrice)).toString()
|
|
231
|
+
};
|
|
232
|
+
} else {
|
|
233
|
+
return {
|
|
234
|
+
slug: this.feeAssets[0],
|
|
235
|
+
amount: '0'
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async generateOptimalPath(params) {
|
|
240
|
+
const result = {
|
|
241
|
+
totalFee: [{
|
|
242
|
+
slug: ''
|
|
243
|
+
}],
|
|
244
|
+
steps: [_constants.DEFAULT_YIELD_FIRST_STEP]
|
|
245
|
+
};
|
|
246
|
+
try {
|
|
247
|
+
/* Token approve step */
|
|
248
|
+
|
|
249
|
+
const approveStep = await this.getTokenApproveStep(params);
|
|
250
|
+
if (approveStep) {
|
|
251
|
+
const [step, fee] = approveStep;
|
|
252
|
+
result.steps.push({
|
|
253
|
+
id: result.steps.length,
|
|
254
|
+
...step
|
|
255
|
+
});
|
|
256
|
+
result.totalFee.push(fee);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/* Token approve step */
|
|
260
|
+
|
|
261
|
+
/* Submit step */
|
|
262
|
+
|
|
263
|
+
const submitFee = await this.getSubmitStepFee(params);
|
|
264
|
+
result.steps.push({
|
|
265
|
+
id: result.steps.length,
|
|
266
|
+
...this.submitJoinStepInfo
|
|
267
|
+
});
|
|
268
|
+
result.totalFee.push(submitFee);
|
|
269
|
+
|
|
270
|
+
/* Submit step */
|
|
271
|
+
|
|
272
|
+
return result;
|
|
273
|
+
} catch (e) {
|
|
274
|
+
const errorMessage = e.message;
|
|
275
|
+
if (errorMessage.includes('network')) {
|
|
276
|
+
result.connectionError = errorMessage.split(' ')[0];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/* Submit step */
|
|
280
|
+
|
|
281
|
+
result.steps.push({
|
|
282
|
+
id: result.steps.length,
|
|
283
|
+
...this.submitJoinStepInfo
|
|
284
|
+
});
|
|
285
|
+
result.totalFee.push({
|
|
286
|
+
slug: this.feeAssets[0],
|
|
287
|
+
amount: '0'
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
/* Submit step */
|
|
291
|
+
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
async validateTokenApproveStep(params, path) {
|
|
296
|
+
return Promise.resolve([]);
|
|
297
|
+
}
|
|
298
|
+
async handleTokenApproveStep(data, path) {
|
|
299
|
+
const {
|
|
300
|
+
address
|
|
301
|
+
} = data;
|
|
302
|
+
const inputTokenSlug = this.inputAsset;
|
|
303
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
304
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
|
|
305
|
+
const derivativeTokenContractAddress = (0, _utils._getContractAddressOfToken)(derivativeTokenInfo);
|
|
306
|
+
const inputTokenContract = (0, _web.getERC20Contract)(this.chain, (0, _utils._getContractAddressOfToken)(inputTokenInfo), this.state.getEvmApiMap());
|
|
307
|
+
|
|
308
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
309
|
+
const approveCall = inputTokenContract.methods.approve(derivativeTokenContractAddress, MAX_INT); // TODO: need test
|
|
310
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
311
|
+
const approveEncodedCall = approveCall.encodeABI();
|
|
312
|
+
const transactionObject = {
|
|
313
|
+
from: address,
|
|
314
|
+
to: (0, _utils._getContractAddressOfToken)(inputTokenInfo),
|
|
315
|
+
data: approveEncodedCall
|
|
316
|
+
};
|
|
317
|
+
return Promise.resolve({
|
|
318
|
+
txChain: this.chain,
|
|
319
|
+
extrinsicType: _KoniTypes.ExtrinsicType.EVM_EXECUTE,
|
|
320
|
+
extrinsic: transactionObject,
|
|
321
|
+
txData: transactionObject,
|
|
322
|
+
transferNativeAmount: '0'
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
327
|
+
async handleSubmitStep(data, path) {
|
|
328
|
+
const {
|
|
329
|
+
address,
|
|
330
|
+
amount
|
|
331
|
+
} = data;
|
|
332
|
+
const evmApi = this.evmApi;
|
|
333
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
334
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
335
|
+
const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
|
|
336
|
+
|
|
337
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
338
|
+
const depositCall = stakingContract.methods.deposit(amount, SUBWALLET_REFERRAL); // TODO: need test
|
|
339
|
+
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
341
|
+
const depositEncodedCall = depositCall.encodeABI();
|
|
342
|
+
const transactionObject = {
|
|
343
|
+
from: address,
|
|
344
|
+
to: (0, _utils._getContractAddressOfToken)(derivativeTokenInfo),
|
|
345
|
+
data: depositEncodedCall
|
|
346
|
+
};
|
|
347
|
+
return {
|
|
348
|
+
txChain: this.chain,
|
|
349
|
+
extrinsicType: _KoniTypes.ExtrinsicType.MINT_STDOT,
|
|
350
|
+
extrinsic: transactionObject,
|
|
351
|
+
txData: data,
|
|
352
|
+
transferNativeAmount: '0'
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/* Join pool action */
|
|
357
|
+
|
|
358
|
+
/* Leave pool action */
|
|
359
|
+
|
|
360
|
+
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
361
|
+
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
365
|
+
async handleYieldUnstake(amount, address, selectedTarget) {
|
|
366
|
+
const evmApi = this.evmApi;
|
|
367
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
368
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
369
|
+
const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
|
|
370
|
+
|
|
371
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
372
|
+
const redeemCall = stakingContract.methods.redeem(amount);
|
|
373
|
+
|
|
374
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
375
|
+
const redeemEncodedCall = redeemCall.encodeABI();
|
|
376
|
+
const transaction = {
|
|
377
|
+
from: address,
|
|
378
|
+
to: (0, _utils._getContractAddressOfToken)(derivativeTokenInfo),
|
|
379
|
+
data: redeemEncodedCall
|
|
380
|
+
};
|
|
381
|
+
return [_KoniTypes.ExtrinsicType.STAKING_UNBOND, transaction];
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/* Leave pool action */
|
|
385
|
+
|
|
386
|
+
/* Other actions */
|
|
387
|
+
|
|
388
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
389
|
+
async handleYieldWithdraw(address, unstakingInfo) {
|
|
390
|
+
const evmApi = this.evmApi;
|
|
391
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
392
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
393
|
+
const stakingContract = getStellaswapLiquidStakingContract(this.chain, (0, _utils._getContractAddressOfToken)(derivativeTokenInfo), evmApi);
|
|
394
|
+
|
|
395
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
396
|
+
const withdrawCall = stakingContract.methods.claimUnbonded();
|
|
397
|
+
|
|
398
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
399
|
+
const withdrawEncodedCall = withdrawCall.encodeABI();
|
|
400
|
+
return {
|
|
401
|
+
from: address,
|
|
402
|
+
to: (0, _utils._getContractAddressOfToken)(derivativeTokenInfo),
|
|
403
|
+
data: withdrawEncodedCall
|
|
404
|
+
}; // TODO: check tx history parsing
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/* Other actions */
|
|
408
|
+
}
|
|
409
|
+
exports.default = StellaSwapLiquidStakingPoolHandler;
|