@subwallet/extension-base 1.1.35-0 → 1.1.35-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +111 -69
- package/background/KoniTypes.js +19 -13
- package/background/errors/TransactionError.js +9 -0
- package/cjs/background/KoniTypes.js +20 -16
- package/cjs/background/errors/TransactionError.js +9 -0
- package/cjs/constants/index.js +19 -4
- package/cjs/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 +14 -0
- package/cjs/utils/number.js +6 -2
- package/cjs/utils/object.js +12 -0
- package/constants/index.d.ts +6 -1
- package/constants/index.js +6 -1
- package/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 +6 -0
- package/utils/number.d.ts +2 -1
- package/utils/number.js +2 -1
- package/utils/object.d.ts +1 -0
- package/utils/object.js +6 -0
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
krest_network: string[];
|
|
14
|
+
};
|
|
15
|
+
export declare const ST_LIQUID_TOKEN_ABI: Record<string, any>;
|
|
@@ -0,0 +1,22 @@
|
|
|
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', 'manta_network'],
|
|
7
|
+
astar: ['astar', 'shiden', 'shibuya'],
|
|
8
|
+
amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum', 'krest_network'],
|
|
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
|
+
krest_network: ['krest_network']
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
22
|
+
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,113 @@
|
|
|
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, EarningRewardHistoryItem, EarningRewardItem, HandleYieldStepData, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, ResponseEarlyValidateYield, StakeCancelWithdrawalParams, SubmitYieldJoinData, TransactionData, UnstakingInfo, YieldPoolInfo, YieldPoolMethodInfo, 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
|
+
/** Pool's available method */
|
|
29
|
+
protected abstract readonly availableMethod: YieldPoolMethodInfo;
|
|
30
|
+
/**
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param {KoniState} state - Koni state
|
|
33
|
+
* @param {string} chain - Pool's chain
|
|
34
|
+
* */
|
|
35
|
+
protected constructor(state: KoniState, chain: string);
|
|
36
|
+
get logo(): string;
|
|
37
|
+
get group(): string;
|
|
38
|
+
get isActive(): boolean;
|
|
39
|
+
protected get substrateApi(): _SubstrateApi;
|
|
40
|
+
protected get evmApi(): _EvmApi;
|
|
41
|
+
get chainInfo(): _ChainInfo;
|
|
42
|
+
protected get nativeToken(): _ChainAsset;
|
|
43
|
+
protected get baseInfo(): Omit<BasePoolInfo, 'type'>;
|
|
44
|
+
protected getAssetBySlug(slug: string): _ChainAsset;
|
|
45
|
+
protected abstract getDescription(amount?: string): string;
|
|
46
|
+
protected get maintainBalance(): string;
|
|
47
|
+
get metadataInfo(): Omit<BaseYieldPoolMetadata, 'description'>;
|
|
48
|
+
/** Can mint when haven't enough native token (use input token for fee) */
|
|
49
|
+
get isPoolSupportAlternativeFee(): boolean;
|
|
50
|
+
getPoolInfo(): Promise<YieldPoolInfo | undefined>;
|
|
51
|
+
getPoolPosition(address: string): Promise<YieldPositionInfo | undefined>;
|
|
52
|
+
/** Subscribe pool info */
|
|
53
|
+
abstract subscribePoolInfo(callback: (data: YieldPoolInfo) => void): Promise<VoidFunction>;
|
|
54
|
+
/** Subscribe pool position */
|
|
55
|
+
abstract subscribePoolPosition(useAddresses: string[], callback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
56
|
+
/** Get pool reward */
|
|
57
|
+
abstract getPoolReward(useAddresses: string[], callback: (rs: EarningRewardItem) => void): Promise<VoidFunction>;
|
|
58
|
+
/** Get pool reward history */
|
|
59
|
+
abstract getPoolRewardHistory(useAddresses: string[], callback: (rs: EarningRewardHistoryItem) => void): Promise<VoidFunction>;
|
|
60
|
+
/** Get pool target */
|
|
61
|
+
abstract getPoolTargets(): Promise<YieldPoolTarget[]>;
|
|
62
|
+
earlyValidate(request: RequestEarlyValidateYield): Promise<ResponseEarlyValidateYield>;
|
|
63
|
+
/**
|
|
64
|
+
* @function firstStepFee
|
|
65
|
+
* */
|
|
66
|
+
protected get firstStepFee(): YieldTokenBaseInfo;
|
|
67
|
+
/**
|
|
68
|
+
* @function defaultSubmitStep
|
|
69
|
+
* @description Default submit step data
|
|
70
|
+
* */
|
|
71
|
+
protected abstract get defaultSubmitStep(): YieldStepBaseInfo;
|
|
72
|
+
/**
|
|
73
|
+
* @async
|
|
74
|
+
* @function getTokenApproveStep
|
|
75
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
76
|
+
* @description Generate token approve step data
|
|
77
|
+
* */
|
|
78
|
+
protected getTokenApproveStep(params: OptimalYieldPathParams): Promise<YieldStepBaseInfo | undefined>;
|
|
79
|
+
/**
|
|
80
|
+
* @async
|
|
81
|
+
* @function getXcmStep
|
|
82
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
83
|
+
* @description Generate token approve step data
|
|
84
|
+
* */
|
|
85
|
+
protected getXcmStep(params: OptimalYieldPathParams): Promise<YieldStepBaseInfo | undefined>;
|
|
86
|
+
/**
|
|
87
|
+
* @async
|
|
88
|
+
* @function getSubmitStep
|
|
89
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
90
|
+
* @description Generate token approve step data
|
|
91
|
+
* */
|
|
92
|
+
protected abstract getSubmitStep(params: OptimalYieldPathParams): Promise<YieldStepBaseInfo>;
|
|
93
|
+
/** Generate the optimal steps to join pool */
|
|
94
|
+
generateOptimalPath(params: OptimalYieldPathParams): Promise<OptimalYieldPath>;
|
|
95
|
+
/** Validate param to join the pool */
|
|
96
|
+
abstract validateYieldJoin(data: SubmitYieldJoinData, path: OptimalYieldPath): Promise<TransactionError[]>;
|
|
97
|
+
/** Create `transaction` to join the pool step-by-step */
|
|
98
|
+
abstract handleYieldJoin(data: SubmitYieldJoinData, path: OptimalYieldPath, currentStep: number): Promise<HandleYieldStepData>;
|
|
99
|
+
/** Validate param to leave the pool */
|
|
100
|
+
abstract validateYieldLeave(amount: string, address: string, fastLeave: boolean, selectedTarget?: string): Promise<TransactionError[]>;
|
|
101
|
+
/** Create `transaction` to leave the pool normal (default unstake) */
|
|
102
|
+
protected abstract handleYieldUnstake(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
103
|
+
/** Create `transaction` to leave the pool fast (swap token) */
|
|
104
|
+
protected abstract handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
105
|
+
/** Create `transaction` to leave the pool */
|
|
106
|
+
handleYieldLeave(fastLeave: boolean, amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
107
|
+
/** Create `transaction` to withdraw unstaked amount */
|
|
108
|
+
abstract handleYieldWithdraw(address: string, unstakingInfo: UnstakingInfo): Promise<TransactionData>;
|
|
109
|
+
/** Create `transaction` to cancel unstake */
|
|
110
|
+
abstract handleYieldCancelUnstake(params: StakeCancelWithdrawalParams): Promise<TransactionData>;
|
|
111
|
+
/** Create `transaction` to claim reward */
|
|
112
|
+
abstract handleYieldClaimReward(address: string, bondReward?: boolean): Promise<TransactionData>;
|
|
113
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
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 { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
6
|
+
import { DEFAULT_YIELD_FIRST_STEP } from '@subwallet/extension-base/services/earning-service/constants';
|
|
7
|
+
import { formatNumber } from '@subwallet/extension-base/utils';
|
|
8
|
+
import { BN, BN_TEN } from '@polkadot/util';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @class BasePoolHandler
|
|
12
|
+
* @description Base pool handler
|
|
13
|
+
* */
|
|
14
|
+
export default class BasePoolHandler {
|
|
15
|
+
/** Koni state */
|
|
16
|
+
|
|
17
|
+
/** Pool's chain */
|
|
18
|
+
|
|
19
|
+
/** Pool's logo */
|
|
20
|
+
|
|
21
|
+
/** Pool's slug */
|
|
22
|
+
|
|
23
|
+
/** Pool's type */
|
|
24
|
+
|
|
25
|
+
/** Pool's name */
|
|
26
|
+
|
|
27
|
+
/** Pool's short name */
|
|
28
|
+
|
|
29
|
+
/** Pool's transaction type */
|
|
30
|
+
transactionChainType = ChainType.SUBSTRATE;
|
|
31
|
+
|
|
32
|
+
/** Pool's available method */
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @constructor
|
|
36
|
+
* @param {KoniState} state - Koni state
|
|
37
|
+
* @param {string} chain - Pool's chain
|
|
38
|
+
* */
|
|
39
|
+
constructor(state, chain) {
|
|
40
|
+
this.state = state;
|
|
41
|
+
this.chain = chain;
|
|
42
|
+
this._logo = chain;
|
|
43
|
+
}
|
|
44
|
+
get logo() {
|
|
45
|
+
return this._logo;
|
|
46
|
+
}
|
|
47
|
+
get group() {
|
|
48
|
+
const groupSlug = this.nativeToken.multiChainAsset;
|
|
49
|
+
return groupSlug || this.nativeToken.slug;
|
|
50
|
+
}
|
|
51
|
+
get isActive() {
|
|
52
|
+
return this.state.activeChainSlugs.includes(this.chain);
|
|
53
|
+
}
|
|
54
|
+
get substrateApi() {
|
|
55
|
+
return this.state.getSubstrateApi(this.chain);
|
|
56
|
+
}
|
|
57
|
+
get evmApi() {
|
|
58
|
+
return this.state.getEvmApi(this.chain);
|
|
59
|
+
}
|
|
60
|
+
get chainInfo() {
|
|
61
|
+
return this.state.getChainInfo(this.chain);
|
|
62
|
+
}
|
|
63
|
+
get nativeToken() {
|
|
64
|
+
return this.state.getNativeTokenInfo(this.chain);
|
|
65
|
+
}
|
|
66
|
+
get baseInfo() {
|
|
67
|
+
return {
|
|
68
|
+
group: this.group,
|
|
69
|
+
chain: this.chain,
|
|
70
|
+
slug: this.slug
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
getAssetBySlug(slug) {
|
|
74
|
+
return this.state.getAssetBySlug(slug);
|
|
75
|
+
}
|
|
76
|
+
get maintainBalance() {
|
|
77
|
+
const decimals = this.nativeToken.decimals || 0;
|
|
78
|
+
const defaultMaintainBalance = new BN(1).mul(BN_TEN.pow(new BN(decimals)));
|
|
79
|
+
const ed = new BN(this.nativeToken.minAmount || '0');
|
|
80
|
+
const maintainBalance = ed.gte(defaultMaintainBalance) ? new BN(15).mul(ed).div(BN_TEN) : defaultMaintainBalance;
|
|
81
|
+
return maintainBalance.toString();
|
|
82
|
+
}
|
|
83
|
+
get metadataInfo() {
|
|
84
|
+
return {
|
|
85
|
+
name: this.name,
|
|
86
|
+
shortName: this.shortName,
|
|
87
|
+
logo: this.logo,
|
|
88
|
+
inputAsset: this.nativeToken.slug,
|
|
89
|
+
isAvailable: true,
|
|
90
|
+
maintainAsset: this.nativeToken.slug,
|
|
91
|
+
maintainBalance: this.maintainBalance,
|
|
92
|
+
availableMethod: this.availableMethod
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Can mint when haven't enough native token (use input token for fee) */
|
|
97
|
+
get isPoolSupportAlternativeFee() {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
async getPoolInfo() {
|
|
101
|
+
return await this.state.earningService.getYieldPool(this.slug);
|
|
102
|
+
}
|
|
103
|
+
async getPoolPosition(address) {
|
|
104
|
+
return await this.state.earningService.getYieldPosition(address, this.slug);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* Subscribe data */
|
|
108
|
+
|
|
109
|
+
/** Subscribe pool info */
|
|
110
|
+
|
|
111
|
+
/* Subscribe data */
|
|
112
|
+
|
|
113
|
+
/* Join action */
|
|
114
|
+
|
|
115
|
+
/* Early validate */
|
|
116
|
+
|
|
117
|
+
async earlyValidate(request) {
|
|
118
|
+
var _poolInfo$statistic, _poolInfo$statistic2, _poolInfo$statistic2$;
|
|
119
|
+
const poolInfo = await this.getPoolInfo();
|
|
120
|
+
if (!poolInfo || !((_poolInfo$statistic = poolInfo.statistic) !== null && _poolInfo$statistic !== void 0 && _poolInfo$statistic.earningThreshold.join)) {
|
|
121
|
+
return {
|
|
122
|
+
passed: false,
|
|
123
|
+
errorMessage: 'There is a problem fetching your data. Check your Internet connection or change the network endpoint and try again.'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (request.address === ALL_ACCOUNT_KEY) {
|
|
127
|
+
return {
|
|
128
|
+
passed: true
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(this.chain);
|
|
132
|
+
const nativeTokenBalance = await this.state.balanceService.getTokenFreeBalance(request.address, this.chain);
|
|
133
|
+
const bnNativeTokenBalance = new BN(nativeTokenBalance.value);
|
|
134
|
+
const bnMinBalanceToJoin = new 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 BN(poolInfo.metadata.maintainBalance));
|
|
135
|
+
if (bnNativeTokenBalance.lte(bnMinBalanceToJoin)) {
|
|
136
|
+
const minJoin = formatNumber(bnMinBalanceToJoin.toString(), this.nativeToken.decimals || 0);
|
|
137
|
+
const originChain = this.state.getChainInfo(nativeTokenInfo.originChain);
|
|
138
|
+
return {
|
|
139
|
+
passed: false,
|
|
140
|
+
errorMessage: `You need at least ${minJoin} ${nativeTokenInfo.symbol} (${originChain.name}) to start earning`
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
passed: true
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* Early validate */
|
|
149
|
+
|
|
150
|
+
/* Generate steps */
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @function firstStepFee
|
|
154
|
+
* */
|
|
155
|
+
get firstStepFee() {
|
|
156
|
+
return {
|
|
157
|
+
slug: ''
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @function defaultSubmitStep
|
|
163
|
+
* @description Default submit step data
|
|
164
|
+
* */
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @async
|
|
168
|
+
* @function getTokenApproveStep
|
|
169
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
170
|
+
* @description Generate token approve step data
|
|
171
|
+
* */
|
|
172
|
+
async getTokenApproveStep(params) {
|
|
173
|
+
return Promise.resolve(undefined);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @async
|
|
178
|
+
* @function getXcmStep
|
|
179
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
180
|
+
* @description Generate token approve step data
|
|
181
|
+
* */
|
|
182
|
+
async getXcmStep(params) {
|
|
183
|
+
return Promise.resolve(undefined);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @async
|
|
188
|
+
* @function getSubmitStep
|
|
189
|
+
* @param {OptimalYieldPathParams} params - base param to join pool
|
|
190
|
+
* @description Generate token approve step data
|
|
191
|
+
* */
|
|
192
|
+
|
|
193
|
+
/** Generate the optimal steps to join pool */
|
|
194
|
+
async generateOptimalPath(params) {
|
|
195
|
+
const result = {
|
|
196
|
+
totalFee: [this.firstStepFee],
|
|
197
|
+
steps: [DEFAULT_YIELD_FIRST_STEP]
|
|
198
|
+
};
|
|
199
|
+
try {
|
|
200
|
+
const stepFunctions = [this.getTokenApproveStep, this.getXcmStep, this.getSubmitStep];
|
|
201
|
+
for (const stepFunction of stepFunctions) {
|
|
202
|
+
const step = await stepFunction.bind(this, params)();
|
|
203
|
+
if (step) {
|
|
204
|
+
const [info, fee] = step;
|
|
205
|
+
result.steps.push({
|
|
206
|
+
id: result.steps.length,
|
|
207
|
+
...info
|
|
208
|
+
});
|
|
209
|
+
result.totalFee.push(fee);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
} catch (e) {
|
|
214
|
+
const errorMessage = e.message;
|
|
215
|
+
if (errorMessage.includes('network')) {
|
|
216
|
+
result.connectionError = errorMessage.split(' ')[0];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/* Submit step */
|
|
220
|
+
|
|
221
|
+
const [step, fee] = this.defaultSubmitStep;
|
|
222
|
+
result.steps.push({
|
|
223
|
+
id: result.steps.length,
|
|
224
|
+
...step
|
|
225
|
+
});
|
|
226
|
+
result.totalFee.push(fee);
|
|
227
|
+
|
|
228
|
+
/* Submit step */
|
|
229
|
+
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* Generate steps */
|
|
235
|
+
|
|
236
|
+
/* Validate */
|
|
237
|
+
|
|
238
|
+
/** Validate param to join the pool */
|
|
239
|
+
|
|
240
|
+
/** Create `transaction` to leave the pool */
|
|
241
|
+
async handleYieldLeave(fastLeave, amount, address, selectedTarget) {
|
|
242
|
+
if (fastLeave) {
|
|
243
|
+
return this.handleYieldRedeem(amount, address, selectedTarget);
|
|
244
|
+
} else {
|
|
245
|
+
return this.handleYieldUnstake(amount, address, selectedTarget);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/* Leave action */
|
|
250
|
+
|
|
251
|
+
/* Other actions */
|
|
252
|
+
|
|
253
|
+
/** Create `transaction` to withdraw unstaked amount */
|
|
254
|
+
|
|
255
|
+
/* Other actions */
|
|
256
|
+
}
|
|
@@ -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,8 @@
|
|
|
1
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
2
|
+
import { LendingYieldPoolInfo, YieldPoolType } from '@subwallet/extension-base/types';
|
|
3
|
+
import BaseSpecialStakingPoolHandler from '../special';
|
|
4
|
+
export default abstract class BaseLendingPoolHandler extends BaseSpecialStakingPoolHandler {
|
|
5
|
+
readonly type = YieldPoolType.LENDING;
|
|
6
|
+
abstract getPoolStat(): Promise<LendingYieldPoolInfo>;
|
|
7
|
+
validateYieldLeave(amount: string, address: string, fastLeave: boolean, selectedTarget?: string): Promise<TransactionError[]>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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, StakingTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
+
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
7
|
+
import { BN_ZERO, formatNumber } from '@subwallet/extension-base/utils';
|
|
8
|
+
import BigN from 'bignumber.js';
|
|
9
|
+
import { t } from 'i18next';
|
|
10
|
+
import BaseSpecialStakingPoolHandler from "../special.js";
|
|
11
|
+
export default class BaseLendingPoolHandler extends BaseSpecialStakingPoolHandler {
|
|
12
|
+
type = YieldPoolType.LENDING;
|
|
13
|
+
|
|
14
|
+
/* Subscribe pool info */
|
|
15
|
+
|
|
16
|
+
/* Subscribe pool info */
|
|
17
|
+
|
|
18
|
+
/* Leave pool action */
|
|
19
|
+
|
|
20
|
+
async validateYieldLeave(amount, address, fastLeave, selectedTarget) {
|
|
21
|
+
const poolInfo = await this.getPoolInfo();
|
|
22
|
+
const poolPosition = await this.getPoolPosition(address);
|
|
23
|
+
if (!poolInfo || !poolInfo.statistic || !poolPosition) {
|
|
24
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
25
|
+
}
|
|
26
|
+
if (!this.availableMethod.defaultUnstake && !fastLeave) {
|
|
27
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
28
|
+
}
|
|
29
|
+
if (!this.availableMethod.fastUnstake && fastLeave) {
|
|
30
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
31
|
+
}
|
|
32
|
+
const errors = [];
|
|
33
|
+
const bnActiveStake = new BigN(poolPosition.activeStake).multipliedBy(poolInfo.statistic.assetEarning[0].exchangeRate || 1);
|
|
34
|
+
const bnAmount = new BigN(amount);
|
|
35
|
+
const bnRemainingStake = bnActiveStake.minus(bnAmount);
|
|
36
|
+
const minStake = new BigN(poolInfo.statistic.earningThreshold.join || '0');
|
|
37
|
+
const minUnstake = new BigN((fastLeave ? poolInfo.statistic.earningThreshold.fastUnstake : poolInfo.statistic.earningThreshold.defaultUnstake) || '0');
|
|
38
|
+
const maxUnstakeRequest = poolInfo.statistic.maxWithdrawalRequestPerFarmer;
|
|
39
|
+
const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
|
|
40
|
+
if (bnAmount.lte(BN_ZERO)) {
|
|
41
|
+
return [new TransactionError(BasicTxErrorType.INVALID_PARAMS, t('Amount must be greater than 0'))];
|
|
42
|
+
}
|
|
43
|
+
if (bnAmount.lt(minUnstake)) {
|
|
44
|
+
const minUnstakeStr = formatNumber(minUnstake.toString(), derivativeTokenInfo.decimals || 0);
|
|
45
|
+
errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_UNSTAKE, t('You need to unstake at least {{amount}} {{token}}', {
|
|
46
|
+
replace: {
|
|
47
|
+
amount: minUnstakeStr,
|
|
48
|
+
token: derivativeTokenInfo.symbol
|
|
49
|
+
}
|
|
50
|
+
})));
|
|
51
|
+
}
|
|
52
|
+
if (!fastLeave) {
|
|
53
|
+
if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
|
|
54
|
+
errors.push(new TransactionError(StakingTxErrorType.INVALID_ACTIVE_STAKE)); // TODO
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (poolPosition.unstakings.length > maxUnstakeRequest) {
|
|
58
|
+
errors.push(new TransactionError(StakingTxErrorType.EXCEED_MAX_UNSTAKING, t('You cannot unstake more than {{number}} times', {
|
|
59
|
+
replace: {
|
|
60
|
+
number: maxUnstakeRequest
|
|
61
|
+
}
|
|
62
|
+
})));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (bnRemainingStake.lt(0)) {
|
|
66
|
+
errors.push(new TransactionError(StakingTxErrorType.INVALID_ACTIVE_STAKE)); // TODO
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return Promise.resolve(errors);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* Leave pool action */
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as InterlayLendingPoolHandler } from './interlay';
|
|
@@ -0,0 +1,24 @@
|
|
|
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, YieldPoolMethodInfo, YieldPositionInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
|
|
4
|
+
import BaseLendingPoolHandler from './base';
|
|
5
|
+
export default class InterlayLendingPoolHandler extends BaseLendingPoolHandler {
|
|
6
|
+
slug: string;
|
|
7
|
+
protected readonly name: string;
|
|
8
|
+
protected readonly shortName: string;
|
|
9
|
+
protected readonly altInputAsset: string;
|
|
10
|
+
protected readonly derivativeAssets: string[];
|
|
11
|
+
protected readonly inputAsset: string;
|
|
12
|
+
protected readonly rewardAssets: string[];
|
|
13
|
+
protected readonly feeAssets: string[];
|
|
14
|
+
protected readonly availableMethod: YieldPoolMethodInfo;
|
|
15
|
+
protected readonly rateDecimals = 18;
|
|
16
|
+
constructor(state: KoniState, chain: string);
|
|
17
|
+
protected getDescription(): string;
|
|
18
|
+
getPoolStat(): Promise<LendingYieldPoolInfo>;
|
|
19
|
+
subscribePoolPosition(useAddresses: string[], resultCallback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
|
|
20
|
+
get submitJoinStepInfo(): BaseYieldStepDetail;
|
|
21
|
+
getSubmitStepFee(params: OptimalYieldPathParams): Promise<YieldTokenBaseInfo>;
|
|
22
|
+
handleSubmitStep(data: SubmitYieldJoinData, path: OptimalYieldPath): Promise<HandleYieldStepData>;
|
|
23
|
+
handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
24
|
+
}
|