@subwallet/extension-base 1.1.28-0 → 1.1.28-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 +92 -68
- package/background/KoniTypes.js +16 -13
- package/background/errors/TransactionError.js +9 -0
- package/cjs/background/KoniTypes.js +17 -16
- package/cjs/background/errors/TransactionError.js +9 -0
- package/cjs/constants/index.js +9 -3
- package/cjs/koni/api/dotsama/balance.js +464 -0
- package/cjs/koni/api/nft/config.js +33 -23
- package/cjs/koni/api/nft/index.js +14 -0
- package/cjs/koni/api/nft/nft.js +1 -22
- package/cjs/koni/api/nft/ordinal_nft/constants.js +21 -0
- package/cjs/koni/api/nft/ordinal_nft/index.js +121 -0
- package/cjs/koni/api/nft/ordinal_nft/utils.js +41 -0
- package/cjs/koni/api/staking/bonding/amplitude.js +17 -15
- package/cjs/koni/api/staking/bonding/astar.js +11 -10
- package/cjs/koni/api/staking/bonding/index.js +4 -1
- package/cjs/koni/api/staking/bonding/paraChain.js +25 -23
- package/cjs/koni/api/staking/bonding/relayChain.js +48 -45
- package/cjs/koni/api/staking/bonding/utils.js +104 -86
- package/cjs/koni/api/staking/index.js +6 -5
- package/cjs/koni/api/staking/paraChain.js +6 -5
- package/cjs/koni/api/staking/relayChain.js +3 -2
- package/cjs/koni/api/yield/helper/utils.js +46 -0
- package/cjs/koni/background/cron.js +2 -0
- package/cjs/koni/background/handlers/Extension.js +323 -69
- package/cjs/koni/background/handlers/State.js +57 -4
- package/cjs/koni/background/handlers/index.js +4 -2
- package/cjs/koni/background/subscription.js +89 -19
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/campaign-service/index.js +9 -6
- package/cjs/services/chain-service/constants.js +2 -16
- package/cjs/services/chain-service/utils.js +7 -1
- package/cjs/services/earning-service/constants/chains.js +29 -0
- package/cjs/services/earning-service/constants/index.js +27 -0
- package/cjs/services/earning-service/constants/step.js +18 -0
- package/cjs/services/earning-service/handlers/base.js +202 -0
- package/cjs/services/earning-service/handlers/index.js +60 -0
- package/cjs/services/earning-service/handlers/lending/base.js +20 -0
- package/cjs/services/earning-service/handlers/lending/index.js +13 -0
- package/cjs/services/earning-service/handlers/lending/interlay.js +168 -0
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +196 -0
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +39 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +257 -0
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +180 -0
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +373 -0
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +359 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +426 -0
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +137 -0
- package/cjs/services/earning-service/handlers/native-staking/base.js +109 -0
- package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +361 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +512 -0
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +501 -0
- package/cjs/services/earning-service/handlers/special.js +387 -0
- package/cjs/services/earning-service/service.js +327 -0
- package/cjs/services/earning-service/utils/index.js +111 -0
- package/cjs/services/event-service/index.js +4 -0
- package/cjs/services/keyring-service/index.js +14 -2
- package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
- package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
- package/cjs/services/migration-service/scripts/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/index.js +4 -0
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
- package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
- package/cjs/services/mint-campaign-service/constants.js +11 -0
- package/cjs/services/mint-campaign-service/index.js +18 -0
- package/cjs/services/notification-service/NotificationService.js +1 -1
- package/cjs/services/storage-service/DatabaseService.js +47 -0
- package/cjs/services/storage-service/databases/index.js +4 -0
- package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/cjs/services/storage-service/db-stores/YieldPoolStore.js +36 -0
- package/cjs/services/storage-service/db-stores/YieldPositionStore.js +65 -0
- package/cjs/services/storage-service/index.js +241 -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 +180 -74
- package/cjs/services/transaction-service/utils.js +1 -0
- package/cjs/types/campaigns/index.js +16 -0
- package/cjs/types/campaigns/unlock-dot.js +1 -0
- package/cjs/types/index.js +44 -0
- package/cjs/types/ordinal.js +1 -0
- package/cjs/types/transaction.js +1 -0
- package/cjs/types/yield/actions/index.js +27 -0
- package/cjs/types/yield/actions/join/index.js +38 -0
- package/cjs/types/yield/actions/join/step.js +37 -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 +34 -0
- package/cjs/types/yield/info/chain/index.js +27 -0
- package/cjs/types/yield/info/chain/info.js +1 -0
- package/cjs/types/yield/info/chain/target.js +1 -0
- package/cjs/types/yield/info/index.js +49 -0
- package/cjs/types/yield/info/pallet.js +15 -0
- package/cjs/types.js +1 -0
- package/cjs/utils/address.js +34 -0
- package/cjs/utils/fetchStaticData.js +2 -1
- package/cjs/utils/index.js +89 -1
- package/cjs/utils/keyring.js +57 -0
- package/cjs/utils/object.js +12 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +2 -0
- package/koni/api/nft/config.js +33 -23
- package/koni/api/nft/index.js +15 -1
- package/koni/api/nft/nft.js +2 -23
- package/koni/api/nft/ordinal_nft/constants.d.ts +9 -0
- package/koni/api/nft/ordinal_nft/constants.js +12 -0
- package/koni/api/nft/ordinal_nft/index.d.ts +8 -0
- package/koni/api/nft/ordinal_nft/index.js +114 -0
- package/koni/api/nft/ordinal_nft/utils.d.ts +2 -0
- package/koni/api/nft/ordinal_nft/utils.js +33 -0
- package/koni/api/staking/bonding/amplitude.js +11 -9
- package/koni/api/staking/bonding/astar.js +9 -8
- package/koni/api/staking/bonding/index.d.ts +1 -1
- package/koni/api/staking/bonding/index.js +5 -1
- package/koni/api/staking/bonding/paraChain.js +12 -10
- package/koni/api/staking/bonding/relayChain.d.ts +2 -2
- package/koni/api/staking/bonding/relayChain.js +33 -30
- package/koni/api/staking/bonding/utils.d.ts +15 -38
- package/koni/api/staking/bonding/utils.js +85 -69
- package/koni/api/staking/index.js +2 -1
- package/koni/api/staking/paraChain.js +7 -6
- package/koni/api/staking/relayChain.js +4 -3
- package/koni/api/yield/helper/utils.d.ts +10 -0
- package/koni/api/yield/helper/utils.js +32 -0
- package/koni/background/cron.js +2 -0
- package/koni/background/handlers/Extension.d.ts +14 -1
- package/koni/background/handlers/Extension.js +282 -30
- package/koni/background/handlers/State.d.ts +18 -2
- package/koni/background/handlers/State.js +56 -4
- package/koni/background/handlers/index.js +4 -2
- package/koni/background/subscription.d.ts +5 -1
- package/koni/background/subscription.js +91 -21
- package/package.json +311 -8
- package/packageInfo.js +1 -1
- package/services/campaign-service/index.js +9 -6
- package/services/chain-service/constants.d.ts +0 -11
- package/services/chain-service/constants.js +1 -14
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +5 -1
- package/services/earning-service/constants/abis/compound_finance_v2_abi.json +1235 -0
- package/services/earning-service/constants/abis/st_liquid_token_abi.json +1355 -0
- package/services/earning-service/constants/chains.d.ts +14 -0
- package/services/earning-service/constants/chains.js +21 -0
- package/services/earning-service/constants/index.d.ts +2 -0
- package/services/earning-service/constants/index.js +5 -0
- package/services/earning-service/constants/step.d.ts +3 -0
- package/services/earning-service/constants/step.js +10 -0
- package/services/earning-service/handlers/base.d.ts +105 -0
- package/services/earning-service/handlers/base.js +195 -0
- package/services/earning-service/handlers/index.d.ts +5 -0
- package/services/earning-service/handlers/index.js +8 -0
- package/services/earning-service/handlers/lending/base.d.ts +6 -0
- package/services/earning-service/handlers/lending/base.js +12 -0
- package/services/earning-service/handlers/lending/index.d.ts +1 -0
- package/services/earning-service/handlers/lending/index.js +4 -0
- package/services/earning-service/handlers/lending/interlay.d.ts +22 -0
- package/services/earning-service/handlers/lending/interlay.js +160 -0
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +188 -0
- package/services/earning-service/handlers/liquid-staking/base.d.ts +8 -0
- package/services/earning-service/handlers/liquid-staking/base.js +31 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +44 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.js +246 -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 +27 -0
- package/services/earning-service/handlers/liquid-staking/parallel.js +172 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +36 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +363 -0
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +350 -0
- package/services/earning-service/handlers/native-staking/astar.d.ts +18 -0
- package/services/earning-service/handlers/native-staking/astar.js +416 -0
- package/services/earning-service/handlers/native-staking/base-para.d.ts +11 -0
- package/services/earning-service/handlers/native-staking/base-para.js +129 -0
- package/services/earning-service/handlers/native-staking/base.d.ts +19 -0
- package/services/earning-service/handlers/native-staking/base.js +101 -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 +353 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +503 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +33 -0
- package/services/earning-service/handlers/nomination-pool/index.js +492 -0
- package/services/earning-service/handlers/special.d.ts +56 -0
- package/services/earning-service/handlers/special.js +379 -0
- package/services/earning-service/service.d.ts +36 -0
- package/services/earning-service/service.js +320 -0
- package/services/earning-service/utils/index.d.ts +14 -0
- package/services/earning-service/utils/index.js +100 -0
- package/services/event-service/index.d.ts +1 -0
- package/services/event-service/index.js +4 -0
- package/services/event-service/types.d.ts +8 -0
- package/services/keyring-service/index.d.ts +2 -1
- package/services/keyring-service/index.js +14 -2
- package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
- package/services/migration-service/scripts/DeleteEarningData.js +13 -0
- package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
- package/services/migration-service/scripts/EnableEarningChains.js +13 -0
- package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/services/migration-service/scripts/index.js +4 -0
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
- package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
- package/services/mint-campaign-service/campaigns/index.js +4 -0
- package/services/mint-campaign-service/constants.d.ts +1 -0
- package/services/mint-campaign-service/constants.js +4 -0
- package/services/mint-campaign-service/index.d.ts +7 -0
- package/services/mint-campaign-service/index.js +11 -0
- package/services/notification-service/NotificationService.js +1 -1
- package/services/storage-service/DatabaseService.d.ts +17 -1
- package/services/storage-service/DatabaseService.js +47 -0
- package/services/storage-service/databases/index.d.ts +3 -1
- package/services/storage-service/databases/index.js +4 -0
- package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/services/storage-service/db-stores/YieldPoolStore.d.ts +10 -0
- package/services/storage-service/db-stores/YieldPoolStore.js +28 -0
- package/services/storage-service/db-stores/YieldPositionStore.d.ts +9 -0
- package/services/storage-service/db-stores/YieldPositionStore.js +57 -0
- package/services/subscan-service/index.d.ts +2 -2
- package/services/transaction-service/event-parser/index.d.ts +3 -1
- package/services/transaction-service/event-parser/index.js +57 -1
- package/services/transaction-service/helpers/index.js +3 -1
- package/services/transaction-service/index.d.ts +4 -15
- package/services/transaction-service/index.js +178 -72
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.js +1 -0
- package/types/campaigns/index.d.ts +1 -0
- package/types/campaigns/index.js +4 -0
- package/types/campaigns/unlock-dot.d.ts +71 -0
- package/types/campaigns/unlock-dot.js +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.js +5 -1
- package/types/ordinal.d.ts +69 -0
- package/types/ordinal.js +1 -0
- package/types/transaction.d.ts +3 -0
- package/types/transaction.js +1 -0
- package/types/yield/actions/index.d.ts +2 -0
- package/types/yield/actions/index.js +5 -0
- package/types/yield/actions/join/index.d.ts +3 -0
- package/types/yield/actions/join/index.js +6 -0
- package/types/yield/actions/join/step.d.ts +75 -0
- package/types/yield/actions/join/step.js +34 -0
- package/types/yield/actions/join/submit.d.ts +53 -0
- package/types/yield/actions/join/submit.js +1 -0
- package/types/yield/actions/join/validate.d.ts +18 -0
- package/types/yield/actions/join/validate.js +10 -0
- package/types/yield/actions/others.d.ts +60 -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 +112 -0
- package/types/yield/info/account/info.js +1 -0
- package/types/yield/info/account/reward.d.ts +41 -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 +28 -0
- package/types/yield/info/base.js +28 -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 +190 -0
- package/types/yield/info/chain/info.js +1 -0
- package/types/yield/info/chain/target.d.ts +33 -0
- package/types/yield/info/chain/target.js +1 -0
- package/types/yield/info/index.d.ts +4 -0
- package/types/yield/info/index.js +7 -0
- package/types/yield/info/pallet.d.ts +143 -0
- package/types/yield/info/pallet.js +9 -0
- package/utils/fetchStaticData.js +2 -1
- package/utils/index.d.ts +5 -0
- package/utils/index.js +53 -1
- package/utils/object.d.ts +1 -0
- package/utils/object.js +6 -0
|
@@ -0,0 +1,202 @@
|
|
|
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/services/earning-service/constants");
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @class BasePoolHandler
|
|
14
|
+
* @description Base pool handler
|
|
15
|
+
* */
|
|
16
|
+
class BasePoolHandler {
|
|
17
|
+
/** Koni state */
|
|
18
|
+
|
|
19
|
+
/** Pool's chain */
|
|
20
|
+
|
|
21
|
+
/** Pool's logo */
|
|
22
|
+
|
|
23
|
+
/** Pool's slug */
|
|
24
|
+
|
|
25
|
+
/** Pool's type */
|
|
26
|
+
|
|
27
|
+
/** Pool's name */
|
|
28
|
+
|
|
29
|
+
/** Pool's short name */
|
|
30
|
+
|
|
31
|
+
/** Pool's description */
|
|
32
|
+
|
|
33
|
+
/** Pool's transaction type */
|
|
34
|
+
transactionChainType = _KoniTypes.ChainType.SUBSTRATE;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @constructor
|
|
38
|
+
* @param {KoniState} state - Koni state
|
|
39
|
+
* @param {string} chain - Pool's chain
|
|
40
|
+
* */
|
|
41
|
+
constructor(state, chain) {
|
|
42
|
+
this.state = state;
|
|
43
|
+
this.chain = chain;
|
|
44
|
+
this._logo = chain;
|
|
45
|
+
}
|
|
46
|
+
get logo() {
|
|
47
|
+
return this._logo;
|
|
48
|
+
}
|
|
49
|
+
get group() {
|
|
50
|
+
const groupSlug = this.nativeToken.multiChainAsset;
|
|
51
|
+
return groupSlug || this.nativeToken.slug;
|
|
52
|
+
}
|
|
53
|
+
get substrateApi() {
|
|
54
|
+
return this.state.getSubstrateApi(this.chain);
|
|
55
|
+
}
|
|
56
|
+
get evmApi() {
|
|
57
|
+
return this.state.getEvmApi(this.chain);
|
|
58
|
+
}
|
|
59
|
+
get chainInfo() {
|
|
60
|
+
return this.state.getChainInfo(this.chain);
|
|
61
|
+
}
|
|
62
|
+
get nativeToken() {
|
|
63
|
+
return this.state.getNativeTokenInfo(this.chain);
|
|
64
|
+
}
|
|
65
|
+
get defaultInfo() {
|
|
66
|
+
return {
|
|
67
|
+
name: this.name,
|
|
68
|
+
shortName: this.shortName,
|
|
69
|
+
group: this.group,
|
|
70
|
+
logo: this.logo,
|
|
71
|
+
chain: this.chain,
|
|
72
|
+
slug: this.slug
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Can mint when haven't enough native token (use input token for fee) */
|
|
77
|
+
get isPoolSupportAlternativeFee() {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
async getPoolInfo() {
|
|
81
|
+
return this.state.dbService.getYieldPool(this.slug);
|
|
82
|
+
}
|
|
83
|
+
async getPoolPosition(address) {
|
|
84
|
+
return this.state.dbService.getYieldPositionByAddressAndSlug(address, this.slug);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/* Subscribe data */
|
|
88
|
+
|
|
89
|
+
/** Subscribe pool info */
|
|
90
|
+
|
|
91
|
+
/* Subscribe data */
|
|
92
|
+
|
|
93
|
+
/* Join action */
|
|
94
|
+
|
|
95
|
+
/* Generate steps */
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @function firstStepFee
|
|
99
|
+
* */
|
|
100
|
+
get firstStepFee() {
|
|
101
|
+
return {
|
|
102
|
+
slug: ''
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @function defaultSubmitStep
|
|
108
|
+
* @description Default submit step data
|
|
109
|
+
* */
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @async
|
|
113
|
+
* @function getTokenApproveStep
|
|
114
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
115
|
+
* @description Generate token approve step data
|
|
116
|
+
* */
|
|
117
|
+
async getTokenApproveStep(params) {
|
|
118
|
+
return Promise.resolve(undefined);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @async
|
|
123
|
+
* @function getXcmStep
|
|
124
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
125
|
+
* @description Generate token approve step data
|
|
126
|
+
* */
|
|
127
|
+
async getXcmStep(params) {
|
|
128
|
+
return Promise.resolve(undefined);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @async
|
|
133
|
+
* @function getSubmitStep
|
|
134
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
135
|
+
* @description Generate token approve step data
|
|
136
|
+
* */
|
|
137
|
+
|
|
138
|
+
/** Generate the optimal steps to join pool */
|
|
139
|
+
async generateOptimalPath(params) {
|
|
140
|
+
const result = {
|
|
141
|
+
totalFee: [this.firstStepFee],
|
|
142
|
+
steps: [_constants.DEFAULT_YIELD_FIRST_STEP]
|
|
143
|
+
};
|
|
144
|
+
try {
|
|
145
|
+
const stepFunctions = [this.getTokenApproveStep, this.getXcmStep, this.getSubmitStep];
|
|
146
|
+
for (const stepFunction of stepFunctions) {
|
|
147
|
+
const step = await stepFunction(params);
|
|
148
|
+
if (step) {
|
|
149
|
+
const [info, fee] = step;
|
|
150
|
+
result.steps.push({
|
|
151
|
+
id: result.steps.length,
|
|
152
|
+
...info
|
|
153
|
+
});
|
|
154
|
+
result.totalFee.push(fee);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
} catch (e) {
|
|
159
|
+
const errorMessage = e.message;
|
|
160
|
+
if (errorMessage.includes('network')) {
|
|
161
|
+
result.connectionError = errorMessage.split(' ')[0];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* Submit step */
|
|
165
|
+
|
|
166
|
+
const [step, fee] = this.defaultSubmitStep;
|
|
167
|
+
result.steps.push({
|
|
168
|
+
id: result.steps.length,
|
|
169
|
+
...step
|
|
170
|
+
});
|
|
171
|
+
result.totalFee.push(fee);
|
|
172
|
+
|
|
173
|
+
/* Submit step */
|
|
174
|
+
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/* Generate steps */
|
|
180
|
+
|
|
181
|
+
/* Validate */
|
|
182
|
+
|
|
183
|
+
/** Validate param to join the pool */
|
|
184
|
+
|
|
185
|
+
/** Create `transaction` to leave the pool */
|
|
186
|
+
async handleYieldLeave(fastLeave, amount, address, selectedTarget) {
|
|
187
|
+
if (fastLeave) {
|
|
188
|
+
return this.handleYieldRedeem(amount, address, selectedTarget);
|
|
189
|
+
} else {
|
|
190
|
+
return this.handleYieldUnstake(amount, address, selectedTarget);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* Leave action */
|
|
195
|
+
|
|
196
|
+
/* Other actions */
|
|
197
|
+
|
|
198
|
+
/** Create `transaction` to withdraw unstaked amount */
|
|
199
|
+
|
|
200
|
+
/* Other actions */
|
|
201
|
+
}
|
|
202
|
+
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,20 @@
|
|
|
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 _types = require("@subwallet/extension-base/types");
|
|
9
|
+
var _special = _interopRequireDefault(require("../special"));
|
|
10
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
13
|
+
class BaseLendingPoolHandler extends _special.default {
|
|
14
|
+
type = _types.YieldPoolType.LENDING;
|
|
15
|
+
|
|
16
|
+
/* Subscribe pool info */
|
|
17
|
+
|
|
18
|
+
/* Subscribe pool info */
|
|
19
|
+
}
|
|
20
|
+
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,168 @@
|
|
|
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 _bn = _interopRequireDefault(require("bn.js"));
|
|
13
|
+
var _util = require("@polkadot/util");
|
|
14
|
+
var _constants = require("../../constants");
|
|
15
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
16
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
17
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
|
|
19
|
+
class InterlayLendingPoolHandler extends _base.default {
|
|
20
|
+
altInputAsset = 'polkadot-NATIVE-DOT';
|
|
21
|
+
derivativeAssets = ['interlay-LOCAL-qDOT'];
|
|
22
|
+
inputAsset = 'interlay-LOCAL-DOT';
|
|
23
|
+
rewardAssets = ['interlay-LOCAL-DOT'];
|
|
24
|
+
feeAssets = ['interlay-NATIVE-INTR', 'interlay-LOCAL-DOT'];
|
|
25
|
+
constructor(state, chain) {
|
|
26
|
+
super(state, chain);
|
|
27
|
+
const chainInfo = this.chainInfo;
|
|
28
|
+
this.slug = `DOT___lending___${chain}`;
|
|
29
|
+
this.name = `${chainInfo.name} Lending`;
|
|
30
|
+
this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
|
|
31
|
+
this.description = 'Earn rewards by lending DOT';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* Subscribe pool info */
|
|
35
|
+
|
|
36
|
+
async getPoolStat() {
|
|
37
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
38
|
+
const inputTokenSlug = this.inputAsset;
|
|
39
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
40
|
+
const _exchangeRate = await substrateApi.api.query.loans.exchangeRate((0, _utils._getTokenOnChainInfo)(inputTokenInfo));
|
|
41
|
+
const exchangeRate = _exchangeRate.toPrimitive();
|
|
42
|
+
const decimals = 10 ** 18;
|
|
43
|
+
return {
|
|
44
|
+
...this.defaultInfo,
|
|
45
|
+
description: this.description,
|
|
46
|
+
type: this.type,
|
|
47
|
+
metadata: {
|
|
48
|
+
...this.baseMetadata,
|
|
49
|
+
isAvailable: true,
|
|
50
|
+
allowCancelUnstaking: false,
|
|
51
|
+
assetEarning: [{
|
|
52
|
+
slug: this.rewardAssets[0],
|
|
53
|
+
apr: 1.29,
|
|
54
|
+
exchangeRate: exchangeRate / decimals
|
|
55
|
+
}],
|
|
56
|
+
maxCandidatePerFarmer: 1,
|
|
57
|
+
maxWithdrawalRequestPerFarmer: 1,
|
|
58
|
+
minJoinPool: '10000000000',
|
|
59
|
+
minWithdrawal: '0',
|
|
60
|
+
totalApr: 1.29,
|
|
61
|
+
tvl: '291890000000000'
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* Subscribe pool info */
|
|
67
|
+
|
|
68
|
+
/* Subscribe pool position */
|
|
69
|
+
|
|
70
|
+
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
71
|
+
let cancel = false;
|
|
72
|
+
const substrateApi = this.substrateApi;
|
|
73
|
+
await substrateApi.isReady;
|
|
74
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
75
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
76
|
+
const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, (0, _utils._getTokenOnChainInfo)(derivativeTokenInfo)]), _balances => {
|
|
77
|
+
if (cancel) {
|
|
78
|
+
unsub();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const balances = _balances;
|
|
82
|
+
for (let i = 0; i < balances.length; i++) {
|
|
83
|
+
const balanceItem = balances[i];
|
|
84
|
+
const address = useAddresses[i];
|
|
85
|
+
const bnTotalBalance = balanceItem.free || _util.BN_ZERO;
|
|
86
|
+
const totalBalance = bnTotalBalance.toString();
|
|
87
|
+
const result = {
|
|
88
|
+
...this.defaultInfo,
|
|
89
|
+
type: this.type,
|
|
90
|
+
address,
|
|
91
|
+
balanceToken: this.inputAsset,
|
|
92
|
+
totalStake: totalBalance,
|
|
93
|
+
activeStake: totalBalance,
|
|
94
|
+
unstakeBalance: '0',
|
|
95
|
+
status: _types.EarningStatus.EARNING_REWARD,
|
|
96
|
+
derivativeToken: derivativeTokenSlug,
|
|
97
|
+
isBondedBefore: bnTotalBalance.gt(_util.BN_ZERO),
|
|
98
|
+
nominations: [],
|
|
99
|
+
unstakings: []
|
|
100
|
+
};
|
|
101
|
+
resultCallback(result);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return () => {
|
|
105
|
+
cancel = true;
|
|
106
|
+
unsub();
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* Subscribe pool position */
|
|
111
|
+
|
|
112
|
+
/* Join pool action */
|
|
113
|
+
|
|
114
|
+
get submitJoinStepInfo() {
|
|
115
|
+
return {
|
|
116
|
+
name: 'Mint qDOT',
|
|
117
|
+
type: _types.YieldStepType.MINT_QDOT
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async getSubmitStepFee(params) {
|
|
121
|
+
const poolOriginSubstrateApi = await this.substrateApi.isReady;
|
|
122
|
+
const inputTokenSlug = this.inputAsset;
|
|
123
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
124
|
+
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
125
|
+
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.loans.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), params.amount).paymentInfo(_constants.fakeAddress);
|
|
126
|
+
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
127
|
+
return {
|
|
128
|
+
amount: mintFeeInfo.partialFee.toString(),
|
|
129
|
+
slug: defaultFeeTokenSlug
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async handleSubmitStep(data, path) {
|
|
133
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
134
|
+
const inputTokenSlug = this.inputAsset;
|
|
135
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
136
|
+
const extrinsic = substrateApi.api.tx.loans.mint((0, _utils._getTokenOnChainInfo)(inputTokenInfo), data.amount);
|
|
137
|
+
return {
|
|
138
|
+
txChain: this.chain,
|
|
139
|
+
extrinsicType: _KoniTypes.ExtrinsicType.MINT_QDOT,
|
|
140
|
+
extrinsic,
|
|
141
|
+
txData: data,
|
|
142
|
+
transferNativeAmount: '0'
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* Join pool action */
|
|
147
|
+
|
|
148
|
+
/* Leave pool action */
|
|
149
|
+
|
|
150
|
+
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
151
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
const inputTokenSlug = this.inputAsset;
|
|
154
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
155
|
+
const yieldPositionInfo = await this.getPoolPosition(address);
|
|
156
|
+
if (!yieldPositionInfo) {
|
|
157
|
+
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INVALID_PARAMS));
|
|
158
|
+
}
|
|
159
|
+
const bnAmount = new _bn.default(amount);
|
|
160
|
+
const bnActiveBalance = new _bn.default(yieldPositionInfo.activeStake);
|
|
161
|
+
const redeemAll = bnAmount.eq(bnActiveBalance);
|
|
162
|
+
const extrinsic = !redeemAll ? substrateApi.api.tx.loans.redeem((0, _utils._getTokenOnChainInfo)(inputTokenInfo), amount) : substrateApi.api.tx.loans.redeemAll((0, _utils._getTokenOnChainInfo)(inputTokenInfo));
|
|
163
|
+
return [_KoniTypes.ExtrinsicType.REDEEM_QDOT, extrinsic];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* Leave pool action */
|
|
167
|
+
}
|
|
168
|
+
exports.default = InterlayLendingPoolHandler;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
|
+
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
10
|
+
var _constants = require("@subwallet/extension-base/services/earning-service/constants");
|
|
11
|
+
var _types = require("@subwallet/extension-base/types");
|
|
12
|
+
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
13
|
+
var _util = require("@polkadot/util");
|
|
14
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
15
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
|
|
18
|
+
const GRAPHQL_API = 'https://api.polkawallet.io/acala-liquid-staking-subql';
|
|
19
|
+
const EXCHANGE_RATE_REQUEST = 'query { dailySummaries(first:30, orderBy:TIMESTAMP_DESC) {nodes { exchangeRate timestamp }}}';
|
|
20
|
+
class AcalaLiquidStakingPoolHandler extends _base.default {
|
|
21
|
+
altInputAsset = 'polkadot-NATIVE-DOT';
|
|
22
|
+
derivativeAssets = ['acala-LOCAL-LDOT'];
|
|
23
|
+
inputAsset = 'acala-LOCAL-DOT';
|
|
24
|
+
rewardAssets = ['acala-LOCAL-DOT'];
|
|
25
|
+
feeAssets = ['acala-NATIVE-ACA', 'acala-LOCAL-DOT'];
|
|
26
|
+
/** @inner */
|
|
27
|
+
minAmountPercent = 0.98;
|
|
28
|
+
/** @inner */
|
|
29
|
+
allowDefaultUnstake = true;
|
|
30
|
+
constructor(state, chain) {
|
|
31
|
+
super(state, chain);
|
|
32
|
+
const chainInfo = this.chainInfo;
|
|
33
|
+
this.slug = `DOT___liquid_staking___${chain}`;
|
|
34
|
+
this.name = `${chainInfo.name} Liquid Staking`;
|
|
35
|
+
this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
|
|
36
|
+
this.description = 'Stake DOT to earn yield on LDOT';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* Subscribe pool info */
|
|
40
|
+
|
|
41
|
+
async getPoolStat() {
|
|
42
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
43
|
+
const stakingMetaPromise = new Promise(function (resolve) {
|
|
44
|
+
(0, _crossFetch.default)(GRAPHQL_API, {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: {
|
|
47
|
+
'Content-Type': 'application/json'
|
|
48
|
+
},
|
|
49
|
+
body: JSON.stringify({
|
|
50
|
+
query: EXCHANGE_RATE_REQUEST
|
|
51
|
+
})
|
|
52
|
+
}).then(res => {
|
|
53
|
+
resolve(res.json());
|
|
54
|
+
}).catch(console.error);
|
|
55
|
+
});
|
|
56
|
+
const [_toBondPool, _totalStakingBonded, _stakingMeta] = await Promise.all([substrateApi.api.query.homa.toBondPool(), substrateApi.api.query.homa.totalStakingBonded(), stakingMetaPromise]);
|
|
57
|
+
const stakingMeta = _stakingMeta;
|
|
58
|
+
const stakingMetaList = stakingMeta.data.dailySummaries.nodes;
|
|
59
|
+
const latestExchangeRate = parseInt(stakingMetaList[0].exchangeRate);
|
|
60
|
+
const decimals = 10 ** 10;
|
|
61
|
+
const endingBalance = parseInt(stakingMetaList[0].exchangeRate);
|
|
62
|
+
const beginBalance = parseInt(stakingMetaList[29].exchangeRate);
|
|
63
|
+
const diff = endingBalance / beginBalance;
|
|
64
|
+
const apy = diff ** (365 / 30) - 1;
|
|
65
|
+
const toBondPool = new _util.BN(_toBondPool.toString());
|
|
66
|
+
const totalStakingBonded = new _util.BN(_totalStakingBonded.toString());
|
|
67
|
+
return {
|
|
68
|
+
...this.defaultInfo,
|
|
69
|
+
description: this.description,
|
|
70
|
+
type: this.type,
|
|
71
|
+
metadata: {
|
|
72
|
+
...this.baseMetadata,
|
|
73
|
+
isAvailable: true,
|
|
74
|
+
allowCancelUnstaking: false,
|
|
75
|
+
assetEarning: [{
|
|
76
|
+
slug: this.rewardAssets[0],
|
|
77
|
+
apy: apy * 100,
|
|
78
|
+
exchangeRate: latestExchangeRate / decimals
|
|
79
|
+
}],
|
|
80
|
+
maxCandidatePerFarmer: 1,
|
|
81
|
+
maxWithdrawalRequestPerFarmer: 1,
|
|
82
|
+
minJoinPool: '50000000000',
|
|
83
|
+
minWithdrawal: '50000000000',
|
|
84
|
+
totalApy: apy * 100,
|
|
85
|
+
tvl: totalStakingBonded.add(toBondPool).toString()
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* Subscribe pool info */
|
|
91
|
+
|
|
92
|
+
/* Subscribe pool position */
|
|
93
|
+
|
|
94
|
+
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
95
|
+
let cancel = false;
|
|
96
|
+
const substrateApi = this.substrateApi;
|
|
97
|
+
await substrateApi.isReady;
|
|
98
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
99
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
100
|
+
const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, (0, _utils._getTokenOnChainInfo)(derivativeTokenInfo)]), _balances => {
|
|
101
|
+
if (cancel) {
|
|
102
|
+
unsub();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const balances = _balances;
|
|
106
|
+
for (let i = 0; i < balances.length; i++) {
|
|
107
|
+
const balanceItem = balances[i];
|
|
108
|
+
const address = useAddresses[i];
|
|
109
|
+
const bnTotalBalance = balanceItem.free || _util.BN_ZERO;
|
|
110
|
+
const totalBalance = bnTotalBalance.toString();
|
|
111
|
+
const result = {
|
|
112
|
+
...this.defaultInfo,
|
|
113
|
+
type: this.type,
|
|
114
|
+
address,
|
|
115
|
+
balanceToken: this.inputAsset,
|
|
116
|
+
totalStake: totalBalance,
|
|
117
|
+
activeStake: totalBalance,
|
|
118
|
+
unstakeBalance: '0',
|
|
119
|
+
status: _types.EarningStatus.EARNING_REWARD,
|
|
120
|
+
derivativeToken: derivativeTokenSlug,
|
|
121
|
+
isBondedBefore: bnTotalBalance.gt(_util.BN_ZERO),
|
|
122
|
+
nominations: [],
|
|
123
|
+
unstakings: []
|
|
124
|
+
};
|
|
125
|
+
resultCallback(result);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return () => {
|
|
129
|
+
cancel = true;
|
|
130
|
+
unsub();
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* Subscribe pool position */
|
|
135
|
+
|
|
136
|
+
/* Join pool action */
|
|
137
|
+
|
|
138
|
+
get submitJoinStepInfo() {
|
|
139
|
+
return {
|
|
140
|
+
name: 'Mint LDOT',
|
|
141
|
+
type: _types.YieldStepType.MINT_LDOT
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
async getSubmitStepFee(params) {
|
|
145
|
+
const poolOriginSubstrateApi = await this.substrateApi.isReady;
|
|
146
|
+
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
147
|
+
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.homa.mint(params.amount).paymentInfo(_constants.fakeAddress);
|
|
148
|
+
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
149
|
+
return {
|
|
150
|
+
amount: mintFeeInfo.partialFee.toString(),
|
|
151
|
+
slug: defaultFeeTokenSlug
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
async handleSubmitStep(data, path) {
|
|
155
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
156
|
+
const extrinsic = substrateApi.api.tx.homa.mint(data.amount);
|
|
157
|
+
return {
|
|
158
|
+
txChain: this.chain,
|
|
159
|
+
extrinsicType: _KoniTypes.ExtrinsicType.MINT_LDOT,
|
|
160
|
+
extrinsic,
|
|
161
|
+
txData: data,
|
|
162
|
+
transferNativeAmount: '0'
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* Join pool action */
|
|
167
|
+
|
|
168
|
+
/* Leave pool action */
|
|
169
|
+
|
|
170
|
+
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
171
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
172
|
+
const weightedMinAmount = await this.createParamToRedeem(amount, address);
|
|
173
|
+
const extrinsic = substrateApi.api.tx.aggregatedDex.swapWithExactSupply(
|
|
174
|
+
// Swap path
|
|
175
|
+
[{
|
|
176
|
+
Taiga: [0, /* pool id */
|
|
177
|
+
1, /* supply asset */
|
|
178
|
+
0 /* target asset */]
|
|
179
|
+
}],
|
|
180
|
+
// Supply amount
|
|
181
|
+
amount,
|
|
182
|
+
// Min target amount
|
|
183
|
+
weightedMinAmount // should always set a min target to prevent unexpected result
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
return [_KoniTypes.ExtrinsicType.REDEEM_QDOT, extrinsic];
|
|
187
|
+
}
|
|
188
|
+
async handleYieldUnstake(amount, address, selectedTarget) {
|
|
189
|
+
const chainApi = await this.substrateApi.isReady;
|
|
190
|
+
const extrinsic = chainApi.api.tx.homa.requestRedeem(amount, false);
|
|
191
|
+
return [_KoniTypes.ExtrinsicType.UNSTAKE_QDOT, extrinsic];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* Leave pool action */
|
|
195
|
+
}
|
|
196
|
+
exports.default = AcalaLiquidStakingPoolHandler;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
9
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
|
+
var _utils = require("@subwallet/extension-base/koni/api/yield/helper/utils");
|
|
11
|
+
var _types = require("@subwallet/extension-base/types");
|
|
12
|
+
var _special = _interopRequireDefault(require("../special"));
|
|
13
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
14
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
15
|
+
|
|
16
|
+
class BaseLiquidStakingPoolHandler extends _special.default {
|
|
17
|
+
type = _types.YieldPoolType.LIQUID_STAKING;
|
|
18
|
+
/** Rate convert token when redeem */
|
|
19
|
+
minAmountPercent = 0.98;
|
|
20
|
+
|
|
21
|
+
/* Leave pool action */
|
|
22
|
+
|
|
23
|
+
async createParamToRedeem(amount, address) {
|
|
24
|
+
const yieldPositionInfo = await this.getPoolPosition(address);
|
|
25
|
+
const poolInfo = await this.getPoolInfo();
|
|
26
|
+
const originTokenSlug = this.inputAsset;
|
|
27
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
28
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
29
|
+
const originTokenInfo = this.state.getAssetBySlug(originTokenSlug);
|
|
30
|
+
if (!yieldPositionInfo || !poolInfo) {
|
|
31
|
+
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INVALID_PARAMS));
|
|
32
|
+
}
|
|
33
|
+
const formattedMinAmount = (0, _utils.convertDerivativeToOriginToken)(amount, poolInfo, derivativeTokenInfo, originTokenInfo);
|
|
34
|
+
return Math.floor(this.minAmountPercent * formattedMinAmount);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Leave pool action */
|
|
38
|
+
}
|
|
39
|
+
exports.default = BaseLiquidStakingPoolHandler;
|