@subwallet/extension-base 1.1.35-0 → 1.1.35-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 +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/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/services/campaign-service/index.js +9 -6
- package/cjs/services/chain-service/constants.js +1 -16
- package/cjs/services/chain-service/index.js +6 -2
- 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 +63 -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 +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 +21 -0
- package/cjs/utils/number.js +6 -2
- package/cjs/utils/object.js +12 -0
- package/constants/index.d.ts +6 -1
- package/constants/index.js +6 -1
- package/koni/api/nft/config.js +33 -23
- package/koni/api/nft/index.js +15 -1
- package/koni/api/nft/nft.js +2 -23
- package/koni/api/nft/ordinal_nft/constants.d.ts +9 -0
- package/koni/api/nft/ordinal_nft/constants.js +12 -0
- package/koni/api/nft/ordinal_nft/index.d.ts +8 -0
- package/koni/api/nft/ordinal_nft/index.js +114 -0
- package/koni/api/nft/ordinal_nft/utils.d.ts +2 -0
- package/koni/api/nft/ordinal_nft/utils.js +33 -0
- package/koni/api/staking/bonding/amplitude.js +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 +326 -3
- package/services/campaign-service/index.js +9 -6
- package/services/chain-service/constants.d.ts +0 -12
- package/services/chain-service/constants.js +0 -14
- package/services/chain-service/index.js +6 -2
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +5 -1
- package/services/earning-service/constants/abis/compound_finance_v2_abi.json +1235 -0
- package/services/earning-service/constants/abis/st_liquid_token_abi.json +1355 -0
- package/services/earning-service/constants/chains.d.ts +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 +63 -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 +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 +13 -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,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
8
|
+
var _constants = require("@subwallet/extension-base/constants");
|
|
9
|
+
var _constants2 = require("@subwallet/extension-base/services/earning-service/constants");
|
|
10
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
11
|
+
var _util = require("@polkadot/util");
|
|
12
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
13
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @class BasePoolHandler
|
|
17
|
+
* @description Base pool handler
|
|
18
|
+
* */
|
|
19
|
+
class BasePoolHandler {
|
|
20
|
+
/** Koni state */
|
|
21
|
+
|
|
22
|
+
/** Pool's chain */
|
|
23
|
+
|
|
24
|
+
/** Pool's logo */
|
|
25
|
+
|
|
26
|
+
/** Pool's slug */
|
|
27
|
+
|
|
28
|
+
/** Pool's type */
|
|
29
|
+
|
|
30
|
+
/** Pool's name */
|
|
31
|
+
|
|
32
|
+
/** Pool's short name */
|
|
33
|
+
|
|
34
|
+
/** Pool's transaction type */
|
|
35
|
+
transactionChainType = _KoniTypes.ChainType.SUBSTRATE;
|
|
36
|
+
|
|
37
|
+
/** Pool's available method */
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @constructor
|
|
41
|
+
* @param {KoniState} state - Koni state
|
|
42
|
+
* @param {string} chain - Pool's chain
|
|
43
|
+
* */
|
|
44
|
+
constructor(state, chain) {
|
|
45
|
+
this.state = state;
|
|
46
|
+
this.chain = chain;
|
|
47
|
+
this._logo = chain;
|
|
48
|
+
}
|
|
49
|
+
get logo() {
|
|
50
|
+
return this._logo;
|
|
51
|
+
}
|
|
52
|
+
get group() {
|
|
53
|
+
const groupSlug = this.nativeToken.multiChainAsset;
|
|
54
|
+
return groupSlug || this.nativeToken.slug;
|
|
55
|
+
}
|
|
56
|
+
get isActive() {
|
|
57
|
+
return this.state.activeChainSlugs.includes(this.chain);
|
|
58
|
+
}
|
|
59
|
+
get substrateApi() {
|
|
60
|
+
return this.state.getSubstrateApi(this.chain);
|
|
61
|
+
}
|
|
62
|
+
get evmApi() {
|
|
63
|
+
return this.state.getEvmApi(this.chain);
|
|
64
|
+
}
|
|
65
|
+
get chainInfo() {
|
|
66
|
+
return this.state.getChainInfo(this.chain);
|
|
67
|
+
}
|
|
68
|
+
get nativeToken() {
|
|
69
|
+
return this.state.getNativeTokenInfo(this.chain);
|
|
70
|
+
}
|
|
71
|
+
get baseInfo() {
|
|
72
|
+
return {
|
|
73
|
+
group: this.group,
|
|
74
|
+
chain: this.chain,
|
|
75
|
+
slug: this.slug
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
getAssetBySlug(slug) {
|
|
79
|
+
return this.state.getAssetBySlug(slug);
|
|
80
|
+
}
|
|
81
|
+
get maintainBalance() {
|
|
82
|
+
const decimals = this.nativeToken.decimals || 0;
|
|
83
|
+
const defaultMaintainBalance = new _util.BN(1).mul(_util.BN_TEN.pow(new _util.BN(decimals)));
|
|
84
|
+
const ed = new _util.BN(this.nativeToken.minAmount || '0');
|
|
85
|
+
const maintainBalance = ed.gte(defaultMaintainBalance) ? new _util.BN(15).mul(ed).div(_util.BN_TEN) : defaultMaintainBalance;
|
|
86
|
+
return maintainBalance.toString();
|
|
87
|
+
}
|
|
88
|
+
get metadataInfo() {
|
|
89
|
+
return {
|
|
90
|
+
name: this.name,
|
|
91
|
+
shortName: this.shortName,
|
|
92
|
+
logo: this.logo,
|
|
93
|
+
inputAsset: this.nativeToken.slug,
|
|
94
|
+
isAvailable: true,
|
|
95
|
+
maintainAsset: this.nativeToken.slug,
|
|
96
|
+
maintainBalance: this.maintainBalance,
|
|
97
|
+
availableMethod: this.availableMethod
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Can mint when haven't enough native token (use input token for fee) */
|
|
102
|
+
get isPoolSupportAlternativeFee() {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
async getPoolInfo() {
|
|
106
|
+
return await this.state.earningService.getYieldPool(this.slug);
|
|
107
|
+
}
|
|
108
|
+
async getPoolPosition(address) {
|
|
109
|
+
return await this.state.earningService.getYieldPosition(address, this.slug);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/* Subscribe data */
|
|
113
|
+
|
|
114
|
+
/** Subscribe pool info */
|
|
115
|
+
|
|
116
|
+
/* Subscribe data */
|
|
117
|
+
|
|
118
|
+
/* Join action */
|
|
119
|
+
|
|
120
|
+
/* Early validate */
|
|
121
|
+
|
|
122
|
+
async earlyValidate(request) {
|
|
123
|
+
var _poolInfo$statistic, _poolInfo$statistic2, _poolInfo$statistic2$;
|
|
124
|
+
const poolInfo = await this.getPoolInfo();
|
|
125
|
+
if (!poolInfo || !((_poolInfo$statistic = poolInfo.statistic) !== null && _poolInfo$statistic !== void 0 && _poolInfo$statistic.earningThreshold.join)) {
|
|
126
|
+
return {
|
|
127
|
+
passed: false,
|
|
128
|
+
errorMessage: 'There is a problem fetching your data. Check your Internet connection or change the network endpoint and try again.'
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (request.address === _constants.ALL_ACCOUNT_KEY) {
|
|
132
|
+
return {
|
|
133
|
+
passed: true
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(this.chain);
|
|
137
|
+
const nativeTokenBalance = await this.state.balanceService.getTokenFreeBalance(request.address, this.chain);
|
|
138
|
+
const bnNativeTokenBalance = new _util.BN(nativeTokenBalance.value);
|
|
139
|
+
const bnMinBalanceToJoin = new _util.BN(((_poolInfo$statistic2 = poolInfo.statistic) === null || _poolInfo$statistic2 === void 0 ? void 0 : (_poolInfo$statistic2$ = _poolInfo$statistic2.earningThreshold) === null || _poolInfo$statistic2$ === void 0 ? void 0 : _poolInfo$statistic2$.join) || '0').add(new _util.BN(poolInfo.metadata.maintainBalance));
|
|
140
|
+
if (bnNativeTokenBalance.lte(bnMinBalanceToJoin)) {
|
|
141
|
+
const minJoin = (0, _utils.formatNumber)(bnMinBalanceToJoin.toString(), this.nativeToken.decimals || 0);
|
|
142
|
+
const originChain = this.state.getChainInfo(nativeTokenInfo.originChain);
|
|
143
|
+
return {
|
|
144
|
+
passed: false,
|
|
145
|
+
errorMessage: `You need at least ${minJoin} ${nativeTokenInfo.symbol} (${originChain.name}) to start earning`
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
passed: true
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* Early validate */
|
|
154
|
+
|
|
155
|
+
/* Generate steps */
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @function firstStepFee
|
|
159
|
+
* */
|
|
160
|
+
get firstStepFee() {
|
|
161
|
+
return {
|
|
162
|
+
slug: ''
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @function defaultSubmitStep
|
|
168
|
+
* @description Default submit step data
|
|
169
|
+
* */
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @async
|
|
173
|
+
* @function getTokenApproveStep
|
|
174
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
175
|
+
* @description Generate token approve step data
|
|
176
|
+
* */
|
|
177
|
+
async getTokenApproveStep(params) {
|
|
178
|
+
return Promise.resolve(undefined);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @async
|
|
183
|
+
* @function getXcmStep
|
|
184
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
185
|
+
* @description Generate token approve step data
|
|
186
|
+
* */
|
|
187
|
+
async getXcmStep(params) {
|
|
188
|
+
return Promise.resolve(undefined);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @async
|
|
193
|
+
* @function getSubmitStep
|
|
194
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
195
|
+
* @description Generate token approve step data
|
|
196
|
+
* */
|
|
197
|
+
|
|
198
|
+
/** Generate the optimal steps to join pool */
|
|
199
|
+
async generateOptimalPath(params) {
|
|
200
|
+
const result = {
|
|
201
|
+
totalFee: [this.firstStepFee],
|
|
202
|
+
steps: [_constants2.DEFAULT_YIELD_FIRST_STEP]
|
|
203
|
+
};
|
|
204
|
+
try {
|
|
205
|
+
const stepFunctions = [this.getTokenApproveStep, this.getXcmStep, this.getSubmitStep];
|
|
206
|
+
for (const stepFunction of stepFunctions) {
|
|
207
|
+
const step = await stepFunction.bind(this, params)();
|
|
208
|
+
if (step) {
|
|
209
|
+
const [info, fee] = step;
|
|
210
|
+
result.steps.push({
|
|
211
|
+
id: result.steps.length,
|
|
212
|
+
...info
|
|
213
|
+
});
|
|
214
|
+
result.totalFee.push(fee);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
} catch (e) {
|
|
219
|
+
const errorMessage = e.message;
|
|
220
|
+
if (errorMessage.includes('network')) {
|
|
221
|
+
result.connectionError = errorMessage.split(' ')[0];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* Submit step */
|
|
225
|
+
|
|
226
|
+
const [step, fee] = this.defaultSubmitStep;
|
|
227
|
+
result.steps.push({
|
|
228
|
+
id: result.steps.length,
|
|
229
|
+
...step
|
|
230
|
+
});
|
|
231
|
+
result.totalFee.push(fee);
|
|
232
|
+
|
|
233
|
+
/* Submit step */
|
|
234
|
+
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/* Generate steps */
|
|
240
|
+
|
|
241
|
+
/* Validate */
|
|
242
|
+
|
|
243
|
+
/** Validate param to join the pool */
|
|
244
|
+
|
|
245
|
+
/** Create `transaction` to leave the pool */
|
|
246
|
+
async handleYieldLeave(fastLeave, amount, address, selectedTarget) {
|
|
247
|
+
if (fastLeave) {
|
|
248
|
+
return this.handleYieldRedeem(amount, address, selectedTarget);
|
|
249
|
+
} else {
|
|
250
|
+
return this.handleYieldUnstake(amount, address, selectedTarget);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/* Leave action */
|
|
255
|
+
|
|
256
|
+
/* Other actions */
|
|
257
|
+
|
|
258
|
+
/** Create `transaction` to withdraw unstaked amount */
|
|
259
|
+
|
|
260
|
+
/* Other actions */
|
|
261
|
+
}
|
|
262
|
+
exports.default = BasePoolHandler;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
var _exportNames = {
|
|
8
|
+
BasePoolHandler: true,
|
|
9
|
+
NominationPoolHandler: true
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "BasePoolHandler", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return _base.default;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "NominationPoolHandler", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () {
|
|
20
|
+
return _nominationPool.default;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
24
|
+
var _nominationPool = _interopRequireDefault(require("./nomination-pool"));
|
|
25
|
+
var _lending = require("./lending");
|
|
26
|
+
Object.keys(_lending).forEach(function (key) {
|
|
27
|
+
if (key === "default" || key === "__esModule") return;
|
|
28
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
29
|
+
if (key in exports && exports[key] === _lending[key]) return;
|
|
30
|
+
Object.defineProperty(exports, key, {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _lending[key];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
var _liquidStaking = require("./liquid-staking");
|
|
38
|
+
Object.keys(_liquidStaking).forEach(function (key) {
|
|
39
|
+
if (key === "default" || key === "__esModule") return;
|
|
40
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
41
|
+
if (key in exports && exports[key] === _liquidStaking[key]) return;
|
|
42
|
+
Object.defineProperty(exports, key, {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _liquidStaking[key];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
var _nativeStaking = require("./native-staking");
|
|
50
|
+
Object.keys(_nativeStaking).forEach(function (key) {
|
|
51
|
+
if (key === "default" || key === "__esModule") return;
|
|
52
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
53
|
+
if (key in exports && exports[key] === _nativeStaking[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _nativeStaking[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
9
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
|
+
var _types = require("@subwallet/extension-base/types");
|
|
11
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
12
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
13
|
+
var _i18next = require("i18next");
|
|
14
|
+
var _special = _interopRequireDefault(require("../special"));
|
|
15
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
|
|
18
|
+
class BaseLendingPoolHandler extends _special.default {
|
|
19
|
+
type = _types.YieldPoolType.LENDING;
|
|
20
|
+
|
|
21
|
+
/* Subscribe pool info */
|
|
22
|
+
|
|
23
|
+
/* Subscribe pool info */
|
|
24
|
+
|
|
25
|
+
/* Leave pool action */
|
|
26
|
+
|
|
27
|
+
async validateYieldLeave(amount, address, fastLeave, selectedTarget) {
|
|
28
|
+
const poolInfo = await this.getPoolInfo();
|
|
29
|
+
const poolPosition = await this.getPoolPosition(address);
|
|
30
|
+
if (!poolInfo || !poolInfo.statistic || !poolPosition) {
|
|
31
|
+
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
|
|
32
|
+
}
|
|
33
|
+
if (!this.availableMethod.defaultUnstake && !fastLeave) {
|
|
34
|
+
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
|
|
35
|
+
}
|
|
36
|
+
if (!this.availableMethod.fastUnstake && fastLeave) {
|
|
37
|
+
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)];
|
|
38
|
+
}
|
|
39
|
+
const errors = [];
|
|
40
|
+
const bnActiveStake = new _bignumber.default(poolPosition.activeStake).multipliedBy(poolInfo.statistic.assetEarning[0].exchangeRate || 1);
|
|
41
|
+
const bnAmount = new _bignumber.default(amount);
|
|
42
|
+
const bnRemainingStake = bnActiveStake.minus(bnAmount);
|
|
43
|
+
const minStake = new _bignumber.default(poolInfo.statistic.earningThreshold.join || '0');
|
|
44
|
+
const minUnstake = new _bignumber.default((fastLeave ? poolInfo.statistic.earningThreshold.fastUnstake : poolInfo.statistic.earningThreshold.defaultUnstake) || '0');
|
|
45
|
+
const maxUnstakeRequest = poolInfo.statistic.maxWithdrawalRequestPerFarmer;
|
|
46
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
|
|
47
|
+
if (bnAmount.lte(_utils.BN_ZERO)) {
|
|
48
|
+
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INVALID_PARAMS, (0, _i18next.t)('Amount must be greater than 0'))];
|
|
49
|
+
}
|
|
50
|
+
if (bnAmount.lt(minUnstake)) {
|
|
51
|
+
const minUnstakeStr = (0, _utils.formatNumber)(minUnstake.toString(), derivativeTokenInfo.decimals || 0);
|
|
52
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_UNSTAKE, (0, _i18next.t)('You need to unstake at least {{amount}} {{token}}', {
|
|
53
|
+
replace: {
|
|
54
|
+
amount: minUnstakeStr,
|
|
55
|
+
token: derivativeTokenInfo.symbol
|
|
56
|
+
}
|
|
57
|
+
})));
|
|
58
|
+
}
|
|
59
|
+
if (!fastLeave) {
|
|
60
|
+
if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
|
|
61
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE)); // TODO
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (poolPosition.unstakings.length > maxUnstakeRequest) {
|
|
65
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_UNSTAKING, (0, _i18next.t)('You cannot unstake more than {{number}} times', {
|
|
66
|
+
replace: {
|
|
67
|
+
number: maxUnstakeRequest
|
|
68
|
+
}
|
|
69
|
+
})));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (bnRemainingStake.lt(0)) {
|
|
73
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE)); // TODO
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return Promise.resolve(errors);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Leave pool action */
|
|
80
|
+
}
|
|
81
|
+
exports.default = BaseLendingPoolHandler;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "InterlayLendingPoolHandler", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _interlay.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _interlay = _interopRequireDefault(require("./interlay"));
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
9
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
|
+
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
11
|
+
var _types = require("@subwallet/extension-base/types");
|
|
12
|
+
var _util = require("@polkadot/util");
|
|
13
|
+
var _constants = require("../../constants");
|
|
14
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
15
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
|
|
18
|
+
class InterlayLendingPoolHandler extends _base.default {
|
|
19
|
+
altInputAsset = 'polkadot-NATIVE-DOT';
|
|
20
|
+
derivativeAssets = ['interlay-LOCAL-qDOT'];
|
|
21
|
+
inputAsset = 'interlay-LOCAL-DOT';
|
|
22
|
+
rewardAssets = ['interlay-LOCAL-DOT'];
|
|
23
|
+
feeAssets = ['interlay-NATIVE-INTR', 'interlay-LOCAL-DOT'];
|
|
24
|
+
availableMethod = {
|
|
25
|
+
join: true,
|
|
26
|
+
defaultUnstake: false,
|
|
27
|
+
fastUnstake: true,
|
|
28
|
+
cancelUnstake: false,
|
|
29
|
+
withdraw: false,
|
|
30
|
+
claimReward: false
|
|
31
|
+
};
|
|
32
|
+
rateDecimals = 18;
|
|
33
|
+
constructor(state, chain) {
|
|
34
|
+
super(state, chain);
|
|
35
|
+
const chainInfo = this.chainInfo;
|
|
36
|
+
this.slug = `DOT___lending___${chain}`;
|
|
37
|
+
this.name = `${chainInfo.name} Lending`;
|
|
38
|
+
this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
|
|
39
|
+
}
|
|
40
|
+
getDescription() {
|
|
41
|
+
return 'Earn rewards by lending DOT';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* Subscribe pool info */
|
|
45
|
+
|
|
46
|
+
async getPoolStat() {
|
|
47
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
48
|
+
const inputTokenSlug = this.inputAsset;
|
|
49
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
50
|
+
const _exchangeRate = await substrateApi.api.query.loans.exchangeRate((0, _utils._getTokenOnChainInfo)(inputTokenInfo));
|
|
51
|
+
const exchangeRate = _exchangeRate.toPrimitive();
|
|
52
|
+
const decimals = 10 ** this.rateDecimals;
|
|
53
|
+
this.updateExchangeRate(exchangeRate);
|
|
54
|
+
return {
|
|
55
|
+
...this.baseInfo,
|
|
56
|
+
type: this.type,
|
|
57
|
+
metadata: {
|
|
58
|
+
...this.metadataInfo,
|
|
59
|
+
description: this.getDescription()
|
|
60
|
+
},
|
|
61
|
+
statistic: {
|
|
62
|
+
assetEarning: [{
|
|
63
|
+
slug: this.rewardAssets[0],
|
|
64
|
+
apr: 1.29,
|
|
65
|
+
exchangeRate: exchangeRate / decimals
|
|
66
|
+
}],
|
|
67
|
+
maxCandidatePerFarmer: 1,
|
|
68
|
+
maxWithdrawalRequestPerFarmer: 1,
|
|
69
|
+
earningThreshold: {
|
|
70
|
+
join: '10000000000',
|
|
71
|
+
defaultUnstake: '0',
|
|
72
|
+
fastUnstake: '0'
|
|
73
|
+
},
|
|
74
|
+
totalApr: 1.29,
|
|
75
|
+
tvl: '291890000000000'
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* Subscribe pool info */
|
|
81
|
+
|
|
82
|
+
/* Subscribe pool position */
|
|
83
|
+
|
|
84
|
+
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
85
|
+
let cancel = false;
|
|
86
|
+
const substrateApi = this.substrateApi;
|
|
87
|
+
await substrateApi.isReady;
|
|
88
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
89
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
90
|
+
const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, (0, _utils._getTokenOnChainInfo)(derivativeTokenInfo)]), async _balances => {
|
|
91
|
+
if (cancel) {
|
|
92
|
+
unsub();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const exchangeRate = await this.getExchangeRate();
|
|
96
|
+
const decimals = _util.BN_TEN.pow(new _util.BN(this.rateDecimals));
|
|
97
|
+
const balances = _balances;
|
|
98
|
+
for (let i = 0; i < balances.length; i++) {
|
|
99
|
+
const balanceItem = balances[i];
|
|
100
|
+
const address = useAddresses[i];
|
|
101
|
+
const bnActiveBalance = balanceItem.free || _util.BN_ZERO;
|
|
102
|
+
const bnTotalBalance = bnActiveBalance.mul(new _util.BN(exchangeRate)).div(decimals);
|
|
103
|
+
const result = {
|
|
104
|
+
...this.baseInfo,
|
|
105
|
+
type: this.type,
|
|
106
|
+
address,
|
|
107
|
+
balanceToken: this.inputAsset,
|
|
108
|
+
totalStake: bnTotalBalance.toString(),
|
|
109
|
+
activeStake: bnActiveBalance.toString(),
|
|
110
|
+
unstakeBalance: '0',
|
|
111
|
+
status: bnActiveBalance.gt(_util.BN_ZERO) ? _types.EarningStatus.EARNING_REWARD : _types.EarningStatus.NOT_EARNING,
|
|
112
|
+
derivativeToken: derivativeTokenSlug,
|
|
113
|
+
isBondedBefore: bnTotalBalance.gt(_util.BN_ZERO),
|
|
114
|
+
nominations: [],
|
|
115
|
+
unstakings: []
|
|
116
|
+
};
|
|
117
|
+
resultCallback(result);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return () => {
|
|
121
|
+
cancel = true;
|
|
122
|
+
unsub();
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* Subscribe pool position */
|
|
127
|
+
|
|
128
|
+
/* Join pool action */
|
|
129
|
+
|
|
130
|
+
get submitJoinStepInfo() {
|
|
131
|
+
return {
|
|
132
|
+
name: 'Mint qDOT',
|
|
133
|
+
type: _types.YieldStepType.MINT_QDOT
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async getSubmitStepFee(params) {
|
|
137
|
+
const poolOriginSubstrateApi = await this.substrateApi.isReady;
|
|
138
|
+
const inputTokenSlug = this.inputAsset;
|
|
139
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
140
|
+
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
141
|
+
if (new _util.BN(params.amount).gt(_util.BN_ZERO)) {
|
|
142
|
+
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.loans.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), params.amount).paymentInfo(_constants.fakeAddress);
|
|
143
|
+
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
144
|
+
return {
|
|
145
|
+
amount: mintFeeInfo.partialFee.toString(),
|
|
146
|
+
slug: defaultFeeTokenSlug
|
|
147
|
+
};
|
|
148
|
+
} else {
|
|
149
|
+
return {
|
|
150
|
+
amount: '0',
|
|
151
|
+
slug: defaultFeeTokenSlug
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async handleSubmitStep(data, path) {
|
|
156
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
157
|
+
const inputTokenSlug = this.inputAsset;
|
|
158
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
159
|
+
const extrinsic = substrateApi.api.tx.loans.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), data.amount);
|
|
160
|
+
return {
|
|
161
|
+
txChain: this.chain,
|
|
162
|
+
extrinsicType: _KoniTypes.ExtrinsicType.MINT_QDOT,
|
|
163
|
+
extrinsic,
|
|
164
|
+
txData: data,
|
|
165
|
+
transferNativeAmount: '0',
|
|
166
|
+
chainType: _KoniTypes.ChainType.SUBSTRATE
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/* Join pool action */
|
|
171
|
+
|
|
172
|
+
/* Leave pool action */
|
|
173
|
+
|
|
174
|
+
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
175
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
176
|
+
// @ts-ignore
|
|
177
|
+
const inputTokenSlug = this.inputAsset;
|
|
178
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
179
|
+
const yieldPositionInfo = await this.getPoolPosition(address);
|
|
180
|
+
if (!yieldPositionInfo) {
|
|
181
|
+
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INVALID_PARAMS));
|
|
182
|
+
}
|
|
183
|
+
const bnAmount = new _util.BN(amount);
|
|
184
|
+
const bnActiveBalance = new _util.BN(yieldPositionInfo.activeStake);
|
|
185
|
+
const redeemAll = bnAmount.eq(bnActiveBalance);
|
|
186
|
+
const extrinsic = !redeemAll ? substrateApi.api.tx.loans.redeem((0, _utils._getTokenOnChainInfo)(inputTokenInfo), amount) : substrateApi.api.tx.loans.redeemAll((0, _utils._getTokenOnChainInfo)(inputTokenInfo));
|
|
187
|
+
return [_KoniTypes.ExtrinsicType.REDEEM_QDOT, extrinsic];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* Leave pool action */
|
|
191
|
+
}
|
|
192
|
+
exports.default = InterlayLendingPoolHandler;
|