@subwallet/extension-base 1.1.34-0 → 1.1.35-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +111 -69
- package/background/KoniTypes.js +19 -13
- package/background/errors/TransactionError.js +9 -0
- package/cjs/background/KoniTypes.js +20 -16
- package/cjs/background/errors/TransactionError.js +9 -0
- package/cjs/constants/index.js +19 -4
- package/cjs/constants/staking.js +1 -1
- package/cjs/koni/api/dotsama/balance.js +464 -0
- package/cjs/koni/api/nft/config.js +33 -23
- package/cjs/koni/api/nft/index.js +14 -0
- package/cjs/koni/api/nft/nft.js +1 -22
- package/cjs/koni/api/nft/ordinal_nft/constants.js +21 -0
- package/cjs/koni/api/nft/ordinal_nft/index.js +121 -0
- package/cjs/koni/api/nft/ordinal_nft/utils.js +41 -0
- package/cjs/koni/api/staking/bonding/amplitude.js +19 -16
- package/cjs/koni/api/staking/bonding/astar.js +11 -10
- package/cjs/koni/api/staking/bonding/index.js +4 -1
- package/cjs/koni/api/staking/bonding/paraChain.js +25 -23
- package/cjs/koni/api/staking/bonding/relayChain.js +48 -45
- package/cjs/koni/api/staking/bonding/utils.js +104 -86
- package/cjs/koni/api/staking/index.js +6 -5
- package/cjs/koni/api/staking/paraChain.js +6 -5
- package/cjs/koni/api/staking/relayChain.js +3 -2
- package/cjs/koni/api/yield/helper/utils.js +46 -0
- package/cjs/koni/background/cron.js +3 -21
- package/cjs/koni/background/handlers/Extension.js +368 -69
- package/cjs/koni/background/handlers/State.js +18 -12
- package/cjs/koni/background/handlers/index.js +4 -2
- package/cjs/koni/background/subscription.js +7 -104
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/campaign-service/index.js +9 -6
- package/cjs/services/chain-service/constants.js +2 -17
- package/cjs/services/chain-service/index.js +50 -3
- package/cjs/services/chain-service/utils.js +7 -1
- package/cjs/services/earning-service/constants/chains.js +30 -0
- package/cjs/services/earning-service/constants/index.js +27 -0
- package/cjs/services/earning-service/constants/step.js +18 -0
- package/cjs/services/earning-service/handlers/base.js +262 -0
- package/cjs/services/earning-service/handlers/index.js +60 -0
- package/cjs/services/earning-service/handlers/lending/base.js +81 -0
- package/cjs/services/earning-service/handlers/lending/index.js +13 -0
- package/cjs/services/earning-service/handlers/lending/interlay.js +192 -0
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +240 -0
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +97 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +140 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +298 -0
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +227 -0
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +404 -0
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +434 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +466 -0
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +146 -0
- package/cjs/services/earning-service/handlers/native-staking/base.js +161 -0
- package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +390 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +567 -0
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +566 -0
- package/cjs/services/earning-service/handlers/special.js +493 -0
- package/cjs/services/earning-service/service.js +733 -0
- package/cjs/services/earning-service/utils/index.js +128 -0
- package/cjs/services/event-service/index.js +5 -0
- package/cjs/services/keyring-service/index.js +14 -2
- package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
- package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
- package/cjs/services/migration-service/scripts/MigrateEthProvider.js +17 -0
- package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +17 -0
- package/cjs/services/migration-service/scripts/MigrateProvider.js +29 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +21 -0
- package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +21 -0
- package/cjs/services/migration-service/scripts/index.js +6 -1
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
- package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
- package/cjs/services/mint-campaign-service/constants.js +11 -0
- package/cjs/services/mint-campaign-service/index.js +18 -0
- package/cjs/services/notification-service/NotificationService.js +3 -2
- package/cjs/services/request-service/handler/PopupHandler.js +2 -3
- package/cjs/services/storage-service/DatabaseService.js +97 -0
- package/cjs/services/storage-service/databases/index.js +4 -0
- package/cjs/services/storage-service/db-stores/AssetRef.js +24 -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 +71 -0
- package/cjs/services/storage-service/index.js +241 -0
- package/cjs/services/subscan-service/index.js +16 -0
- package/cjs/services/transaction-service/event-parser/index.js +58 -0
- package/cjs/services/transaction-service/helpers/index.js +3 -1
- package/cjs/services/transaction-service/index.js +249 -75
- package/cjs/services/transaction-service/utils.js +1 -0
- package/cjs/types/campaigns/index.js +16 -0
- package/cjs/types/campaigns/unlock-dot.js +1 -0
- package/cjs/types/index.js +44 -0
- package/cjs/types/ordinal.js +1 -0
- package/cjs/types/transaction.js +1 -0
- package/cjs/types/yield/actions/index.js +27 -0
- package/cjs/types/yield/actions/join/index.js +38 -0
- package/cjs/types/yield/actions/join/step.js +47 -0
- package/cjs/types/yield/actions/join/submit.js +1 -0
- package/cjs/types/yield/actions/join/validate.js +16 -0
- package/cjs/types/yield/actions/others.js +1 -0
- package/cjs/types/yield/index.js +27 -0
- package/cjs/types/yield/info/account/index.js +49 -0
- package/cjs/types/yield/info/account/info.js +1 -0
- package/cjs/types/yield/info/account/reward.js +1 -0
- package/cjs/types/yield/info/account/target.js +32 -0
- package/cjs/types/yield/info/account/unstake.js +27 -0
- package/cjs/types/yield/info/base.js +41 -0
- package/cjs/types/yield/info/chain/index.js +27 -0
- package/cjs/types/yield/info/chain/info.js +1 -0
- package/cjs/types/yield/info/chain/target.js +1 -0
- package/cjs/types/yield/info/index.js +49 -0
- package/cjs/types/yield/info/pallet.js +15 -0
- package/cjs/types.js +1 -0
- package/cjs/utils/address.js +34 -0
- package/cjs/utils/environment.js +23 -28
- package/cjs/utils/fetchStaticCache.js +22 -0
- package/cjs/utils/fetchStaticData.js +2 -1
- package/cjs/utils/index.js +94 -10
- package/cjs/utils/keyring.js +57 -0
- package/cjs/utils/mv3.js +14 -0
- package/cjs/utils/number.js +6 -2
- package/cjs/utils/object.js +12 -0
- package/constants/index.d.ts +6 -1
- package/constants/index.js +6 -1
- package/constants/staking.js +1 -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 +13 -10
- package/koni/api/staking/bonding/astar.js +9 -8
- package/koni/api/staking/bonding/index.d.ts +1 -1
- package/koni/api/staking/bonding/index.js +5 -1
- package/koni/api/staking/bonding/paraChain.js +12 -10
- package/koni/api/staking/bonding/relayChain.d.ts +2 -2
- package/koni/api/staking/bonding/relayChain.js +33 -30
- package/koni/api/staking/bonding/utils.d.ts +15 -38
- package/koni/api/staking/bonding/utils.js +85 -69
- package/koni/api/staking/index.js +2 -1
- package/koni/api/staking/paraChain.js +7 -6
- package/koni/api/staking/relayChain.js +4 -3
- package/koni/api/yield/helper/utils.d.ts +10 -0
- package/koni/api/yield/helper/utils.js +32 -0
- package/koni/background/cron.d.ts +0 -4
- package/koni/background/cron.js +4 -22
- package/koni/background/handlers/Extension.d.ts +17 -1
- package/koni/background/handlers/Extension.js +327 -30
- package/koni/background/handlers/State.d.ts +6 -1
- package/koni/background/handlers/State.js +17 -12
- package/koni/background/handlers/index.js +4 -2
- package/koni/background/subscription.d.ts +1 -6
- package/koni/background/subscription.js +8 -104
- package/package.json +335 -7
- package/packageInfo.js +1 -1
- package/services/campaign-service/index.js +9 -6
- package/services/chain-service/constants.d.ts +1 -13
- package/services/chain-service/constants.js +1 -15
- package/services/chain-service/index.d.ts +3 -0
- package/services/chain-service/index.js +50 -3
- 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 +15 -0
- package/services/earning-service/constants/chains.js +22 -0
- package/services/earning-service/constants/index.d.ts +2 -0
- package/services/earning-service/constants/index.js +5 -0
- package/services/earning-service/constants/step.d.ts +3 -0
- package/services/earning-service/constants/step.js +10 -0
- package/services/earning-service/handlers/base.d.ts +113 -0
- package/services/earning-service/handlers/base.js +256 -0
- package/services/earning-service/handlers/index.d.ts +5 -0
- package/services/earning-service/handlers/index.js +8 -0
- package/services/earning-service/handlers/lending/base.d.ts +8 -0
- package/services/earning-service/handlers/lending/base.js +73 -0
- package/services/earning-service/handlers/lending/index.d.ts +1 -0
- package/services/earning-service/handlers/lending/index.js +4 -0
- package/services/earning-service/handlers/lending/interlay.d.ts +24 -0
- package/services/earning-service/handlers/lending/interlay.js +184 -0
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +232 -0
- package/services/earning-service/handlers/liquid-staking/base.d.ts +11 -0
- package/services/earning-service/handlers/liquid-staking/base.js +89 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +46 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.js +287 -0
- package/services/earning-service/handlers/liquid-staking/index.d.ts +4 -0
- package/services/earning-service/handlers/liquid-staking/index.js +7 -0
- package/services/earning-service/handlers/liquid-staking/parallel.d.ts +26 -0
- package/services/earning-service/handlers/liquid-staking/parallel.js +219 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +34 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +394 -0
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +425 -0
- package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
- package/services/earning-service/handlers/native-staking/astar.js +456 -0
- package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
- package/services/earning-service/handlers/native-staking/base-para.js +138 -0
- package/services/earning-service/handlers/native-staking/base.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/base.js +152 -0
- package/services/earning-service/handlers/native-staking/index.d.ts +4 -0
- package/services/earning-service/handlers/native-staking/index.js +7 -0
- package/services/earning-service/handlers/native-staking/para-chain.d.ts +15 -0
- package/services/earning-service/handlers/native-staking/para-chain.js +382 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +558 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +36 -0
- package/services/earning-service/handlers/nomination-pool/index.js +556 -0
- package/services/earning-service/handlers/special.d.ts +64 -0
- package/services/earning-service/handlers/special.js +485 -0
- package/services/earning-service/service.d.ts +94 -0
- package/services/earning-service/service.js +722 -0
- package/services/earning-service/utils/index.d.ts +18 -0
- package/services/earning-service/utils/index.js +112 -0
- package/services/event-service/index.d.ts +2 -0
- package/services/event-service/index.js +5 -0
- package/services/event-service/types.d.ts +9 -0
- package/services/keyring-service/index.d.ts +2 -1
- package/services/keyring-service/index.js +14 -2
- package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
- package/services/migration-service/scripts/DeleteEarningData.js +13 -0
- package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
- package/services/migration-service/scripts/EnableEarningChains.js +13 -0
- package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningHistory.js +13 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.js +13 -0
- package/services/migration-service/scripts/index.js +6 -1
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
- package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
- package/services/mint-campaign-service/campaigns/index.js +4 -0
- package/services/mint-campaign-service/constants.d.ts +1 -0
- package/services/mint-campaign-service/constants.js +4 -0
- package/services/mint-campaign-service/index.d.ts +7 -0
- package/services/mint-campaign-service/index.js +11 -0
- package/services/notification-service/NotificationService.js +3 -2
- package/services/request-service/handler/PopupHandler.js +3 -4
- package/services/storage-service/DatabaseService.d.ts +22 -1
- package/services/storage-service/DatabaseService.js +97 -0
- package/services/storage-service/databases/index.d.ts +7 -2
- package/services/storage-service/databases/index.js +4 -0
- package/services/storage-service/db-stores/AssetRef.d.ts +7 -0
- package/services/storage-service/db-stores/AssetRef.js +16 -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 +11 -0
- package/services/storage-service/db-stores/YieldPositionStore.js +63 -0
- package/services/subscan-service/index.d.ts +3 -2
- package/services/subscan-service/index.js +15 -0
- package/services/subscan-service/types.d.ts +20 -0
- package/services/transaction-service/event-parser/index.d.ts +3 -1
- package/services/transaction-service/event-parser/index.js +57 -1
- package/services/transaction-service/helpers/index.js +3 -1
- package/services/transaction-service/index.d.ts +6 -13
- package/services/transaction-service/index.js +247 -73
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.js +1 -0
- package/types/campaigns/index.d.ts +1 -0
- package/types/campaigns/index.js +4 -0
- package/types/campaigns/unlock-dot.d.ts +71 -0
- package/types/campaigns/unlock-dot.js +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.js +5 -1
- package/types/ordinal.d.ts +69 -0
- package/types/ordinal.js +1 -0
- package/types/transaction.d.ts +3 -0
- package/types/transaction.js +1 -0
- package/types/yield/actions/index.d.ts +2 -0
- package/types/yield/actions/index.js +5 -0
- package/types/yield/actions/join/index.d.ts +3 -0
- package/types/yield/actions/join/index.js +6 -0
- package/types/yield/actions/join/step.d.ts +95 -0
- package/types/yield/actions/join/step.js +46 -0
- package/types/yield/actions/join/submit.d.ts +58 -0
- package/types/yield/actions/join/submit.js +1 -0
- package/types/yield/actions/join/validate.d.ts +18 -0
- package/types/yield/actions/join/validate.js +10 -0
- package/types/yield/actions/others.d.ts +85 -0
- package/types/yield/actions/others.js +1 -0
- package/types/yield/index.d.ts +2 -0
- package/types/yield/index.js +5 -0
- package/types/yield/info/account/index.d.ts +4 -0
- package/types/yield/info/account/index.js +7 -0
- package/types/yield/info/account/info.d.ts +92 -0
- package/types/yield/info/account/info.js +1 -0
- package/types/yield/info/account/reward.d.ts +47 -0
- package/types/yield/info/account/reward.js +1 -0
- package/types/yield/info/account/target.d.ts +43 -0
- package/types/yield/info/account/target.js +27 -0
- package/types/yield/info/account/unstake.d.ts +31 -0
- package/types/yield/info/account/unstake.js +22 -0
- package/types/yield/info/base.d.ts +45 -0
- package/types/yield/info/base.js +36 -0
- package/types/yield/info/chain/index.d.ts +2 -0
- package/types/yield/info/chain/index.js +5 -0
- package/types/yield/info/chain/info.d.ts +252 -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/environment.d.ts +9 -2
- package/utils/environment.js +14 -26
- package/utils/fetchStaticCache.d.ts +1 -0
- package/utils/fetchStaticCache.js +14 -0
- package/utils/fetchStaticData.js +2 -1
- package/utils/index.d.ts +5 -1
- package/utils/index.js +53 -3
- package/utils/mv3.d.ts +2 -0
- package/utils/mv3.js +6 -0
- package/utils/number.d.ts +2 -1
- package/utils/number.js +2 -1
- package/utils/object.d.ts +1 -0
- package/utils/object.js +6 -0
|
@@ -0,0 +1,404 @@
|
|
|
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;
|