@subwallet/extension-base 1.1.31-0 → 1.1.31-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 +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 +11 -1
- package/cjs/koni/background/handlers/Extension.js +362 -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 +95 -37
- 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/index.js +3 -2
- 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 +259 -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 +191 -0
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +239 -0
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +43 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +297 -0
- package/cjs/services/earning-service/handlers/liquid-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +226 -0
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +395 -0
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +384 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +461 -0
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +146 -0
- package/cjs/services/earning-service/handlers/native-staking/base.js +159 -0
- package/cjs/services/earning-service/handlers/native-staking/index.js +34 -0
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +385 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +558 -0
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +560 -0
- package/cjs/services/earning-service/handlers/special.js +503 -0
- package/cjs/services/earning-service/service.js +387 -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/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 +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/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 +231 -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/fetchStaticData.js +2 -1
- package/cjs/utils/index.js +89 -1
- package/cjs/utils/keyring.js +57 -0
- package/cjs/utils/number.js +3 -1
- 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 +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.d.ts +1 -0
- package/koni/background/cron.js +12 -2
- package/koni/background/handlers/Extension.d.ts +17 -1
- package/koni/background/handlers/Extension.js +321 -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 +6 -1
- package/koni/background/subscription.js +97 -38
- package/package.json +321 -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/index.js +3 -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 +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 +112 -0
- package/services/earning-service/handlers/base.js +253 -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 +24 -0
- package/services/earning-service/handlers/lending/interlay.js +183 -0
- package/services/earning-service/handlers/liquid-staking/acala.d.ts +27 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +231 -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 +46 -0
- package/services/earning-service/handlers/liquid-staking/bifrost.js +286 -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 +218 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +34 -0
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +385 -0
- package/services/earning-service/handlers/native-staking/amplitude.d.ts +22 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +375 -0
- package/services/earning-service/handlers/native-staking/astar.d.ts +19 -0
- package/services/earning-service/handlers/native-staking/astar.js +451 -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 +150 -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 +377 -0
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +21 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +549 -0
- package/services/earning-service/handlers/nomination-pool/index.d.ts +36 -0
- package/services/earning-service/handlers/nomination-pool/index.js +550 -0
- package/services/earning-service/handlers/special.d.ts +65 -0
- package/services/earning-service/handlers/special.js +495 -0
- package/services/earning-service/service.d.ts +45 -0
- package/services/earning-service/service.js +379 -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 +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 +4 -15
- package/services/transaction-service/index.js +229 -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 +57 -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 +45 -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 +251 -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/number.d.ts +1 -1
- package/utils/number.js +1 -1
- package/utils/object.d.ts +1 -0
- package/utils/object.js +6 -0
|
@@ -0,0 +1,379 @@
|
|
|
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 } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
+
import { _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
+
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants';
|
|
8
|
+
import BaseLiquidStakingPoolHandler from '@subwallet/extension-base/services/earning-service/handlers/liquid-staking/base';
|
|
9
|
+
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
10
|
+
import { categoryAddresses } from '@subwallet/extension-base/utils';
|
|
11
|
+
import { BehaviorSubject } from 'rxjs';
|
|
12
|
+
import { AcalaLiquidStakingPoolHandler, AmplitudeNativeStakingPoolHandler, AstarNativeStakingPoolHandler, BifrostLiquidStakingPoolHandler, InterlayLendingPoolHandler, NominationPoolHandler, ParallelLiquidStakingPoolHandler, ParaNativeStakingPoolHandler, RelayNativeStakingPoolHandler, StellaSwapLiquidStakingPoolHandler } from "./handlers/index.js";
|
|
13
|
+
export default class EarningService {
|
|
14
|
+
handlers = {};
|
|
15
|
+
earningRewardSubject = new BehaviorSubject({
|
|
16
|
+
ready: false,
|
|
17
|
+
data: {}
|
|
18
|
+
});
|
|
19
|
+
earningRewardHistorySubject = new BehaviorSubject({});
|
|
20
|
+
minAmountPercentSubject = new BehaviorSubject({});
|
|
21
|
+
constructor(state) {
|
|
22
|
+
this.state = state;
|
|
23
|
+
this.initHandlers().catch(console.error);
|
|
24
|
+
}
|
|
25
|
+
async initHandlers() {
|
|
26
|
+
await this.state.eventService.waitChainReady;
|
|
27
|
+
const chains = Object.keys(this.state.getChainInfoMap());
|
|
28
|
+
const minAmountPercent = {};
|
|
29
|
+
for (const chain of chains) {
|
|
30
|
+
const handlers = [];
|
|
31
|
+
if (_STAKING_CHAIN_GROUP.relay.includes(chain)) {
|
|
32
|
+
handlers.push(new RelayNativeStakingPoolHandler(this.state, chain));
|
|
33
|
+
}
|
|
34
|
+
if (_STAKING_CHAIN_GROUP.para.includes(chain)) {
|
|
35
|
+
handlers.push(new ParaNativeStakingPoolHandler(this.state, chain));
|
|
36
|
+
}
|
|
37
|
+
if (_STAKING_CHAIN_GROUP.astar.includes(chain)) {
|
|
38
|
+
handlers.push(new AstarNativeStakingPoolHandler(this.state, chain));
|
|
39
|
+
}
|
|
40
|
+
if (_STAKING_CHAIN_GROUP.amplitude.includes(chain)) {
|
|
41
|
+
handlers.push(new AmplitudeNativeStakingPoolHandler(this.state, chain));
|
|
42
|
+
}
|
|
43
|
+
if (_STAKING_CHAIN_GROUP.nominationPool.includes(chain)) {
|
|
44
|
+
handlers.push(new NominationPoolHandler(this.state, chain));
|
|
45
|
+
}
|
|
46
|
+
if (_STAKING_CHAIN_GROUP.liquidStaking.includes(chain)) {
|
|
47
|
+
if (chain === 'bifrost_dot') {
|
|
48
|
+
handlers.push(new BifrostLiquidStakingPoolHandler(this.state, chain));
|
|
49
|
+
}
|
|
50
|
+
if (chain === 'acala') {
|
|
51
|
+
handlers.push(new AcalaLiquidStakingPoolHandler(this.state, chain));
|
|
52
|
+
}
|
|
53
|
+
if (chain === 'parallel') {
|
|
54
|
+
handlers.push(new ParallelLiquidStakingPoolHandler(this.state, chain));
|
|
55
|
+
}
|
|
56
|
+
if (chain === 'moonbeam') {
|
|
57
|
+
handlers.push(new StellaSwapLiquidStakingPoolHandler(this.state, chain));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (_STAKING_CHAIN_GROUP.lending.includes(chain)) {
|
|
61
|
+
if (chain === 'interlay') {
|
|
62
|
+
handlers.push(new InterlayLendingPoolHandler(this.state, chain));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const handler of handlers) {
|
|
66
|
+
this.handlers[handler.slug] = handler;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const handler of Object.values(this.handlers)) {
|
|
70
|
+
if (handler.type === YieldPoolType.LIQUID_STAKING) {
|
|
71
|
+
minAmountPercent[handler.slug] = handler.minAmountPercent;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
minAmountPercent.default = BaseLiquidStakingPoolHandler.defaultMinAmountPercent;
|
|
75
|
+
this.minAmountPercentSubject.next(minAmountPercent);
|
|
76
|
+
}
|
|
77
|
+
getPoolHandler(slug) {
|
|
78
|
+
return this.handlers[slug];
|
|
79
|
+
}
|
|
80
|
+
isPoolSupportAlternativeFee(slug) {
|
|
81
|
+
const handler = this.getPoolHandler(slug);
|
|
82
|
+
if (handler) {
|
|
83
|
+
return handler.isPoolSupportAlternativeFee;
|
|
84
|
+
} else {
|
|
85
|
+
throw new TransactionError(BasicTxErrorType.INTERNAL_ERROR);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
subscribeMinAmountPercent() {
|
|
89
|
+
return this.minAmountPercentSubject;
|
|
90
|
+
}
|
|
91
|
+
getMinAmountPercent() {
|
|
92
|
+
return this.minAmountPercentSubject.getValue();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Subscribe pools' info */
|
|
96
|
+
|
|
97
|
+
async subscribePoolsInfo(callback) {
|
|
98
|
+
let cancel = false;
|
|
99
|
+
await this.state.eventService.waitChainReady;
|
|
100
|
+
const unsubList = [];
|
|
101
|
+
for (const handler of Object.values(this.handlers)) {
|
|
102
|
+
handler.subscribePoolInfo(callback).then(unsub => {
|
|
103
|
+
if (cancel) {
|
|
104
|
+
unsub();
|
|
105
|
+
} else {
|
|
106
|
+
unsubList.push(unsub);
|
|
107
|
+
}
|
|
108
|
+
}).catch(console.error);
|
|
109
|
+
}
|
|
110
|
+
return () => {
|
|
111
|
+
cancel = true;
|
|
112
|
+
unsubList.forEach(unsub => {
|
|
113
|
+
unsub === null || unsub === void 0 ? void 0 : unsub();
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* Subscribe pools' info */
|
|
119
|
+
|
|
120
|
+
/* Subscribe pools' position */
|
|
121
|
+
|
|
122
|
+
async subscribePoolPositions(addresses, callback) {
|
|
123
|
+
let cancel = false;
|
|
124
|
+
await this.state.eventService.waitChainReady;
|
|
125
|
+
const [substrateAddresses, evmAddresses] = categoryAddresses(addresses);
|
|
126
|
+
const activeChains = this.state.activeChainSlugs;
|
|
127
|
+
const unsubList = [];
|
|
128
|
+
for (const handler of Object.values(this.handlers)) {
|
|
129
|
+
if (activeChains.includes(handler.chain)) {
|
|
130
|
+
const chainInfo = handler.chainInfo;
|
|
131
|
+
const useAddresses = _isChainEvmCompatible(chainInfo) ? evmAddresses : substrateAddresses;
|
|
132
|
+
handler.subscribePoolPosition(useAddresses, callback).then(unsub => {
|
|
133
|
+
if (cancel) {
|
|
134
|
+
unsub();
|
|
135
|
+
} else {
|
|
136
|
+
unsubList.push(unsub);
|
|
137
|
+
}
|
|
138
|
+
}).catch(console.error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return () => {
|
|
142
|
+
cancel = true;
|
|
143
|
+
unsubList.forEach(unsub => {
|
|
144
|
+
unsub === null || unsub === void 0 ? void 0 : unsub();
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* Subscribe pools' position */
|
|
150
|
+
|
|
151
|
+
/* Get pools' reward */
|
|
152
|
+
|
|
153
|
+
updateEarningReward(stakingRewardData) {
|
|
154
|
+
const stakingRewardState = this.earningRewardSubject.getValue();
|
|
155
|
+
stakingRewardState.ready = true;
|
|
156
|
+
const key = `${stakingRewardData.slug}---${stakingRewardData.address}`;
|
|
157
|
+
stakingRewardState.data[key] = stakingRewardData;
|
|
158
|
+
this.earningRewardSubject.next(stakingRewardState);
|
|
159
|
+
}
|
|
160
|
+
async getPoolReward(addresses, callback) {
|
|
161
|
+
let cancel = false;
|
|
162
|
+
await this.state.eventService.waitChainReady;
|
|
163
|
+
const [substrateAddresses, evmAddresses] = categoryAddresses(addresses);
|
|
164
|
+
const activeChains = this.state.activeChainSlugs;
|
|
165
|
+
const unsubList = [];
|
|
166
|
+
for (const handler of Object.values(this.handlers)) {
|
|
167
|
+
if (activeChains.includes(handler.chain)) {
|
|
168
|
+
const chainInfo = handler.chainInfo;
|
|
169
|
+
const useAddresses = _isChainEvmCompatible(chainInfo) ? evmAddresses : substrateAddresses;
|
|
170
|
+
handler.getPoolReward(useAddresses, callback).then(unsub => {
|
|
171
|
+
if (cancel) {
|
|
172
|
+
unsub();
|
|
173
|
+
} else {
|
|
174
|
+
unsubList.push(unsub);
|
|
175
|
+
}
|
|
176
|
+
}).catch(console.error);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return () => {
|
|
180
|
+
cancel = true;
|
|
181
|
+
unsubList.forEach(unsub => {
|
|
182
|
+
unsub === null || unsub === void 0 ? void 0 : unsub();
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
subscribeEarningReward() {
|
|
187
|
+
return this.earningRewardSubject;
|
|
188
|
+
}
|
|
189
|
+
getEarningRewards() {
|
|
190
|
+
return this.earningRewardSubject.getValue();
|
|
191
|
+
}
|
|
192
|
+
async fetchPoolRewardHistory(addresses, callback) {
|
|
193
|
+
let cancel = false;
|
|
194
|
+
await this.state.eventService.waitChainReady;
|
|
195
|
+
const [substrateAddresses, evmAddresses] = categoryAddresses(addresses);
|
|
196
|
+
const activeChains = this.state.activeChainSlugs;
|
|
197
|
+
const unsubList = [];
|
|
198
|
+
for (const handler of Object.values(this.handlers)) {
|
|
199
|
+
if (activeChains.includes(handler.chain)) {
|
|
200
|
+
const chainInfo = handler.chainInfo;
|
|
201
|
+
const useAddresses = _isChainEvmCompatible(chainInfo) ? evmAddresses : substrateAddresses;
|
|
202
|
+
handler.getPoolRewardHistory(useAddresses, callback).then(unsub => {
|
|
203
|
+
if (cancel) {
|
|
204
|
+
unsub();
|
|
205
|
+
} else {
|
|
206
|
+
unsubList.push(unsub);
|
|
207
|
+
}
|
|
208
|
+
}).catch(console.error);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return () => {
|
|
212
|
+
cancel = true;
|
|
213
|
+
unsubList.forEach(unsub => {
|
|
214
|
+
unsub === null || unsub === void 0 ? void 0 : unsub();
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
updateEarningRewardHistory(earningRewardHistory) {
|
|
219
|
+
const earningRewardHistoryState = this.earningRewardHistorySubject.getValue();
|
|
220
|
+
const key = `${earningRewardHistory.slug}---${earningRewardHistory.address}---${earningRewardHistory.blockTimestamp}`;
|
|
221
|
+
earningRewardHistoryState[key] = earningRewardHistory;
|
|
222
|
+
this.earningRewardHistorySubject.next(earningRewardHistoryState);
|
|
223
|
+
}
|
|
224
|
+
subscribeEarningRewardHistory() {
|
|
225
|
+
return this.earningRewardHistorySubject;
|
|
226
|
+
}
|
|
227
|
+
getEarningRewardHistory() {
|
|
228
|
+
return this.earningRewardHistorySubject.getValue();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/* Get pools' reward */
|
|
232
|
+
|
|
233
|
+
/* Get pool's targets */
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @async
|
|
237
|
+
* @function getPoolTargets
|
|
238
|
+
* @param {string} slug - Pool's slug
|
|
239
|
+
* @return {Promise<YieldPoolTarget[]>} List of pool's target
|
|
240
|
+
* */
|
|
241
|
+
async getPoolTargets(slug) {
|
|
242
|
+
await this.state.eventService.waitChainReady;
|
|
243
|
+
const handler = this.getPoolHandler(slug);
|
|
244
|
+
if (handler) {
|
|
245
|
+
return await handler.getPoolTargets();
|
|
246
|
+
} else {
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/* Get pool's targets */
|
|
252
|
+
|
|
253
|
+
/* Handle actions */
|
|
254
|
+
|
|
255
|
+
/* Join */
|
|
256
|
+
|
|
257
|
+
async earlyValidateJoin(request) {
|
|
258
|
+
await this.state.eventService.waitChainReady;
|
|
259
|
+
const {
|
|
260
|
+
slug
|
|
261
|
+
} = request;
|
|
262
|
+
const handler = this.getPoolHandler(slug);
|
|
263
|
+
if (handler) {
|
|
264
|
+
return handler.earlyValidate(request);
|
|
265
|
+
} else {
|
|
266
|
+
throw new TransactionError(BasicTxErrorType.INTERNAL_ERROR);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async generateOptimalSteps(params) {
|
|
270
|
+
await this.state.eventService.waitChainReady;
|
|
271
|
+
const {
|
|
272
|
+
slug
|
|
273
|
+
} = params;
|
|
274
|
+
const handler = this.getPoolHandler(slug);
|
|
275
|
+
if (handler) {
|
|
276
|
+
return handler.generateOptimalPath(params);
|
|
277
|
+
} else {
|
|
278
|
+
throw new TransactionError(BasicTxErrorType.INTERNAL_ERROR);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async validateYieldJoin(params) {
|
|
282
|
+
await this.state.eventService.waitChainReady;
|
|
283
|
+
const {
|
|
284
|
+
slug
|
|
285
|
+
} = params.data;
|
|
286
|
+
const handler = this.getPoolHandler(slug);
|
|
287
|
+
if (handler) {
|
|
288
|
+
return handler.validateYieldJoin(params.data, params.path);
|
|
289
|
+
} else {
|
|
290
|
+
return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
async handleYieldJoin(params) {
|
|
294
|
+
await this.state.eventService.waitChainReady;
|
|
295
|
+
const {
|
|
296
|
+
slug
|
|
297
|
+
} = params.data;
|
|
298
|
+
const handler = this.getPoolHandler(slug);
|
|
299
|
+
if (handler) {
|
|
300
|
+
return handler.handleYieldJoin(params.data, params.path, params.currentStep);
|
|
301
|
+
} else {
|
|
302
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/* Join */
|
|
307
|
+
|
|
308
|
+
/* Leave */
|
|
309
|
+
|
|
310
|
+
async validateYieldLeave(params) {
|
|
311
|
+
await this.state.eventService.waitChainReady;
|
|
312
|
+
const {
|
|
313
|
+
slug
|
|
314
|
+
} = params;
|
|
315
|
+
const handler = this.getPoolHandler(slug);
|
|
316
|
+
if (handler) {
|
|
317
|
+
return handler.validateYieldLeave(params.amount, params.address, params.fastLeave, params.selectedTarget);
|
|
318
|
+
} else {
|
|
319
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async handleYieldLeave(params) {
|
|
323
|
+
await this.state.eventService.waitChainReady;
|
|
324
|
+
const {
|
|
325
|
+
slug
|
|
326
|
+
} = params;
|
|
327
|
+
const handler = this.getPoolHandler(slug);
|
|
328
|
+
if (handler) {
|
|
329
|
+
return handler.handleYieldLeave(params.fastLeave, params.amount, params.address, params.selectedTarget);
|
|
330
|
+
} else {
|
|
331
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/* Leave */
|
|
336
|
+
|
|
337
|
+
/* Other */
|
|
338
|
+
|
|
339
|
+
async handleYieldWithdraw(params) {
|
|
340
|
+
await this.state.eventService.waitChainReady;
|
|
341
|
+
const {
|
|
342
|
+
slug
|
|
343
|
+
} = params;
|
|
344
|
+
const handler = this.getPoolHandler(slug);
|
|
345
|
+
if (handler) {
|
|
346
|
+
return handler.handleYieldWithdraw(params.address, params.unstakingInfo);
|
|
347
|
+
} else {
|
|
348
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async handleYieldCancelUnstake(params) {
|
|
352
|
+
await this.state.eventService.waitChainReady;
|
|
353
|
+
const {
|
|
354
|
+
slug
|
|
355
|
+
} = params;
|
|
356
|
+
const handler = this.getPoolHandler(slug);
|
|
357
|
+
if (handler) {
|
|
358
|
+
return handler.handleYieldCancelUnstake(params);
|
|
359
|
+
} else {
|
|
360
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
async handleYieldClaimReward(params) {
|
|
364
|
+
await this.state.eventService.waitChainReady;
|
|
365
|
+
const {
|
|
366
|
+
slug
|
|
367
|
+
} = params;
|
|
368
|
+
const handler = this.getPoolHandler(slug);
|
|
369
|
+
if (handler) {
|
|
370
|
+
return handler.handleYieldClaimReward(params.address, params.bondReward);
|
|
371
|
+
} else {
|
|
372
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/* Other */
|
|
377
|
+
|
|
378
|
+
/* Handle actions */
|
|
379
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
2
|
+
import { LendingYieldPoolInfo, LiquidYieldPoolInfo, NativeYieldPoolInfo, NominationYieldPoolInfo, YieldAssetExpectedEarning, YieldCompoundingPeriod, YieldPoolInfo, YieldPoolType } from '@subwallet/extension-base/types';
|
|
3
|
+
export declare function calculateReward(apr: number, amount?: number, compoundingPeriod?: YieldCompoundingPeriod, isApy?: boolean): YieldAssetExpectedEarning;
|
|
4
|
+
/**
|
|
5
|
+
* @returns
|
|
6
|
+
* <p>
|
|
7
|
+
* [0] - identity
|
|
8
|
+
* </p>
|
|
9
|
+
* <p>
|
|
10
|
+
* [1] - isReasonable (isVerified)
|
|
11
|
+
* </p>
|
|
12
|
+
* */
|
|
13
|
+
export declare function parseIdentity(substrateApi: _SubstrateApi, address: string, children?: string): Promise<[string | undefined, boolean]>;
|
|
14
|
+
export declare function isActionFromValidator(stakingType: YieldPoolType, chain: string): boolean;
|
|
15
|
+
export declare const isNominationPool: (pool: YieldPoolInfo) => pool is NominationYieldPoolInfo;
|
|
16
|
+
export declare const isNativeStakingPool: (pool: YieldPoolInfo) => pool is NativeYieldPoolInfo;
|
|
17
|
+
export declare const isLiquidPool: (pool: YieldPoolInfo) => pool is LiquidYieldPoolInfo;
|
|
18
|
+
export declare const isLendingPool: (pool: YieldPoolInfo) => pool is LendingYieldPoolInfo;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants';
|
|
5
|
+
import { YieldCompoundingPeriod, YieldPoolType } from '@subwallet/extension-base/types';
|
|
6
|
+
import { hexToString, isHex } from '@polkadot/util';
|
|
7
|
+
export function calculateReward(apr, amount = 0, compoundingPeriod = YieldCompoundingPeriod.YEARLY, isApy = false) {
|
|
8
|
+
if (!apr) {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
if (!isApy) {
|
|
12
|
+
const periodApr = apr / 365 * compoundingPeriod; // APR is always annually
|
|
13
|
+
const earningRatio = periodApr / 100 / compoundingPeriod;
|
|
14
|
+
const periodApy = (1 + earningRatio) ** compoundingPeriod - 1;
|
|
15
|
+
const reward = periodApy * amount;
|
|
16
|
+
return {
|
|
17
|
+
apy: periodApy * 100,
|
|
18
|
+
rewardInToken: reward
|
|
19
|
+
};
|
|
20
|
+
} else {
|
|
21
|
+
const reward = apr / 100 * amount;
|
|
22
|
+
return {
|
|
23
|
+
apy: apr,
|
|
24
|
+
rewardInToken: reward * (compoundingPeriod / YieldCompoundingPeriod.YEARLY)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @returns
|
|
31
|
+
* <p>
|
|
32
|
+
* [0] - identity
|
|
33
|
+
* </p>
|
|
34
|
+
* <p>
|
|
35
|
+
* [1] - isReasonable (isVerified)
|
|
36
|
+
* </p>
|
|
37
|
+
* */
|
|
38
|
+
export async function parseIdentity(substrateApi, address, children) {
|
|
39
|
+
const compactResult = rs => {
|
|
40
|
+
const result = [];
|
|
41
|
+
if (rs) {
|
|
42
|
+
result.push(rs);
|
|
43
|
+
}
|
|
44
|
+
if (children) {
|
|
45
|
+
result.push(children);
|
|
46
|
+
}
|
|
47
|
+
if (result.length > 0) {
|
|
48
|
+
return result.join('/');
|
|
49
|
+
} else {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
if (substrateApi.api.query.identity) {
|
|
54
|
+
let identity;
|
|
55
|
+
const _parent = await substrateApi.api.query.identity.superOf(address);
|
|
56
|
+
const parentInfo = _parent.toHuman();
|
|
57
|
+
if (parentInfo) {
|
|
58
|
+
const [parentAddress, {
|
|
59
|
+
Raw: data
|
|
60
|
+
}] = parentInfo;
|
|
61
|
+
const child = isHex(data) ? hexToString(data) : data;
|
|
62
|
+
|
|
63
|
+
// TODO: Re-check
|
|
64
|
+
if (address !== parentAddress) {
|
|
65
|
+
const [rs, isReasonable] = await parseIdentity(substrateApi, parentAddress, child);
|
|
66
|
+
return [compactResult(rs), isReasonable];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const _identity = await substrateApi.api.query.identity.identityOf(address);
|
|
70
|
+
const identityInfo = _identity.toHuman();
|
|
71
|
+
if (identityInfo) {
|
|
72
|
+
var _identityInfo$info, _identityInfo$info$di, _identityInfo$info2, _identityInfo$info2$w, _identityInfo$info3, _identityInfo$info3$r, _identityInfo$info4, _identityInfo$info4$t;
|
|
73
|
+
const displayName = (_identityInfo$info = identityInfo.info) === null || _identityInfo$info === void 0 ? void 0 : (_identityInfo$info$di = _identityInfo$info.display) === null || _identityInfo$info$di === void 0 ? void 0 : _identityInfo$info$di.Raw;
|
|
74
|
+
const web = (_identityInfo$info2 = identityInfo.info) === null || _identityInfo$info2 === void 0 ? void 0 : (_identityInfo$info2$w = _identityInfo$info2.web) === null || _identityInfo$info2$w === void 0 ? void 0 : _identityInfo$info2$w.Raw;
|
|
75
|
+
const riot = (_identityInfo$info3 = identityInfo.info) === null || _identityInfo$info3 === void 0 ? void 0 : (_identityInfo$info3$r = _identityInfo$info3.riot) === null || _identityInfo$info3$r === void 0 ? void 0 : _identityInfo$info3$r.Raw;
|
|
76
|
+
const twitter = (_identityInfo$info4 = identityInfo.info) === null || _identityInfo$info4 === void 0 ? void 0 : (_identityInfo$info4$t = _identityInfo$info4.twitter) === null || _identityInfo$info4$t === void 0 ? void 0 : _identityInfo$info4$t.Raw;
|
|
77
|
+
const isReasonable = identityInfo.judgements.length > 0;
|
|
78
|
+
if (displayName) {
|
|
79
|
+
identity = isHex(displayName) ? hexToString(displayName) : displayName;
|
|
80
|
+
} else {
|
|
81
|
+
identity = twitter || web || riot;
|
|
82
|
+
}
|
|
83
|
+
return [compactResult(identity), isReasonable];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return [undefined, false];
|
|
87
|
+
}
|
|
88
|
+
export function isActionFromValidator(stakingType, chain) {
|
|
89
|
+
if (stakingType === YieldPoolType.NOMINATION_POOL || stakingType === YieldPoolType.LIQUID_STAKING || stakingType === YieldPoolType.LENDING) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (_STAKING_CHAIN_GROUP.astar.includes(chain)) {
|
|
93
|
+
return true;
|
|
94
|
+
} else if (_STAKING_CHAIN_GROUP.amplitude.includes(chain)) {
|
|
95
|
+
return true;
|
|
96
|
+
} else if (_STAKING_CHAIN_GROUP.para.includes(chain)) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
export const isNominationPool = pool => {
|
|
102
|
+
return pool.type === YieldPoolType.NOMINATION_POOL;
|
|
103
|
+
};
|
|
104
|
+
export const isNativeStakingPool = pool => {
|
|
105
|
+
return pool.type === YieldPoolType.NATIVE_STAKING;
|
|
106
|
+
};
|
|
107
|
+
export const isLiquidPool = pool => {
|
|
108
|
+
return pool.type === YieldPoolType.LIQUID_STAKING;
|
|
109
|
+
};
|
|
110
|
+
export const isLendingPool = pool => {
|
|
111
|
+
return pool.type === YieldPoolType.LENDING;
|
|
112
|
+
};
|
|
@@ -8,6 +8,7 @@ export declare class EventService extends EventEmitter<EventRegistry> {
|
|
|
8
8
|
readonly waitDatabaseReady: Promise<boolean>;
|
|
9
9
|
readonly waitKeyringReady: Promise<boolean>;
|
|
10
10
|
readonly waitAccountReady: Promise<boolean>;
|
|
11
|
+
readonly waitInjectReady: Promise<boolean>;
|
|
11
12
|
readonly waitChainReady: Promise<boolean>;
|
|
12
13
|
readonly waitAssetReady: Promise<boolean>;
|
|
13
14
|
readonly waitMigrateReady: Promise<boolean>;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
// Stateless service handle runtime event on background
|
|
5
5
|
|
|
6
|
+
import { TARGET_ENV } from '@subwallet/extension-base/utils';
|
|
6
7
|
import EventEmitter from 'eventemitter3';
|
|
7
8
|
const DEFAULT_LAZY_TIME = 300;
|
|
8
9
|
const LONG_LAZY_TIME = 900;
|
|
@@ -17,6 +18,8 @@ export class EventService extends EventEmitter {
|
|
|
17
18
|
this.waitDatabaseReady = this.generateWaitPromise('database.ready');
|
|
18
19
|
this.waitKeyringReady = this.generateWaitPromise('keyring.ready');
|
|
19
20
|
this.waitAccountReady = this.generateWaitPromise('account.ready');
|
|
21
|
+
// TODO: Need to merge logic on web-runner file
|
|
22
|
+
this.waitInjectReady = TARGET_ENV === 'webapp' ? this.generateWaitPromise('inject.ready') : Promise.resolve(true);
|
|
20
23
|
this.waitChainReady = this.generateWaitPromise('chain.ready');
|
|
21
24
|
this.waitAssetReady = this.generateWaitPromise('asset.ready');
|
|
22
25
|
this.waitMigrateReady = this.generateWaitPromise('migration.done');
|
|
@@ -27,6 +30,7 @@ export class EventService extends EventEmitter {
|
|
|
27
30
|
generateWaitPromise(eventType) {
|
|
28
31
|
return new Promise(resolve => {
|
|
29
32
|
this.once(eventType, isReady => {
|
|
33
|
+
console.log('===LOG generateWaitPromise eventType', eventType);
|
|
30
34
|
resolve(isReady);
|
|
31
35
|
});
|
|
32
36
|
});
|
|
@@ -5,12 +5,20 @@ export interface EventRegistry {
|
|
|
5
5
|
'general.wakeup': [boolean];
|
|
6
6
|
'crypto.ready': [boolean];
|
|
7
7
|
'database.ready': [boolean];
|
|
8
|
+
/** Password state ready */
|
|
8
9
|
'keyring.ready': [boolean];
|
|
10
|
+
/** Update current account */
|
|
9
11
|
'account.updateCurrent': [CurrentAccountInfo];
|
|
12
|
+
/** Account list loaded */
|
|
10
13
|
'account.ready': [boolean];
|
|
14
|
+
/** Add a new account */
|
|
11
15
|
'account.add': [string];
|
|
16
|
+
/** Update account */
|
|
12
17
|
'account.update': [string];
|
|
18
|
+
/** Remove a account */
|
|
13
19
|
'account.remove': [string];
|
|
20
|
+
/** Inject account done */
|
|
21
|
+
'inject.ready': [boolean];
|
|
14
22
|
'chain.ready': [boolean];
|
|
15
23
|
'chain.add': [string];
|
|
16
24
|
'chain.updateState': [string];
|
|
@@ -10,6 +10,7 @@ export declare class KeyringService {
|
|
|
10
10
|
readonly addressesSubject: BehaviorSubject<SubjectInfo>;
|
|
11
11
|
readonly accountSubject: BehaviorSubject<SubjectInfo>;
|
|
12
12
|
private beforeAccount;
|
|
13
|
+
private injected;
|
|
13
14
|
readonly keyringStateSubject: BehaviorSubject<KeyringState>;
|
|
14
15
|
constructor(eventService: EventService);
|
|
15
16
|
private subscribeAccounts;
|
|
@@ -21,6 +22,6 @@ export declare class KeyringService {
|
|
|
21
22
|
setCurrentAccount(currentAccountData: CurrentAccountInfo): void;
|
|
22
23
|
lock(): void;
|
|
23
24
|
addInjectAccounts(accounts: InjectedAccountWithMeta[]): void;
|
|
24
|
-
removeInjectAccounts(
|
|
25
|
+
removeInjectAccounts(_addresses: string[]): void;
|
|
25
26
|
resetWallet(resetAll: boolean): Promise<void>;
|
|
26
27
|
}
|
|
@@ -22,6 +22,7 @@ export class KeyringService {
|
|
|
22
22
|
});
|
|
23
23
|
constructor(eventService) {
|
|
24
24
|
this.eventService = eventService;
|
|
25
|
+
this.injected = false;
|
|
25
26
|
this.eventService.waitCryptoReady.then(() => {
|
|
26
27
|
this.currentAccountStore.get('CurrentAccountInfo', rs => {
|
|
27
28
|
rs && this.currentAccountSubject.next(rs);
|
|
@@ -133,8 +134,19 @@ export class KeyringService {
|
|
|
133
134
|
currentGenesisHash: null
|
|
134
135
|
});
|
|
135
136
|
}
|
|
137
|
+
if (!this.injected) {
|
|
138
|
+
this.eventService.emit('inject.ready', true);
|
|
139
|
+
this.injected = true;
|
|
140
|
+
}
|
|
136
141
|
}
|
|
137
|
-
removeInjectAccounts(
|
|
142
|
+
removeInjectAccounts(_addresses) {
|
|
143
|
+
const addresses = _addresses.map(address => {
|
|
144
|
+
try {
|
|
145
|
+
return keyring.getPair(address).address;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
return address;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
138
150
|
const currentAddress = this.currentAccountSubject.value.address;
|
|
139
151
|
const afterAccounts = Object.keys(this.accounts).filter(address => addresses.indexOf(address) < 0);
|
|
140
152
|
if (afterAccounts.length === 1) {
|
|
@@ -159,7 +171,7 @@ export class KeyringService {
|
|
|
159
171
|
await new Promise(resolve => {
|
|
160
172
|
setTimeout(() => {
|
|
161
173
|
resolve();
|
|
162
|
-
},
|
|
174
|
+
}, 1500);
|
|
163
175
|
});
|
|
164
176
|
this.updateKeyringState();
|
|
165
177
|
this.currentAccountSubject.next({
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
export default class DeleteEarningData extends BaseMigrationJob {
|
|
6
|
+
async run() {
|
|
7
|
+
try {
|
|
8
|
+
await this.state.dbService.deleteYieldPoolInfo(['LcDOT___acala_euphrates_liquid_staking', 'xcDOT___moonwell_lending']);
|
|
9
|
+
} catch (e) {
|
|
10
|
+
console.error(e);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
export default class EnableEarningChains extends BaseMigrationJob {
|
|
6
|
+
async run() {
|
|
7
|
+
try {
|
|
8
|
+
await this.state.chainService.enableChains(['moonbeam', 'acala', 'bifrost_dot', 'interlay', 'parallel']);
|
|
9
|
+
} catch (e) {
|
|
10
|
+
console.error(e);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -11,7 +11,7 @@ export default class MigrateLedgerAccount extends BaseMigrationJob {
|
|
|
11
11
|
const store = new AccountsStore();
|
|
12
12
|
const update = (key, value) => {
|
|
13
13
|
var _value$meta;
|
|
14
|
-
if (key.startsWith('account:') && value.meta && isString((_value$meta = value.meta) === null || _value$meta === void 0 ? void 0 : _value$meta.originGenesisHash)) {
|
|
14
|
+
if (key.startsWith('account:') && value !== null && value !== void 0 && value.meta && isString((_value$meta = value.meta) === null || _value$meta === void 0 ? void 0 : _value$meta.originGenesisHash)) {
|
|
15
15
|
const newValue = {
|
|
16
16
|
...value
|
|
17
17
|
};
|
|
@@ -12,7 +12,7 @@ export default class MigrateTransactionHistory extends BaseMigrationJob {
|
|
|
12
12
|
const chainInfoMap = state.getChainInfoMap();
|
|
13
13
|
const assetList = Object.values(state.getAssetRegistry());
|
|
14
14
|
try {
|
|
15
|
-
const db = new Dexie('
|
|
15
|
+
const db = new Dexie('SubWalletDB_v2');
|
|
16
16
|
const dexieDB = await db.open();
|
|
17
17
|
const transactionTable = dexieDB.table('transactions');
|
|
18
18
|
const oldTransactionData = await transactionTable.toArray();
|