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