@subwallet/extension-base 1.1.29-0 → 1.1.29-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 +94 -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/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 +347 -69
- package/cjs/koni/background/handlers/State.js +51 -3
- package/cjs/koni/background/handlers/index.js +4 -2
- package/cjs/koni/background/subscription.js +88 -18
- 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 +230 -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 +176 -0
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +206 -0
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +43 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +267 -0
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +190 -0
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +382 -0
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +380 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +454 -0
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +137 -0
- package/cjs/services/earning-service/handlers/native-staking/base.js +119 -0
- package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +381 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +540 -0
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +528 -0
- package/cjs/services/earning-service/handlers/special.js +412 -0
- package/cjs/services/earning-service/service.js +351 -0
- package/cjs/services/earning-service/utils/index.js +128 -0
- package/cjs/services/event-service/index.js +4 -0
- package/cjs/services/keyring-service/index.js +14 -2
- package/cjs/services/migration-service/scripts/DeleteEarningData.js +21 -0
- package/cjs/services/migration-service/scripts/EnableEarningChains.js +21 -0
- package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +21 -0
- package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +21 -0
- package/cjs/services/migration-service/scripts/index.js +7 -1
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +149 -0
- package/cjs/services/mint-campaign-service/campaigns/index.js +13 -0
- package/cjs/services/mint-campaign-service/constants.js +11 -0
- package/cjs/services/mint-campaign-service/index.js +18 -0
- package/cjs/services/notification-service/NotificationService.js +1 -1
- package/cjs/services/storage-service/DatabaseService.js +51 -0
- package/cjs/services/storage-service/databases/index.js +4 -0
- package/cjs/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/cjs/services/storage-service/db-stores/YieldPoolStore.js +36 -0
- package/cjs/services/storage-service/db-stores/YieldPositionStore.js +65 -0
- package/cjs/services/transaction-service/event-parser/index.js +58 -0
- package/cjs/services/transaction-service/helpers/index.js +3 -1
- package/cjs/services/transaction-service/index.js +185 -74
- package/cjs/services/transaction-service/utils.js +1 -0
- package/cjs/types/campaigns/index.js +16 -0
- package/cjs/types/campaigns/unlock-dot.js +1 -0
- package/cjs/types/index.js +44 -0
- package/cjs/types/ordinal.js +1 -0
- package/cjs/types/transaction.js +1 -0
- package/cjs/types/yield/actions/index.js +27 -0
- package/cjs/types/yield/actions/join/index.js +38 -0
- package/cjs/types/yield/actions/join/step.js +47 -0
- package/cjs/types/yield/actions/join/submit.js +1 -0
- package/cjs/types/yield/actions/join/validate.js +16 -0
- package/cjs/types/yield/actions/others.js +1 -0
- package/cjs/types/yield/index.js +27 -0
- package/cjs/types/yield/info/account/index.js +49 -0
- package/cjs/types/yield/info/account/info.js +1 -0
- package/cjs/types/yield/info/account/reward.js +1 -0
- package/cjs/types/yield/info/account/target.js +32 -0
- package/cjs/types/yield/info/account/unstake.js +27 -0
- package/cjs/types/yield/info/base.js +41 -0
- package/cjs/types/yield/info/chain/index.js +27 -0
- package/cjs/types/yield/info/chain/info.js +1 -0
- package/cjs/types/yield/info/chain/target.js +1 -0
- package/cjs/types/yield/info/index.js +49 -0
- package/cjs/types/yield/info/pallet.js +15 -0
- package/cjs/utils/fetchStaticData.js +2 -1
- package/cjs/utils/index.js +89 -1
- package/cjs/utils/object.js +12 -0
- package/cjs/utils/yield/index.js +3 -0
- package/constants/index.d.ts +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 +16 -1
- package/koni/background/handlers/Extension.js +306 -30
- package/koni/background/handlers/State.d.ts +18 -2
- package/koni/background/handlers/State.js +50 -3
- package/koni/background/handlers/index.js +4 -2
- package/koni/background/subscription.d.ts +5 -1
- package/koni/background/subscription.js +90 -20
- package/package.json +316 -3
- package/services/campaign-service/index.js +9 -6
- package/services/chain-service/constants.d.ts +0 -11
- package/services/chain-service/constants.js +1 -14
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +5 -1
- package/services/earning-service/constants/abis/compound_finance_v2_abi.json +1235 -0
- package/services/earning-service/constants/abis/st_liquid_token_abi.json +1355 -0
- package/services/earning-service/constants/chains.d.ts +14 -0
- package/services/earning-service/constants/chains.js +21 -0
- package/services/earning-service/constants/index.d.ts +2 -0
- package/services/earning-service/constants/index.js +5 -0
- package/services/earning-service/constants/step.d.ts +3 -0
- package/services/earning-service/constants/step.js +10 -0
- package/services/earning-service/handlers/base.d.ts +108 -0
- package/services/earning-service/handlers/base.js +224 -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 +168 -0
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +198 -0
- package/services/earning-service/handlers/liquid-staking/base.d.ts +9 -0
- package/services/earning-service/handlers/liquid-staking/base.js +35 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +44 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.js +256 -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 +182 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +36 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +372 -0
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +371 -0
- package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
- package/services/earning-service/handlers/native-staking/astar.js +444 -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 +20 -0
- package/services/earning-service/handlers/native-staking/base.js +110 -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 +373 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +531 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +33 -0
- package/services/earning-service/handlers/nomination-pool/index.js +518 -0
- package/services/earning-service/handlers/special.d.ts +59 -0
- package/services/earning-service/handlers/special.js +404 -0
- package/services/earning-service/service.d.ts +40 -0
- package/services/earning-service/service.js +343 -0
- package/services/earning-service/utils/index.d.ts +18 -0
- package/services/earning-service/utils/index.js +112 -0
- package/services/event-service/index.d.ts +1 -0
- package/services/event-service/index.js +4 -0
- package/services/event-service/types.d.ts +8 -0
- package/services/keyring-service/index.d.ts +2 -1
- package/services/keyring-service/index.js +14 -2
- package/services/migration-service/scripts/DeleteEarningData.d.ts +4 -0
- package/services/migration-service/scripts/DeleteEarningData.js +13 -0
- package/services/migration-service/scripts/EnableEarningChains.d.ts +4 -0
- package/services/migration-service/scripts/EnableEarningChains.js +13 -0
- package/services/migration-service/scripts/MigrateLedgerAccount.js +1 -1
- package/services/migration-service/scripts/MigrateTransactionHistory.js +1 -1
- package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningHistory.js +13 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateEarningVersion.js +13 -0
- package/services/migration-service/scripts/index.js +7 -1
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.d.ts +13 -0
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +139 -0
- package/services/mint-campaign-service/campaigns/index.d.ts +1 -0
- package/services/mint-campaign-service/campaigns/index.js +4 -0
- package/services/mint-campaign-service/constants.d.ts +1 -0
- package/services/mint-campaign-service/constants.js +4 -0
- package/services/mint-campaign-service/index.d.ts +7 -0
- package/services/mint-campaign-service/index.js +11 -0
- package/services/notification-service/NotificationService.js +1 -1
- package/services/storage-service/DatabaseService.d.ts +18 -1
- package/services/storage-service/DatabaseService.js +51 -0
- package/services/storage-service/databases/index.d.ts +3 -1
- package/services/storage-service/databases/index.js +4 -0
- package/services/storage-service/db-stores/NominatorMetadata.js +3 -3
- package/services/storage-service/db-stores/YieldPoolStore.d.ts +10 -0
- package/services/storage-service/db-stores/YieldPoolStore.js +28 -0
- package/services/storage-service/db-stores/YieldPositionStore.d.ts +9 -0
- package/services/storage-service/db-stores/YieldPositionStore.js +57 -0
- package/services/subscan-service/index.d.ts +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 +183 -72
- package/services/transaction-service/types.d.ts +2 -0
- package/services/transaction-service/utils.js +1 -0
- package/types/campaigns/index.d.ts +1 -0
- package/types/campaigns/index.js +4 -0
- package/types/campaigns/unlock-dot.d.ts +71 -0
- package/types/campaigns/unlock-dot.js +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.js +5 -1
- package/types/ordinal.d.ts +69 -0
- package/types/ordinal.js +1 -0
- package/types/transaction.d.ts +3 -0
- package/types/transaction.js +1 -0
- package/types/yield/actions/index.d.ts +2 -0
- package/types/yield/actions/index.js +5 -0
- package/types/yield/actions/join/index.d.ts +3 -0
- package/types/yield/actions/join/index.js +6 -0
- package/types/yield/actions/join/step.d.ts +94 -0
- package/types/yield/actions/join/step.js +46 -0
- package/types/yield/actions/join/submit.d.ts +53 -0
- package/types/yield/actions/join/submit.js +1 -0
- package/types/yield/actions/join/validate.d.ts +18 -0
- package/types/yield/actions/join/validate.js +10 -0
- package/types/yield/actions/others.d.ts +63 -0
- package/types/yield/actions/others.js +1 -0
- package/types/yield/index.d.ts +2 -0
- package/types/yield/index.js +5 -0
- package/types/yield/info/account/index.d.ts +4 -0
- package/types/yield/info/account/index.js +7 -0
- package/types/yield/info/account/info.d.ts +101 -0
- package/types/yield/info/account/info.js +1 -0
- package/types/yield/info/account/reward.d.ts +30 -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 +217 -0
- package/types/yield/info/chain/info.js +1 -0
- package/types/yield/info/chain/target.d.ts +37 -0
- package/types/yield/info/chain/target.js +1 -0
- package/types/yield/info/index.d.ts +4 -0
- package/types/yield/info/index.js +7 -0
- package/types/yield/info/pallet.d.ts +143 -0
- package/types/yield/info/pallet.js +9 -0
- package/utils/fetchStaticData.js +2 -1
- package/utils/index.d.ts +5 -0
- package/utils/index.js +53 -1
- package/utils/object.d.ts +1 -0
- package/utils/object.js +6 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const _STAKING_CHAIN_GROUP: {
|
|
2
|
+
relay: string[];
|
|
3
|
+
para: string[];
|
|
4
|
+
astar: string[];
|
|
5
|
+
amplitude: string[];
|
|
6
|
+
kilt: string[];
|
|
7
|
+
nominationPool: string[];
|
|
8
|
+
bifrost: string[];
|
|
9
|
+
aleph: string[];
|
|
10
|
+
ternoa: string[];
|
|
11
|
+
liquidStaking: string[];
|
|
12
|
+
lending: string[];
|
|
13
|
+
};
|
|
14
|
+
export declare const ST_LIQUID_TOKEN_ABI: Record<string, any>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export const _STAKING_CHAIN_GROUP = {
|
|
5
|
+
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'ternoa_alphanet', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet'],
|
|
6
|
+
para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari'],
|
|
7
|
+
astar: ['astar', 'shiden', 'shibuya'],
|
|
8
|
+
amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum'],
|
|
9
|
+
// amplitude and kilt only share some common logic
|
|
10
|
+
kilt: ['kilt', 'kilt_peregrine'],
|
|
11
|
+
nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph', 'kate', 'vara_network', 'goldberg_testnet'],
|
|
12
|
+
bifrost: ['bifrost', 'bifrost_testnet'],
|
|
13
|
+
aleph: ['aleph', 'alephTest'],
|
|
14
|
+
// A0 has distinct tokenomics
|
|
15
|
+
ternoa: ['ternoa', 'ternoa_alphanet'],
|
|
16
|
+
liquidStaking: ['bifrost_dot', 'acala', 'parallel', 'moonbeam'],
|
|
17
|
+
lending: ['interlay']
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
21
|
+
export const ST_LIQUID_TOKEN_ABI = require("./abis/st_liquid_token_abi.json");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { YieldStepType } from '@subwallet/extension-base/types';
|
|
5
|
+
export const DEFAULT_YIELD_FIRST_STEP = {
|
|
6
|
+
id: 0,
|
|
7
|
+
name: 'Fill information',
|
|
8
|
+
type: YieldStepType.DEFAULT
|
|
9
|
+
};
|
|
10
|
+
export const fakeAddress = '15MLn9YQaHZ4GMkhK3qXqR5iGGSdULyJ995ctjeBgFRseyi6';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
|
+
import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
+
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
5
|
+
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
6
|
+
import { BasePoolInfo, BaseYieldPoolMetadata, EarningRewardItem, HandleYieldStepData, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, ResponseEarlyValidateYield, StakeCancelWithdrawalParams, SubmitYieldJoinData, TransactionData, UnstakingInfo, YieldPoolInfo, YieldPoolTarget, YieldPoolType, YieldPositionInfo, YieldStepBaseInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
|
|
7
|
+
/**
|
|
8
|
+
* @class BasePoolHandler
|
|
9
|
+
* @description Base pool handler
|
|
10
|
+
* */
|
|
11
|
+
export default abstract class BasePoolHandler {
|
|
12
|
+
/** Koni state */
|
|
13
|
+
protected readonly state: KoniState;
|
|
14
|
+
/** Pool's chain */
|
|
15
|
+
readonly chain: string;
|
|
16
|
+
/** Pool's logo */
|
|
17
|
+
protected _logo: string;
|
|
18
|
+
/** Pool's slug */
|
|
19
|
+
abstract slug: string;
|
|
20
|
+
/** Pool's type */
|
|
21
|
+
abstract type: YieldPoolType;
|
|
22
|
+
/** Pool's name */
|
|
23
|
+
protected abstract name: string;
|
|
24
|
+
/** Pool's short name */
|
|
25
|
+
protected abstract shortName: string;
|
|
26
|
+
/** Pool's transaction type */
|
|
27
|
+
readonly transactionChainType: ChainType;
|
|
28
|
+
/**
|
|
29
|
+
* @constructor
|
|
30
|
+
* @param {KoniState} state - Koni state
|
|
31
|
+
* @param {string} chain - Pool's chain
|
|
32
|
+
* */
|
|
33
|
+
protected constructor(state: KoniState, chain: string);
|
|
34
|
+
get logo(): string;
|
|
35
|
+
get group(): string;
|
|
36
|
+
get isActive(): boolean;
|
|
37
|
+
protected get substrateApi(): _SubstrateApi;
|
|
38
|
+
protected get evmApi(): _EvmApi;
|
|
39
|
+
get chainInfo(): _ChainInfo;
|
|
40
|
+
protected get nativeToken(): _ChainAsset;
|
|
41
|
+
protected get baseInfo(): Omit<BasePoolInfo, 'type'>;
|
|
42
|
+
protected abstract getDescription(amount?: string): string;
|
|
43
|
+
protected get maintainBalance(): string;
|
|
44
|
+
protected get metadataInfo(): Omit<BaseYieldPoolMetadata, 'description'>;
|
|
45
|
+
/** Can mint when haven't enough native token (use input token for fee) */
|
|
46
|
+
get isPoolSupportAlternativeFee(): boolean;
|
|
47
|
+
getPoolInfo(): Promise<YieldPoolInfo | undefined>;
|
|
48
|
+
getPoolPosition(address: string): Promise<YieldPositionInfo | undefined>;
|
|
49
|
+
/** Subscribe pool info */
|
|
50
|
+
abstract subscribePoolInfo(callback: (data: YieldPoolInfo) => void): Promise<VoidFunction>;
|
|
51
|
+
/** Subscribe pool position */
|
|
52
|
+
abstract subscribePoolPosition(useAddresses: string[], callback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
53
|
+
/** Get pool reward */
|
|
54
|
+
abstract getPoolReward(useAddresses: string[], callback: (rs: EarningRewardItem) => void): Promise<VoidFunction>;
|
|
55
|
+
/** Get pool target */
|
|
56
|
+
abstract getPoolTargets(): Promise<YieldPoolTarget[]>;
|
|
57
|
+
earlyValidate(request: RequestEarlyValidateYield): Promise<ResponseEarlyValidateYield>;
|
|
58
|
+
/**
|
|
59
|
+
* @function firstStepFee
|
|
60
|
+
* */
|
|
61
|
+
protected get firstStepFee(): YieldTokenBaseInfo;
|
|
62
|
+
/**
|
|
63
|
+
* @function defaultSubmitStep
|
|
64
|
+
* @description Default submit step data
|
|
65
|
+
* */
|
|
66
|
+
protected abstract get defaultSubmitStep(): YieldStepBaseInfo;
|
|
67
|
+
/**
|
|
68
|
+
* @async
|
|
69
|
+
* @function getTokenApproveStep
|
|
70
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
71
|
+
* @description Generate token approve step data
|
|
72
|
+
* */
|
|
73
|
+
protected getTokenApproveStep(params: OptimalYieldPathParams): Promise<YieldStepBaseInfo | undefined>;
|
|
74
|
+
/**
|
|
75
|
+
* @async
|
|
76
|
+
* @function getXcmStep
|
|
77
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
78
|
+
* @description Generate token approve step data
|
|
79
|
+
* */
|
|
80
|
+
protected getXcmStep(params: OptimalYieldPathParams): Promise<YieldStepBaseInfo | undefined>;
|
|
81
|
+
/**
|
|
82
|
+
* @async
|
|
83
|
+
* @function getSubmitStep
|
|
84
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
85
|
+
* @description Generate token approve step data
|
|
86
|
+
* */
|
|
87
|
+
protected abstract getSubmitStep(params: OptimalYieldPathParams): Promise<YieldStepBaseInfo>;
|
|
88
|
+
/** Generate the optimal steps to join pool */
|
|
89
|
+
generateOptimalPath(params: OptimalYieldPathParams): Promise<OptimalYieldPath>;
|
|
90
|
+
/** Validate param to join the pool */
|
|
91
|
+
abstract validateYieldJoin(data: SubmitYieldJoinData, path: OptimalYieldPath): Promise<TransactionError[]>;
|
|
92
|
+
/** Create `transaction` to join the pool step-by-step */
|
|
93
|
+
abstract handleYieldJoin(data: SubmitYieldJoinData, path: OptimalYieldPath, currentStep: number): Promise<HandleYieldStepData>;
|
|
94
|
+
/** Validate param to leave the pool */
|
|
95
|
+
abstract validateYieldLeave(amount: string, address: string, fastLeave: boolean, selectedTarget?: string): Promise<TransactionError[]>;
|
|
96
|
+
/** Create `transaction` to leave the pool normal (default unstake) */
|
|
97
|
+
protected abstract handleYieldUnstake(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
98
|
+
/** Create `transaction` to leave the pool fast (swap token) */
|
|
99
|
+
protected abstract handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
100
|
+
/** Create `transaction` to leave the pool */
|
|
101
|
+
handleYieldLeave(fastLeave: boolean, amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
102
|
+
/** Create `transaction` to withdraw unstaked amount */
|
|
103
|
+
abstract handleYieldWithdraw(address: string, unstakingInfo: UnstakingInfo): Promise<TransactionData>;
|
|
104
|
+
/** Create `transaction` to cancel unstake */
|
|
105
|
+
abstract handleYieldCancelUnstake(params: StakeCancelWithdrawalParams): Promise<TransactionData>;
|
|
106
|
+
/** Create `transaction` to claim reward */
|
|
107
|
+
abstract handleYieldClaimReward(address: string, bondReward?: boolean): Promise<TransactionData>;
|
|
108
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { ChainType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { DEFAULT_YIELD_FIRST_STEP } from '@subwallet/extension-base/services/earning-service/constants';
|
|
6
|
+
import { BN, BN_TEN } from '@polkadot/util';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @class BasePoolHandler
|
|
10
|
+
* @description Base pool handler
|
|
11
|
+
* */
|
|
12
|
+
export default class BasePoolHandler {
|
|
13
|
+
/** Koni state */
|
|
14
|
+
|
|
15
|
+
/** Pool's chain */
|
|
16
|
+
|
|
17
|
+
/** Pool's logo */
|
|
18
|
+
|
|
19
|
+
/** Pool's slug */
|
|
20
|
+
|
|
21
|
+
/** Pool's type */
|
|
22
|
+
|
|
23
|
+
/** Pool's name */
|
|
24
|
+
|
|
25
|
+
/** Pool's short name */
|
|
26
|
+
|
|
27
|
+
/** Pool's transaction type */
|
|
28
|
+
transactionChainType = ChainType.SUBSTRATE;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param {KoniState} state - Koni state
|
|
33
|
+
* @param {string} chain - Pool's chain
|
|
34
|
+
* */
|
|
35
|
+
constructor(state, chain) {
|
|
36
|
+
this.state = state;
|
|
37
|
+
this.chain = chain;
|
|
38
|
+
this._logo = chain;
|
|
39
|
+
}
|
|
40
|
+
get logo() {
|
|
41
|
+
return this._logo;
|
|
42
|
+
}
|
|
43
|
+
get group() {
|
|
44
|
+
const groupSlug = this.nativeToken.multiChainAsset;
|
|
45
|
+
return groupSlug || this.nativeToken.slug;
|
|
46
|
+
}
|
|
47
|
+
get isActive() {
|
|
48
|
+
return this.state.activeChainSlugs.includes(this.chain);
|
|
49
|
+
}
|
|
50
|
+
get substrateApi() {
|
|
51
|
+
return this.state.getSubstrateApi(this.chain);
|
|
52
|
+
}
|
|
53
|
+
get evmApi() {
|
|
54
|
+
return this.state.getEvmApi(this.chain);
|
|
55
|
+
}
|
|
56
|
+
get chainInfo() {
|
|
57
|
+
return this.state.getChainInfo(this.chain);
|
|
58
|
+
}
|
|
59
|
+
get nativeToken() {
|
|
60
|
+
return this.state.getNativeTokenInfo(this.chain);
|
|
61
|
+
}
|
|
62
|
+
get baseInfo() {
|
|
63
|
+
return {
|
|
64
|
+
group: this.group,
|
|
65
|
+
chain: this.chain,
|
|
66
|
+
slug: this.slug
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
get maintainBalance() {
|
|
70
|
+
const decimals = this.nativeToken.decimals || 0;
|
|
71
|
+
const defaultMaintainBalance = new BN(1).mul(BN_TEN.pow(new BN(decimals)));
|
|
72
|
+
const ed = new BN(this.nativeToken.minAmount || '0');
|
|
73
|
+
const maintainBalance = ed.gt(defaultMaintainBalance) ? ed.mul(new BN(1.5)) : defaultMaintainBalance;
|
|
74
|
+
return maintainBalance.toString();
|
|
75
|
+
}
|
|
76
|
+
get metadataInfo() {
|
|
77
|
+
return {
|
|
78
|
+
name: this.name,
|
|
79
|
+
shortName: this.shortName,
|
|
80
|
+
logo: this.logo,
|
|
81
|
+
inputAsset: this.nativeToken.slug,
|
|
82
|
+
isAvailable: true,
|
|
83
|
+
allowCancelUnstaking: false,
|
|
84
|
+
maintainAsset: this.nativeToken.slug,
|
|
85
|
+
maintainBalance: this.maintainBalance
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Can mint when haven't enough native token (use input token for fee) */
|
|
90
|
+
get isPoolSupportAlternativeFee() {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
async getPoolInfo() {
|
|
94
|
+
return this.state.dbService.getYieldPool(this.slug);
|
|
95
|
+
}
|
|
96
|
+
async getPoolPosition(address) {
|
|
97
|
+
return this.state.dbService.getYieldPositionByAddressAndSlug(address, this.slug);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* Subscribe data */
|
|
101
|
+
|
|
102
|
+
/** Subscribe pool info */
|
|
103
|
+
|
|
104
|
+
/* Subscribe data */
|
|
105
|
+
|
|
106
|
+
/* Join action */
|
|
107
|
+
|
|
108
|
+
/* Early validate */
|
|
109
|
+
|
|
110
|
+
earlyValidate(request) {
|
|
111
|
+
return Promise.resolve({
|
|
112
|
+
passed: false
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* Early validate */
|
|
117
|
+
|
|
118
|
+
/* Generate steps */
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @function firstStepFee
|
|
122
|
+
* */
|
|
123
|
+
get firstStepFee() {
|
|
124
|
+
return {
|
|
125
|
+
slug: ''
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @function defaultSubmitStep
|
|
131
|
+
* @description Default submit step data
|
|
132
|
+
* */
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @async
|
|
136
|
+
* @function getTokenApproveStep
|
|
137
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
138
|
+
* @description Generate token approve step data
|
|
139
|
+
* */
|
|
140
|
+
async getTokenApproveStep(params) {
|
|
141
|
+
return Promise.resolve(undefined);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @async
|
|
146
|
+
* @function getXcmStep
|
|
147
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
148
|
+
* @description Generate token approve step data
|
|
149
|
+
* */
|
|
150
|
+
async getXcmStep(params) {
|
|
151
|
+
return Promise.resolve(undefined);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @async
|
|
156
|
+
* @function getSubmitStep
|
|
157
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
158
|
+
* @description Generate token approve step data
|
|
159
|
+
* */
|
|
160
|
+
|
|
161
|
+
/** Generate the optimal steps to join pool */
|
|
162
|
+
async generateOptimalPath(params) {
|
|
163
|
+
const result = {
|
|
164
|
+
totalFee: [this.firstStepFee],
|
|
165
|
+
steps: [DEFAULT_YIELD_FIRST_STEP]
|
|
166
|
+
};
|
|
167
|
+
try {
|
|
168
|
+
const stepFunctions = [this.getTokenApproveStep, this.getXcmStep, this.getSubmitStep];
|
|
169
|
+
for (const stepFunction of stepFunctions) {
|
|
170
|
+
const step = await stepFunction.bind(this, params)();
|
|
171
|
+
if (step) {
|
|
172
|
+
const [info, fee] = step;
|
|
173
|
+
result.steps.push({
|
|
174
|
+
id: result.steps.length,
|
|
175
|
+
...info
|
|
176
|
+
});
|
|
177
|
+
result.totalFee.push(fee);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
} catch (e) {
|
|
182
|
+
const errorMessage = e.message;
|
|
183
|
+
if (errorMessage.includes('network')) {
|
|
184
|
+
result.connectionError = errorMessage.split(' ')[0];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* Submit step */
|
|
188
|
+
|
|
189
|
+
const [step, fee] = this.defaultSubmitStep;
|
|
190
|
+
result.steps.push({
|
|
191
|
+
id: result.steps.length,
|
|
192
|
+
...step
|
|
193
|
+
});
|
|
194
|
+
result.totalFee.push(fee);
|
|
195
|
+
|
|
196
|
+
/* Submit step */
|
|
197
|
+
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/* Generate steps */
|
|
203
|
+
|
|
204
|
+
/* Validate */
|
|
205
|
+
|
|
206
|
+
/** Validate param to join the pool */
|
|
207
|
+
|
|
208
|
+
/** Create `transaction` to leave the pool */
|
|
209
|
+
async handleYieldLeave(fastLeave, amount, address, selectedTarget) {
|
|
210
|
+
if (fastLeave) {
|
|
211
|
+
return this.handleYieldRedeem(amount, address, selectedTarget);
|
|
212
|
+
} else {
|
|
213
|
+
return this.handleYieldUnstake(amount, address, selectedTarget);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/* Leave action */
|
|
218
|
+
|
|
219
|
+
/* Other actions */
|
|
220
|
+
|
|
221
|
+
/** Create `transaction` to withdraw unstaked amount */
|
|
222
|
+
|
|
223
|
+
/* Other actions */
|
|
224
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export { default as BasePoolHandler } from "./base.js";
|
|
5
|
+
export { default as NominationPoolHandler } from "./nomination-pool/index.js";
|
|
6
|
+
export * from "./lending/index.js";
|
|
7
|
+
export * from "./liquid-staking/index.js";
|
|
8
|
+
export * from "./native-staking/index.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LendingYieldPoolInfo, YieldPoolType } from '@subwallet/extension-base/types';
|
|
2
|
+
import BaseSpecialStakingPoolHandler from '../special';
|
|
3
|
+
export default abstract class BaseLendingPoolHandler extends BaseSpecialStakingPoolHandler {
|
|
4
|
+
readonly type = YieldPoolType.LENDING;
|
|
5
|
+
abstract getPoolStat(): Promise<LendingYieldPoolInfo>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
5
|
+
import BaseSpecialStakingPoolHandler from "../special.js";
|
|
6
|
+
export default class BaseLendingPoolHandler extends BaseSpecialStakingPoolHandler {
|
|
7
|
+
type = YieldPoolType.LENDING;
|
|
8
|
+
|
|
9
|
+
/* Subscribe pool info */
|
|
10
|
+
|
|
11
|
+
/* Subscribe pool info */
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as InterlayLendingPoolHandler } from './interlay';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
3
|
+
import { BaseYieldStepDetail, HandleYieldStepData, LendingYieldPoolInfo, OptimalYieldPath, OptimalYieldPathParams, SubmitYieldJoinData, TransactionData, YieldPositionInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
|
|
4
|
+
import BaseLendingPoolHandler from './base';
|
|
5
|
+
export default class InterlayLendingPoolHandler extends BaseLendingPoolHandler {
|
|
6
|
+
protected readonly name: string;
|
|
7
|
+
protected readonly shortName: string;
|
|
8
|
+
protected readonly altInputAsset: string;
|
|
9
|
+
protected readonly derivativeAssets: string[];
|
|
10
|
+
protected readonly inputAsset: string;
|
|
11
|
+
protected readonly rewardAssets: string[];
|
|
12
|
+
protected readonly feeAssets: string[];
|
|
13
|
+
slug: string;
|
|
14
|
+
constructor(state: KoniState, chain: string);
|
|
15
|
+
protected getDescription(): string;
|
|
16
|
+
getPoolStat(): Promise<LendingYieldPoolInfo>;
|
|
17
|
+
subscribePoolPosition(useAddresses: string[], resultCallback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
18
|
+
get submitJoinStepInfo(): BaseYieldStepDetail;
|
|
19
|
+
getSubmitStepFee(params: OptimalYieldPathParams): Promise<YieldTokenBaseInfo>;
|
|
20
|
+
handleSubmitStep(data: SubmitYieldJoinData, path: OptimalYieldPath): Promise<HandleYieldStepData>;
|
|
21
|
+
handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
|
+
import { BasicTxErrorType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
+
import { _getTokenOnChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
+
import { EarningStatus, YieldStepType } from '@subwallet/extension-base/types';
|
|
8
|
+
import { BN, BN_ZERO } from '@polkadot/util';
|
|
9
|
+
import { fakeAddress } from "../../constants/index.js";
|
|
10
|
+
import BaseLendingPoolHandler from "./base.js";
|
|
11
|
+
export default class InterlayLendingPoolHandler extends BaseLendingPoolHandler {
|
|
12
|
+
altInputAsset = 'polkadot-NATIVE-DOT';
|
|
13
|
+
derivativeAssets = ['interlay-LOCAL-qDOT'];
|
|
14
|
+
inputAsset = 'interlay-LOCAL-DOT';
|
|
15
|
+
rewardAssets = ['interlay-LOCAL-DOT'];
|
|
16
|
+
feeAssets = ['interlay-NATIVE-INTR', 'interlay-LOCAL-DOT'];
|
|
17
|
+
constructor(state, chain) {
|
|
18
|
+
super(state, chain);
|
|
19
|
+
const chainInfo = this.chainInfo;
|
|
20
|
+
this.slug = `DOT___lending___${chain}`;
|
|
21
|
+
this.name = `${chainInfo.name} Lending`;
|
|
22
|
+
this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
|
|
23
|
+
}
|
|
24
|
+
getDescription() {
|
|
25
|
+
return 'Earn rewards by lending DOT';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Subscribe pool info */
|
|
29
|
+
|
|
30
|
+
async getPoolStat() {
|
|
31
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
32
|
+
const inputTokenSlug = this.inputAsset;
|
|
33
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
34
|
+
const _exchangeRate = await substrateApi.api.query.loans.exchangeRate(_getTokenOnChainInfo(inputTokenInfo));
|
|
35
|
+
const exchangeRate = _exchangeRate.toPrimitive();
|
|
36
|
+
const decimals = 10 ** 18;
|
|
37
|
+
return {
|
|
38
|
+
...this.baseInfo,
|
|
39
|
+
type: this.type,
|
|
40
|
+
metadata: {
|
|
41
|
+
...this.metadataInfo,
|
|
42
|
+
description: this.getDescription()
|
|
43
|
+
},
|
|
44
|
+
statistic: {
|
|
45
|
+
assetEarning: [{
|
|
46
|
+
slug: this.rewardAssets[0],
|
|
47
|
+
apr: 1.29,
|
|
48
|
+
exchangeRate: exchangeRate / decimals
|
|
49
|
+
}],
|
|
50
|
+
maxCandidatePerFarmer: 1,
|
|
51
|
+
maxWithdrawalRequestPerFarmer: 1,
|
|
52
|
+
minJoinPool: '10000000000',
|
|
53
|
+
minWithdrawal: '0',
|
|
54
|
+
totalApr: 1.29,
|
|
55
|
+
tvl: '291890000000000'
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Subscribe pool info */
|
|
61
|
+
|
|
62
|
+
/* Subscribe pool position */
|
|
63
|
+
|
|
64
|
+
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
65
|
+
let cancel = false;
|
|
66
|
+
const substrateApi = this.substrateApi;
|
|
67
|
+
await substrateApi.isReady;
|
|
68
|
+
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
69
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
70
|
+
const unsub = await substrateApi.api.query.tokens.accounts.multi(useAddresses.map(address => [address, _getTokenOnChainInfo(derivativeTokenInfo)]), _balances => {
|
|
71
|
+
if (cancel) {
|
|
72
|
+
unsub();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const balances = _balances;
|
|
76
|
+
for (let i = 0; i < balances.length; i++) {
|
|
77
|
+
const balanceItem = balances[i];
|
|
78
|
+
const address = useAddresses[i];
|
|
79
|
+
const bnTotalBalance = balanceItem.free || BN_ZERO;
|
|
80
|
+
const totalBalance = bnTotalBalance.toString();
|
|
81
|
+
const result = {
|
|
82
|
+
...this.baseInfo,
|
|
83
|
+
type: this.type,
|
|
84
|
+
address,
|
|
85
|
+
balanceToken: this.inputAsset,
|
|
86
|
+
totalStake: totalBalance,
|
|
87
|
+
activeStake: totalBalance,
|
|
88
|
+
unstakeBalance: '0',
|
|
89
|
+
status: EarningStatus.EARNING_REWARD,
|
|
90
|
+
derivativeToken: derivativeTokenSlug,
|
|
91
|
+
isBondedBefore: bnTotalBalance.gt(BN_ZERO),
|
|
92
|
+
nominations: [],
|
|
93
|
+
unstakings: []
|
|
94
|
+
};
|
|
95
|
+
resultCallback(result);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return () => {
|
|
99
|
+
cancel = true;
|
|
100
|
+
unsub();
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Subscribe pool position */
|
|
105
|
+
|
|
106
|
+
/* Join pool action */
|
|
107
|
+
|
|
108
|
+
get submitJoinStepInfo() {
|
|
109
|
+
return {
|
|
110
|
+
name: 'Mint qDOT',
|
|
111
|
+
type: YieldStepType.MINT_QDOT
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
async getSubmitStepFee(params) {
|
|
115
|
+
const poolOriginSubstrateApi = await this.substrateApi.isReady;
|
|
116
|
+
const inputTokenSlug = this.inputAsset;
|
|
117
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
118
|
+
const defaultFeeTokenSlug = this.feeAssets[0];
|
|
119
|
+
if (new BN(params.amount).gt(BN_ZERO)) {
|
|
120
|
+
const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.loans.mint(_getTokenOnChainInfo(inputTokenInfo), params.amount).paymentInfo(fakeAddress);
|
|
121
|
+
const mintFeeInfo = _mintFeeInfo.toPrimitive();
|
|
122
|
+
return {
|
|
123
|
+
amount: mintFeeInfo.partialFee.toString(),
|
|
124
|
+
slug: defaultFeeTokenSlug
|
|
125
|
+
};
|
|
126
|
+
} else {
|
|
127
|
+
return {
|
|
128
|
+
amount: '0',
|
|
129
|
+
slug: defaultFeeTokenSlug
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async handleSubmitStep(data, path) {
|
|
134
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
135
|
+
const inputTokenSlug = this.inputAsset;
|
|
136
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
137
|
+
const extrinsic = substrateApi.api.tx.loans.mint(_getTokenOnChainInfo(inputTokenInfo), data.amount);
|
|
138
|
+
return {
|
|
139
|
+
txChain: this.chain,
|
|
140
|
+
extrinsicType: ExtrinsicType.MINT_QDOT,
|
|
141
|
+
extrinsic,
|
|
142
|
+
txData: data,
|
|
143
|
+
transferNativeAmount: '0'
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* Join pool action */
|
|
148
|
+
|
|
149
|
+
/* Leave pool action */
|
|
150
|
+
|
|
151
|
+
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
152
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
const inputTokenSlug = this.inputAsset;
|
|
155
|
+
const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
|
|
156
|
+
const yieldPositionInfo = await this.getPoolPosition(address);
|
|
157
|
+
if (!yieldPositionInfo) {
|
|
158
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.INVALID_PARAMS));
|
|
159
|
+
}
|
|
160
|
+
const bnAmount = new BN(amount);
|
|
161
|
+
const bnActiveBalance = new BN(yieldPositionInfo.activeStake);
|
|
162
|
+
const redeemAll = bnAmount.eq(bnActiveBalance);
|
|
163
|
+
const extrinsic = !redeemAll ? substrateApi.api.tx.loans.redeem(_getTokenOnChainInfo(inputTokenInfo), amount) : substrateApi.api.tx.loans.redeemAll(_getTokenOnChainInfo(inputTokenInfo));
|
|
164
|
+
return [ExtrinsicType.REDEEM_QDOT, extrinsic];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/* Leave pool action */
|
|
168
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
3
|
+
import { BaseYieldStepDetail, HandleYieldStepData, LiquidYieldPoolInfo, OptimalYieldPath, OptimalYieldPathParams, SubmitYieldJoinData, TransactionData, YieldPositionInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
|
|
4
|
+
import BaseLiquidStakingPoolHandler from './base';
|
|
5
|
+
export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPoolHandler {
|
|
6
|
+
protected readonly name: string;
|
|
7
|
+
protected readonly shortName: string;
|
|
8
|
+
protected readonly altInputAsset: string;
|
|
9
|
+
protected readonly derivativeAssets: string[];
|
|
10
|
+
protected readonly inputAsset: string;
|
|
11
|
+
protected readonly rewardAssets: string[];
|
|
12
|
+
protected readonly feeAssets: string[];
|
|
13
|
+
/** @inner */
|
|
14
|
+
readonly minAmountPercent = 0.98;
|
|
15
|
+
/** @inner */
|
|
16
|
+
protected readonly allowDefaultUnstake = true;
|
|
17
|
+
slug: string;
|
|
18
|
+
constructor(state: KoniState, chain: string);
|
|
19
|
+
protected getDescription(): string;
|
|
20
|
+
getPoolStat(): Promise<LiquidYieldPoolInfo>;
|
|
21
|
+
subscribePoolPosition(useAddresses: string[], resultCallback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
22
|
+
get submitJoinStepInfo(): BaseYieldStepDetail;
|
|
23
|
+
getSubmitStepFee(params: OptimalYieldPathParams): Promise<YieldTokenBaseInfo>;
|
|
24
|
+
handleSubmitStep(data: SubmitYieldJoinData, path: OptimalYieldPath): Promise<HandleYieldStepData>;
|
|
25
|
+
handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
26
|
+
handleYieldUnstake(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
27
|
+
}
|