@subwallet/extension-base 1.1.31-beta.0 → 1.1.32-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 +1 -0
- package/cjs/koni/api/staking/bonding/index.js +2 -0
- package/cjs/koni/api/staking/bonding/paraChain.js +6 -3
- package/cjs/koni/background/cron.js +0 -28
- package/cjs/koni/background/handlers/Extension.js +17 -11
- package/cjs/koni/background/handlers/State.js +4 -46
- package/cjs/koni/background/subscription.js +0 -155
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/campaign-service/index.js +19 -0
- package/cjs/services/chain-service/constants.js +3 -2
- package/cjs/services/earning-service/constants/chains.js +1 -1
- package/cjs/services/earning-service/handlers/base.js +9 -6
- package/cjs/services/earning-service/handlers/lending/base.js +61 -0
- package/cjs/services/earning-service/handlers/lending/interlay.js +3 -2
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +3 -2
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +54 -0
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +3 -2
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +3 -2
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +16 -7
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +7 -2
- package/cjs/services/earning-service/handlers/native-staking/astar.js +7 -2
- package/cjs/services/earning-service/handlers/native-staking/base.js +4 -2
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +7 -2
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +12 -3
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +9 -3
- package/cjs/services/earning-service/handlers/special.js +57 -67
- package/cjs/services/earning-service/service.js +370 -37
- package/cjs/services/event-service/index.js +1 -0
- package/cjs/services/migration-service/scripts/index.js +1 -2
- package/cjs/services/storage-service/DatabaseService.js +15 -0
- package/cjs/services/storage-service/db-stores/Campaign.js +9 -3
- package/cjs/services/storage-service/db-stores/YieldPositionStore.js +6 -0
- package/cjs/services/transaction-service/index.js +15 -1
- package/cjs/utils/number.js +3 -1
- package/koni/api/staking/bonding/index.d.ts +1 -0
- package/koni/api/staking/bonding/index.js +2 -0
- package/koni/api/staking/bonding/paraChain.js +6 -3
- package/koni/background/cron.d.ts +0 -5
- package/koni/background/cron.js +1 -29
- package/koni/background/handlers/Extension.js +17 -11
- package/koni/background/handlers/State.d.ts +1 -12
- package/koni/background/handlers/State.js +4 -46
- package/koni/background/subscription.d.ts +1 -11
- package/koni/background/subscription.js +2 -157
- package/package.json +6 -6
- package/packageInfo.js +1 -1
- package/services/campaign-service/index.js +19 -0
- package/services/chain-service/constants.js +3 -2
- package/services/earning-service/constants/chains.js +1 -1
- package/services/earning-service/handlers/base.d.ts +1 -0
- package/services/earning-service/handlers/base.js +9 -6
- package/services/earning-service/handlers/lending/base.d.ts +2 -0
- package/services/earning-service/handlers/lending/base.js +61 -0
- package/services/earning-service/handlers/lending/interlay.js +4 -3
- package/services/earning-service/handlers/liquid-staking/acala.js +4 -3
- package/services/earning-service/handlers/liquid-staking/base.d.ts +2 -0
- package/services/earning-service/handlers/liquid-staking/base.js +55 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +4 -3
- package/services/earning-service/handlers/liquid-staking/parallel.js +4 -3
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +16 -7
- package/services/earning-service/handlers/native-staking/amplitude.js +7 -2
- package/services/earning-service/handlers/native-staking/astar.js +7 -2
- package/services/earning-service/handlers/native-staking/base.js +5 -3
- package/services/earning-service/handlers/native-staking/para-chain.js +7 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +12 -3
- package/services/earning-service/handlers/nomination-pool/index.js +10 -4
- package/services/earning-service/handlers/special.d.ts +0 -1
- package/services/earning-service/handlers/special.js +58 -68
- package/services/earning-service/service.d.ts +49 -1
- package/services/earning-service/service.js +358 -28
- package/services/event-service/index.d.ts +1 -0
- package/services/event-service/index.js +1 -0
- package/services/event-service/types.d.ts +1 -0
- package/services/migration-service/scripts/index.js +1 -2
- package/services/storage-service/DatabaseService.d.ts +5 -0
- package/services/storage-service/DatabaseService.js +15 -0
- package/services/storage-service/db-stores/Campaign.js +9 -3
- package/services/storage-service/db-stores/YieldPositionStore.d.ts +2 -0
- package/services/storage-service/db-stores/YieldPositionStore.js +6 -0
- package/services/transaction-service/index.js +15 -1
- package/types/yield/actions/join/submit.d.ts +2 -1
- package/types/yield/info/account/reward.d.ts +2 -0
- package/utils/number.d.ts +1 -0
- package/utils/number.js +1 -0
|
@@ -49,6 +49,12 @@ class YieldPositionStore extends _BaseStore.default {
|
|
|
49
49
|
// })
|
|
50
50
|
.toArray();
|
|
51
51
|
}
|
|
52
|
+
removeByAddresses(addresses) {
|
|
53
|
+
return this.table.where('address').anyOf(addresses).delete();
|
|
54
|
+
}
|
|
55
|
+
removeByChains(chains) {
|
|
56
|
+
return this.table.where('chain').anyOf(chains).delete();
|
|
57
|
+
}
|
|
52
58
|
async getByAddressAndChains(addresses, chains) {
|
|
53
59
|
return this.table.where('address').anyOfIgnoreCase(addresses).filter(item => chains.includes(item.chain)).toArray();
|
|
54
60
|
}
|
|
@@ -540,6 +540,9 @@ class TransactionService {
|
|
|
540
540
|
eventLogs && !(0, _utils._isChainEvmCompatible)(chainInfo) && (0, _eventParser.parseLiquidStakingEvents)(historyItem, eventLogs, inputTokenInfo, chainInfo, isFeePaidWithInputAsset, extrinsicType);
|
|
541
541
|
break;
|
|
542
542
|
}
|
|
543
|
+
case _KoniTypes.ExtrinsicType.UNSTAKE_QDOT:
|
|
544
|
+
|
|
545
|
+
// eslint-disable-next-line no-fallthrough
|
|
543
546
|
case _KoniTypes.ExtrinsicType.REDEEM_QDOT:
|
|
544
547
|
{
|
|
545
548
|
const data = (0, _utils2.parseTransactionData)(transaction.data);
|
|
@@ -553,10 +556,21 @@ class TransactionService {
|
|
|
553
556
|
decimals: (0, _utils._getAssetDecimals)(inputTokenInfo)
|
|
554
557
|
};
|
|
555
558
|
eventLogs && (0, _eventParser.parseLiquidStakingFastUnstakeEvents)(historyItem, eventLogs, chainInfo, extrinsicType);
|
|
559
|
+
const additionalInfo = {
|
|
560
|
+
minAmountPercent: 1,
|
|
561
|
+
symbol: inputTokenInfo.symbol,
|
|
562
|
+
decimals: inputTokenInfo.decimals || 0,
|
|
563
|
+
exchangeRate: 1,
|
|
564
|
+
slug: yieldPoolInfo.slug,
|
|
565
|
+
type: yieldPoolInfo.type,
|
|
566
|
+
chain: yieldPoolInfo.chain,
|
|
567
|
+
group: yieldPoolInfo.group,
|
|
568
|
+
isFast: data.fastLeave
|
|
569
|
+
};
|
|
570
|
+
historyItem.additionalInfo = additionalInfo;
|
|
556
571
|
}
|
|
557
572
|
break;
|
|
558
573
|
}
|
|
559
|
-
case _KoniTypes.ExtrinsicType.UNSTAKE_QDOT:
|
|
560
574
|
case _KoniTypes.ExtrinsicType.UNSTAKE_VDOT:
|
|
561
575
|
case _KoniTypes.ExtrinsicType.UNSTAKE_LDOT:
|
|
562
576
|
case _KoniTypes.ExtrinsicType.UNSTAKE_SDOT:
|
package/cjs/utils/number.js
CHANGED
|
@@ -4,11 +4,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.toBNString = exports.formatNumber = exports.balanceFormatter = exports.PREDEFINED_FORMATTER = exports.BN_TEN = void 0;
|
|
7
|
+
exports.toBNString = exports.formatNumber = exports.balanceFormatter = exports.PREDEFINED_FORMATTER = exports.BN_ZERO = exports.BN_TEN = void 0;
|
|
8
8
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
9
9
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
10
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
11
|
|
|
12
|
+
const BN_ZERO = new _bignumber.default(0);
|
|
13
|
+
exports.BN_ZERO = BN_ZERO;
|
|
12
14
|
const BN_TEN = new _bignumber.default(10);
|
|
13
15
|
exports.BN_TEN = BN_TEN;
|
|
14
16
|
// Clear zero from end, use with decimal only
|
|
@@ -4,6 +4,7 @@ import { ChainStakingMetadata, NominatorMetadata, StakingType, UnstakingInfo, Va
|
|
|
4
4
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
5
|
export declare function validateUnbondingCondition(nominatorMetadata: NominatorMetadata, amount: string, chain: string, chainStakingMetadata: ChainStakingMetadata, selectedValidator?: string): TransactionError[];
|
|
6
6
|
export declare function validateBondingCondition(chainInfo: _ChainInfo, amount: string, selectedValidators: ValidatorInfo[], address: string, chainStakingMetadata: ChainStakingMetadata, nominatorMetadata?: NominatorMetadata): TransactionError[];
|
|
7
|
+
/** Deprecated */
|
|
7
8
|
export declare function getChainStakingMetadata(chainInfo: _ChainInfo, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
|
|
8
9
|
/**
|
|
9
10
|
* Deprecated
|
|
@@ -25,6 +25,8 @@ export function validateBondingCondition(chainInfo, amount, selectedValidators,
|
|
|
25
25
|
}
|
|
26
26
|
return validateParaChainBondingCondition(chainInfo, amount, selectedValidators, address, chainStakingMetadata, nominatorMetadata);
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
/** Deprecated */
|
|
28
30
|
export async function getChainStakingMetadata(chainInfo, substrateApi) {
|
|
29
31
|
if (_STAKING_CHAIN_GROUP.astar.includes(chainInfo.slug)) {
|
|
30
32
|
return getAstarStakingMetadata(chainInfo.slug, substrateApi);
|
|
@@ -89,17 +89,18 @@ export function validateParaChainBondingCondition(chainInfo, amount, selectedCol
|
|
|
89
89
|
}
|
|
90
90
|
export function subscribeParaChainStakingMetadata(chain, substrateApi, callback) {
|
|
91
91
|
return substrateApi.api.query.parachainStaking.round(_round => {
|
|
92
|
-
var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$con3;
|
|
92
|
+
var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$con3, _substrateApi$api$con4, _substrateApi$api$con5, _substrateApi$api$con6;
|
|
93
93
|
const roundObj = _round.toHuman();
|
|
94
94
|
const round = parseRawNumber(roundObj.current);
|
|
95
95
|
const maxDelegations = (_substrateApi$api$con = substrateApi.api.consts) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.parachainStaking) === null || _substrateApi$api$con2 === void 0 ? void 0 : (_substrateApi$api$con3 = _substrateApi$api$con2.maxDelegationsPerDelegator) === null || _substrateApi$api$con3 === void 0 ? void 0 : _substrateApi$api$con3.toString();
|
|
96
96
|
const unstakingDelay = substrateApi.api.consts.parachainStaking.delegationBondLessDelay.toString();
|
|
97
97
|
const unstakingPeriod = parseInt(unstakingDelay) * (_STAKING_ERA_LENGTH_MAP[chain] || _STAKING_ERA_LENGTH_MAP.default);
|
|
98
|
+
const minDelegatorStake = (_substrateApi$api$con4 = substrateApi.api.consts) === null || _substrateApi$api$con4 === void 0 ? void 0 : (_substrateApi$api$con5 = _substrateApi$api$con4.parachainStaking) === null || _substrateApi$api$con5 === void 0 ? void 0 : (_substrateApi$api$con6 = _substrateApi$api$con5.minDelegatorStk) === null || _substrateApi$api$con6 === void 0 ? void 0 : _substrateApi$api$con6.toString();
|
|
98
99
|
callback(chain, {
|
|
99
100
|
chain,
|
|
100
101
|
type: StakingType.NOMINATED,
|
|
101
102
|
era: round,
|
|
102
|
-
minStake: '0',
|
|
103
|
+
minStake: minDelegatorStake || '0',
|
|
103
104
|
maxValidatorPerNominator: parseInt(maxDelegations),
|
|
104
105
|
maxWithdrawalRequestPerValidator: 1,
|
|
105
106
|
// by default
|
|
@@ -109,11 +110,13 @@ export function subscribeParaChainStakingMetadata(chain, substrateApi, callback)
|
|
|
109
110
|
});
|
|
110
111
|
}
|
|
111
112
|
export async function getParaChainStakingMetadata(chain, substrateApi) {
|
|
113
|
+
var _chainApi$api$consts$, _chainApi$api$consts$2;
|
|
112
114
|
const chainApi = await substrateApi.isReady;
|
|
113
115
|
const _round = (await chainApi.api.query.parachainStaking.round()).toHuman();
|
|
114
116
|
const round = parseRawNumber(_round.current);
|
|
115
117
|
const maxDelegations = chainApi.api.consts.parachainStaking.maxDelegationsPerDelegator.toString();
|
|
116
118
|
const unstakingDelay = chainApi.api.consts.parachainStaking.delegationBondLessDelay.toString();
|
|
119
|
+
const minDelegatorStake = (_chainApi$api$consts$ = chainApi.api.consts.parachainStaking) === null || _chainApi$api$consts$ === void 0 ? void 0 : (_chainApi$api$consts$2 = _chainApi$api$consts$.minDelegatorStk) === null || _chainApi$api$consts$2 === void 0 ? void 0 : _chainApi$api$consts$2.toString();
|
|
117
120
|
let _unvestedAllocation;
|
|
118
121
|
if (chainApi.api.query.vesting && chainApi.api.query.vesting.totalUnvestedAllocation) {
|
|
119
122
|
_unvestedAllocation = await chainApi.api.query.vesting.totalUnvestedAllocation();
|
|
@@ -138,7 +141,7 @@ export async function getParaChainStakingMetadata(chain, substrateApi) {
|
|
|
138
141
|
type: StakingType.NOMINATED,
|
|
139
142
|
era: round,
|
|
140
143
|
inflation,
|
|
141
|
-
minStake: '0',
|
|
144
|
+
minStake: minDelegatorStake || '0',
|
|
142
145
|
maxValidatorPerNominator: parseInt(maxDelegations),
|
|
143
146
|
maxWithdrawalRequestPerValidator: 1,
|
|
144
147
|
// by default
|
|
@@ -10,7 +10,6 @@ export declare class KoniCron {
|
|
|
10
10
|
private serviceSubscription;
|
|
11
11
|
dbService: DatabaseService;
|
|
12
12
|
private state;
|
|
13
|
-
private logger;
|
|
14
13
|
constructor(state: KoniState, subscriptions: KoniSubscription, dbService: DatabaseService);
|
|
15
14
|
private cronMap;
|
|
16
15
|
private subjectMap;
|
|
@@ -26,10 +25,6 @@ export declare class KoniCron {
|
|
|
26
25
|
syncMantaPay: () => void;
|
|
27
26
|
refreshNft: (address: string, apiMap: ApiMap, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>) => () => void;
|
|
28
27
|
resetNft: (newAddress: string) => void;
|
|
29
|
-
refreshStakingReward: (address: string) => () => void;
|
|
30
|
-
refreshStakingRewardFastInterval: (address: string) => () => void;
|
|
31
|
-
refreshEarningRewardHistoryInterval: (address: string) => () => void;
|
|
32
|
-
setStakingRewardReady: () => void;
|
|
33
28
|
checkNetworkAvailable: (serviceInfo: ServiceInfo) => boolean;
|
|
34
29
|
reloadNft(): Promise<boolean>;
|
|
35
30
|
reloadStaking(): Promise<boolean>;
|
package/koni/background/cron.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { CRON_REFRESH_NFT_INTERVAL, CRON_SYNC_MANTA_PAY } from '@subwallet/extension-base/constants';
|
|
5
5
|
import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportWasmNft } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
6
|
import { waitTimeout } from '@subwallet/extension-base/utils';
|
|
7
7
|
import { Subject } from 'rxjs';
|
|
8
|
-
import { logger as createLogger } from '@polkadot/util';
|
|
9
8
|
export class KoniCron {
|
|
10
9
|
status = 'pending';
|
|
11
10
|
constructor(state, subscriptions, dbService) {
|
|
12
11
|
this.subscriptions = subscriptions;
|
|
13
12
|
this.dbService = dbService;
|
|
14
13
|
this.state = state;
|
|
15
|
-
this.logger = createLogger('Cron');
|
|
16
14
|
// this.init();
|
|
17
15
|
}
|
|
18
16
|
|
|
@@ -95,10 +93,6 @@ export class KoniCron {
|
|
|
95
93
|
// only add cron jobs if there's at least 1 active network
|
|
96
94
|
(commonReload || needUpdateNft) && this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
97
95
|
reloadMantaPay && this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
|
|
98
|
-
(commonReload || chainUpdated) && this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
99
|
-
(commonReload || chainUpdated) && this.addCron('refreshEarningRewardHistoryInterval', this.refreshEarningRewardHistoryInterval(currentAccountInfo.address), CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL);
|
|
100
|
-
} else {
|
|
101
|
-
this.setStakingRewardReady();
|
|
102
96
|
}
|
|
103
97
|
};
|
|
104
98
|
this.state.eventService.onLazy(this.eventHandler);
|
|
@@ -109,11 +103,7 @@ export class KoniCron {
|
|
|
109
103
|
this.resetNft(currentAccountInfo.address);
|
|
110
104
|
this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
|
|
111
105
|
// this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
|
|
112
|
-
this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
|
|
113
|
-
this.addCron('refreshEarningRewardHistoryInterval', this.refreshEarningRewardHistoryInterval(currentAccountInfo.address), CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL);
|
|
114
106
|
this.addCron('syncMantaPay', this.syncMantaPay, CRON_SYNC_MANTA_PAY);
|
|
115
|
-
} else {
|
|
116
|
-
this.setStakingRewardReady();
|
|
117
107
|
}
|
|
118
108
|
this.status = 'running';
|
|
119
109
|
};
|
|
@@ -148,24 +138,6 @@ export class KoniCron {
|
|
|
148
138
|
resetNft = newAddress => {
|
|
149
139
|
this.state.resetNft(newAddress);
|
|
150
140
|
};
|
|
151
|
-
refreshStakingReward = address => {
|
|
152
|
-
return () => {
|
|
153
|
-
this.subscriptions.subscribeStakingReward(address).catch(this.logger.error);
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
refreshStakingRewardFastInterval = address => {
|
|
157
|
-
return () => {
|
|
158
|
-
this.subscriptions.subscribeStakingRewardFastInterval(address).catch(this.logger.error);
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
refreshEarningRewardHistoryInterval = address => {
|
|
162
|
-
return () => {
|
|
163
|
-
this.subscriptions.subscribeEarningRewardHistoryInterval(address).catch(this.logger.error);
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
setStakingRewardReady = () => {
|
|
167
|
-
this.state.updateStakingRewardReady(true);
|
|
168
|
-
};
|
|
169
141
|
checkNetworkAvailable = serviceInfo => {
|
|
170
142
|
return Object.keys(serviceInfo.chainApiMap.substrate).length > 0 || Object.keys(serviceInfo.chainApiMap.evm).length > 0;
|
|
171
143
|
};
|
|
@@ -3554,18 +3554,19 @@ export default class KoniExtension {
|
|
|
3554
3554
|
this.#koniState.keyringService.removeInjectAccounts(request.addresses);
|
|
3555
3555
|
return true;
|
|
3556
3556
|
}
|
|
3557
|
-
subscribeYieldPoolInfo(id, port) {
|
|
3557
|
+
async subscribeYieldPoolInfo(id, port) {
|
|
3558
3558
|
const cb = createSubscription(id, port);
|
|
3559
|
-
|
|
3559
|
+
await this.#koniState.earningService.waitForStarted();
|
|
3560
|
+
const yieldPoolSubscription = this.#koniState.earningService.subscribeYieldPoolInfo().subscribe({
|
|
3560
3561
|
next: rs => {
|
|
3561
|
-
cb(rs);
|
|
3562
|
+
cb(Object.values(rs));
|
|
3562
3563
|
}
|
|
3563
3564
|
});
|
|
3564
3565
|
this.createUnsubscriptionHandle(id, yieldPoolSubscription.unsubscribe);
|
|
3565
3566
|
port.onDisconnect.addListener(() => {
|
|
3566
3567
|
this.cancelSubscription(id);
|
|
3567
3568
|
});
|
|
3568
|
-
return this.#koniState.getYieldPoolInfo();
|
|
3569
|
+
return this.#koniState.earningService.getYieldPoolInfo();
|
|
3569
3570
|
}
|
|
3570
3571
|
async earlyValidateJoin(request) {
|
|
3571
3572
|
return await this.#koniState.earningService.earlyValidateJoin(request);
|
|
@@ -3596,6 +3597,7 @@ export default class KoniExtension {
|
|
|
3596
3597
|
|
|
3597
3598
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
3598
3599
|
const {
|
|
3600
|
+
chainType,
|
|
3599
3601
|
extrinsic,
|
|
3600
3602
|
extrinsicType,
|
|
3601
3603
|
transferNativeAmount,
|
|
@@ -3604,7 +3606,6 @@ export default class KoniExtension {
|
|
|
3604
3606
|
} = await this.#koniState.earningService.handleYieldJoin(inputData);
|
|
3605
3607
|
const isPoolSupportAlternativeFee = this.#koniState.earningService.isPoolSupportAlternativeFee(inputData.data.slug);
|
|
3606
3608
|
const isMintingStep = YIELD_EXTRINSIC_TYPES.includes(extrinsicType);
|
|
3607
|
-
const chainInfo = this.#koniState.getChainInfo(txChain);
|
|
3608
3609
|
return await this.#koniState.transactionService.handleTransaction({
|
|
3609
3610
|
address,
|
|
3610
3611
|
chain: txChain,
|
|
@@ -3613,7 +3614,7 @@ export default class KoniExtension {
|
|
|
3613
3614
|
data: txData,
|
|
3614
3615
|
extrinsicType,
|
|
3615
3616
|
// change this depends on step
|
|
3616
|
-
chainType
|
|
3617
|
+
chainType,
|
|
3617
3618
|
resolveOnDone: !isLastStep,
|
|
3618
3619
|
transferNativeAmount,
|
|
3619
3620
|
skipFeeValidation: isMintingStep && isPoolSupportAlternativeFee
|
|
@@ -3644,6 +3645,7 @@ export default class KoniExtension {
|
|
|
3644
3645
|
const {
|
|
3645
3646
|
slug
|
|
3646
3647
|
} = request;
|
|
3648
|
+
await this.#koniState.earningService.waitForStarted();
|
|
3647
3649
|
const targets = await this.#koniState.earningService.getPoolTargets(slug);
|
|
3648
3650
|
return {
|
|
3649
3651
|
slug,
|
|
@@ -3652,7 +3654,8 @@ export default class KoniExtension {
|
|
|
3652
3654
|
}
|
|
3653
3655
|
async subscribeYieldPosition(id, port) {
|
|
3654
3656
|
const cb = createSubscription(id, port);
|
|
3655
|
-
|
|
3657
|
+
await this.#koniState.earningService.waitForStarted();
|
|
3658
|
+
const yieldPositionSubscription = this.#koniState.earningService.subscribeYieldPosition().subscribe({
|
|
3656
3659
|
next: rs => {
|
|
3657
3660
|
cb(rs);
|
|
3658
3661
|
}
|
|
@@ -3661,10 +3664,11 @@ export default class KoniExtension {
|
|
|
3661
3664
|
port.onDisconnect.addListener(() => {
|
|
3662
3665
|
this.cancelSubscription(id);
|
|
3663
3666
|
});
|
|
3664
|
-
return this.#koniState.getYieldPositionInfo();
|
|
3667
|
+
return await this.#koniState.earningService.getYieldPositionInfo();
|
|
3665
3668
|
}
|
|
3666
|
-
subscribeYieldReward(id, port) {
|
|
3669
|
+
async subscribeYieldReward(id, port) {
|
|
3667
3670
|
const cb = createSubscription(id, port);
|
|
3671
|
+
await this.#koniState.earningService.waitForStarted();
|
|
3668
3672
|
const stakingRewardSubscription = this.#koniState.earningService.subscribeEarningReward().subscribe({
|
|
3669
3673
|
next: rs => {
|
|
3670
3674
|
cb(rs);
|
|
@@ -3676,8 +3680,9 @@ export default class KoniExtension {
|
|
|
3676
3680
|
});
|
|
3677
3681
|
return this.#koniState.earningService.getEarningRewards();
|
|
3678
3682
|
}
|
|
3679
|
-
subscribeYieldRewardHistory(id, port) {
|
|
3683
|
+
async subscribeYieldRewardHistory(id, port) {
|
|
3680
3684
|
const cb = createSubscription(id, port);
|
|
3685
|
+
await this.#koniState.earningService.waitForStarted();
|
|
3681
3686
|
const rewardHistorySubscription = this.#koniState.earningService.subscribeEarningRewardHistory().subscribe({
|
|
3682
3687
|
next: rs => {
|
|
3683
3688
|
cb(rs);
|
|
@@ -3689,8 +3694,9 @@ export default class KoniExtension {
|
|
|
3689
3694
|
});
|
|
3690
3695
|
return this.#koniState.earningService.getEarningRewardHistory();
|
|
3691
3696
|
}
|
|
3692
|
-
subscribeEarningMinAmountPercent(id, port) {
|
|
3697
|
+
async subscribeEarningMinAmountPercent(id, port) {
|
|
3693
3698
|
const cb = createSubscription(id, port);
|
|
3699
|
+
await this.#koniState.earningService.waitForStarted();
|
|
3694
3700
|
const earningMinAmountPercentSubscription = this.#koniState.earningService.subscribeMinAmountPercent().subscribe({
|
|
3695
3701
|
next: rs => {
|
|
3696
3702
|
cb(rs);
|
|
@@ -22,7 +22,7 @@ import DatabaseService from '@subwallet/extension-base/services/storage-service/
|
|
|
22
22
|
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
23
23
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
24
24
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
25
|
-
import { BalanceItem, BalanceJson, BalanceMap
|
|
25
|
+
import { BalanceItem, BalanceJson, BalanceMap } from '@subwallet/extension-base/types';
|
|
26
26
|
import { MetadataDef, ProviderMeta } from '@subwallet/extension-inject/types';
|
|
27
27
|
import SimpleKeyring from 'eth-simple-keyring';
|
|
28
28
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
@@ -48,8 +48,6 @@ export default class KoniState {
|
|
|
48
48
|
private stakingNominatorMetadataSubject;
|
|
49
49
|
private stakingRewardSubject;
|
|
50
50
|
private stakingRewardState;
|
|
51
|
-
private yieldPoolInfoSubject;
|
|
52
|
-
private yieldPositionSubject;
|
|
53
51
|
private lazyMap;
|
|
54
52
|
readonly notificationService: NotificationService;
|
|
55
53
|
readonly eventService: EventService;
|
|
@@ -114,11 +112,6 @@ export default class KoniState {
|
|
|
114
112
|
getStaking(): Promise<StakingJson>;
|
|
115
113
|
getStakingOwnersByChains(chains: string[]): Promise<string[]>;
|
|
116
114
|
getPooledStakingRecordsByAddress(addresses: string[]): Promise<StakingItem[]>;
|
|
117
|
-
getPooledPositionByAddress(addresses: string[]): Promise<YieldPositionInfo[]>;
|
|
118
|
-
subscribeYieldPoolInfo(): Subject<YieldPoolInfo[]>;
|
|
119
|
-
subscribeYieldPosition(): Subject<YieldPositionInfo[]>;
|
|
120
|
-
getYieldPoolInfo(): Promise<YieldPoolInfo[]>;
|
|
121
|
-
getYieldPositionInfo(): Promise<YieldPositionInfo[]>;
|
|
122
115
|
subscribeMantaPayConfig(): Subject<MantaPayConfig[]>;
|
|
123
116
|
subscribeStaking(): Subject<StakingJson>;
|
|
124
117
|
subscribeChainStakingMetadata(): Subject<ChainStakingMetadata[]>;
|
|
@@ -262,10 +255,6 @@ export default class KoniState {
|
|
|
262
255
|
metadata: string;
|
|
263
256
|
specVersion: number;
|
|
264
257
|
}>;
|
|
265
|
-
updateYieldPoolInfo(data: YieldPoolInfo): void;
|
|
266
|
-
resetYieldPoolInfo(chains: string[]): void;
|
|
267
|
-
updateYieldPosition(data: YieldPositionInfo): void;
|
|
268
|
-
getYieldPoolStakingInfo(chain: string, poolType: YieldPoolType): Promise<YieldPoolInfo | undefined>;
|
|
269
258
|
getCrowdloanContributions({ address, page, relayChain }: RequestCrowdloanContributions): Promise<import("../../../services/subscan-service/types").CrowdloanContributionsResponse>;
|
|
270
259
|
}
|
|
271
260
|
export {};
|
|
@@ -77,10 +77,6 @@ export default class KoniState {
|
|
|
77
77
|
ready: false,
|
|
78
78
|
data: {}
|
|
79
79
|
};
|
|
80
|
-
|
|
81
|
-
// earning
|
|
82
|
-
yieldPoolInfoSubject = new Subject();
|
|
83
|
-
yieldPositionSubject = new Subject();
|
|
84
80
|
lazyMap = {};
|
|
85
81
|
// Handle the general status of the extension
|
|
86
82
|
generalStatus = ServiceStatus.INITIALIZING;
|
|
@@ -226,6 +222,7 @@ export default class KoniState {
|
|
|
226
222
|
await this.migrationService.run();
|
|
227
223
|
this.campaignService.init();
|
|
228
224
|
this.eventService.emit('chain.ready', true);
|
|
225
|
+
await this.earningService.init();
|
|
229
226
|
this.onReady();
|
|
230
227
|
this.onAccountAdd();
|
|
231
228
|
this.onAccountRemove();
|
|
@@ -255,14 +252,6 @@ export default class KoniState {
|
|
|
255
252
|
this.dbService.subscribeMantaPayConfig(_DEFAULT_MANTA_ZK_CHAIN, data => {
|
|
256
253
|
this.mantaPayConfigSubject.next(data);
|
|
257
254
|
});
|
|
258
|
-
let unsub;
|
|
259
|
-
this.keyringService.accountSubject.subscribe(accounts => {
|
|
260
|
-
// TODO: improve this
|
|
261
|
-
unsub && unsub.unsubscribe();
|
|
262
|
-
unsub = this.dbService.subscribeYieldPosition(Object.keys(accounts), data => {
|
|
263
|
-
this.yieldPositionSubject.next(data);
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
255
|
}
|
|
267
256
|
onReady() {
|
|
268
257
|
// Todo: Need optimize in the future to, only run important services onetime to save resources
|
|
@@ -352,22 +341,6 @@ export default class KoniState {
|
|
|
352
341
|
async getPooledStakingRecordsByAddress(addresses) {
|
|
353
342
|
return this.dbService.getPooledStakings(addresses, this.activeChainSlugs);
|
|
354
343
|
}
|
|
355
|
-
async getPooledPositionByAddress(addresses) {
|
|
356
|
-
return this.dbService.getYieldNominationPoolPosition(addresses, this.activeChainSlugs);
|
|
357
|
-
}
|
|
358
|
-
subscribeYieldPoolInfo() {
|
|
359
|
-
return this.yieldPoolInfoSubject;
|
|
360
|
-
}
|
|
361
|
-
subscribeYieldPosition() {
|
|
362
|
-
return this.yieldPositionSubject;
|
|
363
|
-
}
|
|
364
|
-
getYieldPoolInfo() {
|
|
365
|
-
return this.dbService.getYieldPools();
|
|
366
|
-
}
|
|
367
|
-
getYieldPositionInfo() {
|
|
368
|
-
const addresses = this.getDecodedAddresses(this.keyringService.currentAccount.address);
|
|
369
|
-
return this.dbService.getYieldPositionByAddress(addresses);
|
|
370
|
-
}
|
|
371
344
|
subscribeMantaPayConfig() {
|
|
372
345
|
return this.mantaPayConfigSubject;
|
|
373
346
|
}
|
|
@@ -1434,7 +1407,7 @@ export default class KoniState {
|
|
|
1434
1407
|
// Stopping services
|
|
1435
1408
|
await Promise.all([this.cron.stop(), this.subscription.stop()]);
|
|
1436
1409
|
await this.pauseAllNetworks(undefined, 'IDLE mode');
|
|
1437
|
-
await Promise.all([this.historyService.stop(), this.priceService.stop()]);
|
|
1410
|
+
await Promise.all([this.historyService.stop(), this.priceService.stop(), this.earningService.stop()]);
|
|
1438
1411
|
|
|
1439
1412
|
// Complete sleeping
|
|
1440
1413
|
sleeping.resolve();
|
|
@@ -1466,7 +1439,7 @@ export default class KoniState {
|
|
|
1466
1439
|
}
|
|
1467
1440
|
|
|
1468
1441
|
// Start services
|
|
1469
|
-
await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start()]);
|
|
1442
|
+
await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.earningService.start()]);
|
|
1470
1443
|
|
|
1471
1444
|
// Complete starting
|
|
1472
1445
|
starting.resolve();
|
|
@@ -1567,7 +1540,7 @@ export default class KoniState {
|
|
|
1567
1540
|
return await this.cron.reloadNft();
|
|
1568
1541
|
}
|
|
1569
1542
|
async reloadStaking() {
|
|
1570
|
-
await this.
|
|
1543
|
+
await this.earningService.reloadEarning(true);
|
|
1571
1544
|
return true;
|
|
1572
1545
|
}
|
|
1573
1546
|
async reloadBalance() {
|
|
@@ -1766,21 +1739,6 @@ export default class KoniState {
|
|
|
1766
1739
|
specVersion: parseInt((metadata === null || metadata === void 0 ? void 0 : metadata.specVersion) || '0')
|
|
1767
1740
|
};
|
|
1768
1741
|
}
|
|
1769
|
-
updateYieldPoolInfo(data) {
|
|
1770
|
-
this.dbService.updateYieldPoolStore(data).catch(e => this.logger.warn(e));
|
|
1771
|
-
}
|
|
1772
|
-
resetYieldPoolInfo(chains) {
|
|
1773
|
-
this.dbService.subscribeYieldPoolInfo(chains, data => {
|
|
1774
|
-
// TODO: no unsub
|
|
1775
|
-
this.yieldPoolInfoSubject.next(data);
|
|
1776
|
-
});
|
|
1777
|
-
}
|
|
1778
|
-
updateYieldPosition(data) {
|
|
1779
|
-
this.dbService.updateYieldPosition(data).catch(e => this.logger.warn(e));
|
|
1780
|
-
}
|
|
1781
|
-
getYieldPoolStakingInfo(chain, poolType) {
|
|
1782
|
-
return this.dbService.getYieldPoolStakingInfo(chain, poolType);
|
|
1783
|
-
}
|
|
1784
1742
|
getCrowdloanContributions({
|
|
1785
1743
|
address,
|
|
1786
1744
|
page,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { SubstrateApi } from '@subwallet/extension-base/services/chain-service/handler/SubstrateApi';
|
|
3
2
|
import { _ChainState, _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
3
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
5
4
|
import KoniState from './handlers/State';
|
|
6
|
-
declare type SubscriptionName = 'balance' | 'crowdloan' | '
|
|
5
|
+
declare type SubscriptionName = 'balance' | 'crowdloan' | 'yieldPoolStats' | 'yieldPosition';
|
|
7
6
|
export declare class KoniSubscription {
|
|
8
7
|
private eventHandler?;
|
|
9
8
|
private subscriptionMap;
|
|
@@ -19,20 +18,11 @@ export declare class KoniSubscription {
|
|
|
19
18
|
stop(): Promise<void>;
|
|
20
19
|
subscribeBalances(address: string, chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>, web3ApiMap: Record<string, _EvmApi>, onlyRunOnFirstTime?: boolean): void;
|
|
21
20
|
subscribeCrowdloans(address: string, substrateApiMap: Record<string, _SubstrateApi>, onlyRunOnFirstTime?: boolean): void;
|
|
22
|
-
subscribeYieldPools(chainInfoMap: Record<string, _ChainInfo>, assetInfoMap: Record<string, _ChainAsset>, substrateApiMap: Record<string, SubstrateApi>, evmApiMap: Record<string, _EvmApi>, address?: string, onlyRunOnFirstTime?: boolean): void;
|
|
23
|
-
initYieldPositionSubscription(addresses: string[], substrateApiMap: Record<string, SubstrateApi>, evmApiMap: Record<string, _EvmApi>, chainInfoMap: Record<string, _ChainInfo>, assetInfoMap: Record<string, _ChainAsset>, onlyRunOnFirstTime?: boolean): () => void;
|
|
24
|
-
initYieldPoolStatsSubscription(substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, onlyRunOnFirstTime?: boolean): () => void;
|
|
25
|
-
subscribeStakingOnChain(address: string, substrateApiMap: Record<string, _SubstrateApi>, onlyRunOnFirstTime?: boolean): void;
|
|
26
|
-
initStakingOnChainSubscription(addresses: string[], substrateApiMap: Record<string, _SubstrateApi>, onlyRunOnFirstTime?: boolean): (() => void) | undefined;
|
|
27
|
-
initEssentialChainStakingMetadataSubscription(substrateApiMap: Record<string, _SubstrateApi>, onlyRunOnFirstTime?: boolean): (() => void) | undefined;
|
|
28
21
|
initBalanceSubscription(addresses: string[], chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, onlyRunOnFirstTime?: boolean): (() => void) | undefined;
|
|
29
22
|
initCrowdloanSubscription(addresses: string[], substrateApiMap: Record<string, _SubstrateApi>, onlyRunOnFirstTime?: boolean): (() => void) | undefined;
|
|
30
23
|
subscribeNft(address: string, substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>): void;
|
|
31
24
|
initNftSubscription(addresses: string[], substrateApiMap: Record<string, _SubstrateApi>, evmApiMap: Record<string, _EvmApi>, smartContractNfts: _ChainAsset[], chainInfoMap: Record<string, _ChainInfo>): void;
|
|
32
25
|
subscribeStakingReward(address: string): Promise<void>;
|
|
33
|
-
subscribeStakingRewardFastInterval(address: string): Promise<void>;
|
|
34
|
-
subscribeEarningRewardHistoryInterval(address: string): Promise<void>;
|
|
35
|
-
reloadStaking(): Promise<void>;
|
|
36
26
|
reloadBalance(): Promise<void>;
|
|
37
27
|
reloadCrowdloan(): Promise<void>;
|
|
38
28
|
}
|