@subwallet/extension-base 1.1.40-1 → 1.1.41-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 +3 -1
- package/cjs/constants/index.js +1 -1
- package/cjs/koni/api/dotsama/transfer.js +1 -1
- package/cjs/koni/api/nft/bit.country/index.js +2 -0
- package/cjs/koni/api/nft/config.js +3 -1
- package/cjs/koni/api/tokens/evm/transfer.js +4 -4
- package/cjs/koni/background/handlers/Extension.js +32 -17
- package/cjs/koni/background/handlers/State.js +41 -9
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +58 -0
- package/cjs/services/chain-service/constants.js +11 -7
- package/cjs/services/chain-service/handler/chain-spec/goldberg.js +75 -8
- package/cjs/services/chain-service/index.js +71 -59
- package/cjs/services/chain-service/utils.js +11 -6
- package/cjs/services/earning-service/constants/chains.js +2 -2
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +9 -3
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +8 -1
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +6 -1
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +25 -17
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +4 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +6 -2
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +5 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +14 -16
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +9 -11
- package/cjs/services/earning-service/handlers/special.js +2 -0
- package/cjs/services/earning-service/service.js +51 -18
- package/cjs/services/fee-service/service.js +70 -0
- package/cjs/services/fee-service/utils/index.js +209 -0
- package/cjs/services/migration-service/scripts/DeleteChainStaking.js +23 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/transaction-service/index.js +37 -37
- package/cjs/types/fee/index.js +1 -0
- package/cjs/types/index.js +11 -0
- package/cjs/utils/eth.js +2 -105
- package/cjs/utils/index.js +12 -0
- package/cjs/utils/reportError.js +31 -0
- package/constants/index.d.ts +1 -1
- package/constants/index.js +1 -1
- package/koni/api/dotsama/transfer.js +1 -1
- package/koni/api/nft/bit.country/index.js +3 -1
- package/koni/api/nft/config.d.ts +1 -0
- package/koni/api/nft/config.js +1 -0
- package/koni/api/tokens/evm/transfer.js +1 -1
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +18 -3
- package/koni/background/handlers/State.d.ts +4 -1
- package/koni/background/handlers/State.js +32 -1
- package/package.json +31 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +59 -1
- package/services/chain-service/constants.d.ts +2 -0
- package/services/chain-service/constants.js +11 -7
- package/services/chain-service/handler/chain-spec/goldberg.d.ts +70 -1
- package/services/chain-service/handler/chain-spec/goldberg.js +75 -8
- package/services/chain-service/index.d.ts +7 -3
- package/services/chain-service/index.js +62 -51
- package/services/chain-service/types.d.ts +4 -0
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +10 -6
- package/services/earning-service/constants/chains.js +2 -2
- package/services/earning-service/handlers/liquid-staking/acala.js +9 -3
- package/services/earning-service/handlers/liquid-staking/bifrost.js +8 -1
- package/services/earning-service/handlers/liquid-staking/parallel.d.ts +1 -1
- package/services/earning-service/handlers/liquid-staking/parallel.js +6 -1
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +25 -17
- package/services/earning-service/handlers/native-staking/amplitude.js +4 -0
- package/services/earning-service/handlers/native-staking/astar.js +6 -2
- package/services/earning-service/handlers/native-staking/para-chain.js +5 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +15 -17
- package/services/earning-service/handlers/nomination-pool/index.js +10 -12
- package/services/earning-service/handlers/special.d.ts +1 -0
- package/services/earning-service/handlers/special.js +2 -0
- package/services/earning-service/service.d.ts +4 -1
- package/services/earning-service/service.js +52 -19
- package/services/fee-service/service.d.ts +12 -0
- package/services/fee-service/service.js +63 -0
- package/services/fee-service/utils/index.d.ts +8 -0
- package/services/fee-service/utils/index.js +193 -0
- package/services/migration-service/scripts/DeleteChainStaking.d.ts +4 -0
- package/services/migration-service/scripts/DeleteChainStaking.js +15 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/transaction-service/index.js +2 -2
- package/types/fee/index.d.ts +49 -0
- package/types/fee/index.js +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/yield/info/account/unstake.d.ts +2 -0
- package/types/yield/info/pallet.d.ts +4 -0
- package/utils/eth.d.ts +0 -15
- package/utils/eth.js +0 -101
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/reportError.d.ts +1 -0
- package/utils/reportError.js +23 -0
|
@@ -9,8 +9,8 @@ var _TransactionError = require("@subwallet/extension-base/background/errors/Tra
|
|
|
9
9
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
10
|
var _web = require("@subwallet/extension-base/koni/api/tokens/evm/web3");
|
|
11
11
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
12
|
+
var _utils2 = require("@subwallet/extension-base/services/fee-service/utils");
|
|
12
13
|
var _types = require("@subwallet/extension-base/types");
|
|
13
|
-
var _eth = require("@subwallet/extension-base/utils/eth");
|
|
14
14
|
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
15
15
|
var _util = require("@polkadot/util");
|
|
16
16
|
var _constants = require("../../constants");
|
|
@@ -257,6 +257,7 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
|
|
|
257
257
|
return Promise.resolve([]);
|
|
258
258
|
}
|
|
259
259
|
async handleTokenApproveStep(data, path) {
|
|
260
|
+
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
260
261
|
const {
|
|
261
262
|
address
|
|
262
263
|
} = data;
|
|
@@ -275,14 +276,15 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
|
|
|
275
276
|
const gasLimit = await approveCall.estimateGas({
|
|
276
277
|
from: address
|
|
277
278
|
});
|
|
278
|
-
const
|
|
279
|
-
const gasPrice = (0, _eth.recalculateGasPrice)(_price, this.chain);
|
|
279
|
+
const priority = await (0, _utils2.calculateGasFeeParams)(evmApi, this.chain);
|
|
280
280
|
const transactionObject = {
|
|
281
281
|
from: address,
|
|
282
282
|
to: (0, _utils._getContractAddressOfToken)(inputTokenInfo),
|
|
283
283
|
data: approveEncodedCall,
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
gas: gasLimit,
|
|
285
|
+
gasPrice: priority.gasPrice,
|
|
286
|
+
maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
|
|
287
|
+
maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
|
|
286
288
|
};
|
|
287
289
|
const _data = {
|
|
288
290
|
inputTokenSlug: inputTokenSlug,
|
|
@@ -298,6 +300,7 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
|
|
|
298
300
|
});
|
|
299
301
|
}
|
|
300
302
|
async handleSubmitStep(data, path) {
|
|
303
|
+
var _priority$maxFeePerGa2, _priority$maxPriority2;
|
|
301
304
|
const {
|
|
302
305
|
address,
|
|
303
306
|
amount
|
|
@@ -316,14 +319,15 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
|
|
|
316
319
|
const gasLimit = await depositCall.estimateGas({
|
|
317
320
|
from: address
|
|
318
321
|
});
|
|
319
|
-
const
|
|
320
|
-
const gasPrice = (0, _eth.recalculateGasPrice)(_price, this.chain);
|
|
322
|
+
const priority = await (0, _utils2.calculateGasFeeParams)(evmApi, this.chain);
|
|
321
323
|
const transactionObject = {
|
|
322
324
|
from: address,
|
|
323
325
|
to: (0, _utils._getContractAddressOfToken)(derivativeTokenInfo),
|
|
324
326
|
data: depositEncodedCall,
|
|
325
|
-
|
|
326
|
-
|
|
327
|
+
gas: gasLimit,
|
|
328
|
+
gasPrice: priority.gasPrice,
|
|
329
|
+
maxFeePerGas: (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
|
|
330
|
+
maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString()
|
|
327
331
|
};
|
|
328
332
|
return {
|
|
329
333
|
txChain: this.chain,
|
|
@@ -343,6 +347,7 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
|
|
|
343
347
|
return Promise.reject(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNSUPPORTED));
|
|
344
348
|
}
|
|
345
349
|
async handleYieldUnstake(amount, address, selectedTarget) {
|
|
350
|
+
var _priority$maxFeePerGa3, _priority$maxPriority3;
|
|
346
351
|
const evmApi = this.evmApi;
|
|
347
352
|
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
348
353
|
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
@@ -357,14 +362,15 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
|
|
|
357
362
|
const gasLimit = await redeemCall.estimateGas({
|
|
358
363
|
from: address
|
|
359
364
|
});
|
|
360
|
-
const
|
|
361
|
-
const gasPrice = (0, _eth.recalculateGasPrice)(_price, this.chain);
|
|
365
|
+
const priority = await (0, _utils2.calculateGasFeeParams)(evmApi, this.chain);
|
|
362
366
|
const transaction = {
|
|
363
367
|
from: address,
|
|
364
368
|
to: (0, _utils._getContractAddressOfToken)(derivativeTokenInfo),
|
|
365
369
|
data: redeemEncodedCall,
|
|
366
|
-
|
|
367
|
-
|
|
370
|
+
gas: gasLimit,
|
|
371
|
+
gasPrice: priority.gasPrice,
|
|
372
|
+
maxFeePerGas: (_priority$maxFeePerGa3 = priority.maxFeePerGas) === null || _priority$maxFeePerGa3 === void 0 ? void 0 : _priority$maxFeePerGa3.toString(),
|
|
373
|
+
maxPriorityFeePerGas: (_priority$maxPriority3 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority3 === void 0 ? void 0 : _priority$maxPriority3.toString()
|
|
368
374
|
};
|
|
369
375
|
return [_KoniTypes.ExtrinsicType.UNSTAKE_STDOT, transaction];
|
|
370
376
|
}
|
|
@@ -374,6 +380,7 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
|
|
|
374
380
|
/* Other actions */
|
|
375
381
|
|
|
376
382
|
async handleYieldWithdraw(address, unstakingInfo) {
|
|
383
|
+
var _priority$maxFeePerGa4, _priority$maxPriority4;
|
|
377
384
|
const evmApi = this.evmApi;
|
|
378
385
|
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
379
386
|
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
@@ -388,14 +395,15 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
|
|
|
388
395
|
const gasLimit = await withdrawCall.estimateGas({
|
|
389
396
|
from: address
|
|
390
397
|
});
|
|
391
|
-
const
|
|
392
|
-
const gasPrice = (0, _eth.recalculateGasPrice)(_price, this.chain);
|
|
398
|
+
const priority = await (0, _utils2.calculateGasFeeParams)(evmApi, this.chain);
|
|
393
399
|
return {
|
|
394
400
|
from: address,
|
|
395
401
|
to: (0, _utils._getContractAddressOfToken)(derivativeTokenInfo),
|
|
396
402
|
data: withdrawEncodedCall,
|
|
397
|
-
|
|
398
|
-
|
|
403
|
+
gas: gasLimit,
|
|
404
|
+
gasPrice: priority.gasPrice,
|
|
405
|
+
maxFeePerGas: (_priority$maxFeePerGa4 = priority.maxFeePerGas) === null || _priority$maxFeePerGa4 === void 0 ? void 0 : _priority$maxFeePerGa4.toString(),
|
|
406
|
+
maxPriorityFeePerGas: (_priority$maxPriority4 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority4 === void 0 ? void 0 : _priority$maxPriority4.toString()
|
|
399
407
|
}; // TODO: check tx history parsing
|
|
400
408
|
}
|
|
401
409
|
|
|
@@ -148,12 +148,16 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
|
|
|
148
148
|
const isClaimable = parseInt(unstakingBlock) - currentBlockNumber < 0;
|
|
149
149
|
const remainingBlock = parseInt(unstakingBlock) - currentBlockNumber;
|
|
150
150
|
const waitingTime = remainingBlock * blockDuration;
|
|
151
|
+
// const currentTimestampMs = Date.now();
|
|
152
|
+
// const targetTimestampMs = currentTimestampMs + waitingTime * 60 * 60 * 1000;
|
|
153
|
+
|
|
151
154
|
unstakingBalance = unstakingAmount.toString();
|
|
152
155
|
unstakingList.push({
|
|
153
156
|
chain: chainInfo.slug,
|
|
154
157
|
status: isClaimable ? _types.UnstakingStatus.CLAIMABLE : _types.UnstakingStatus.UNLOCKING,
|
|
155
158
|
claimable: unstakingAmount.toString(),
|
|
156
159
|
waitingTime,
|
|
160
|
+
// targetTimestampMs: targetTimestampMs,
|
|
157
161
|
validatorAddress: undefined
|
|
158
162
|
});
|
|
159
163
|
}
|
|
@@ -26,8 +26,7 @@ function getAstarWithdrawable(yieldPosition) {
|
|
|
26
26
|
const unstakingInfo = {
|
|
27
27
|
chain: yieldPosition.chain,
|
|
28
28
|
status: _types.UnstakingStatus.CLAIMABLE,
|
|
29
|
-
claimable: '0'
|
|
30
|
-
waitingTime: 0
|
|
29
|
+
claimable: '0'
|
|
31
30
|
};
|
|
32
31
|
let bnWithdrawable = _util.BN_ZERO;
|
|
33
32
|
for (const unstaking of yieldPosition.unstakings) {
|
|
@@ -208,14 +207,19 @@ class AstarNativeStakingPoolHandler extends _basePara.default {
|
|
|
208
207
|
const isClaimable = unlockingChunk.unlockEra - parseInt(currentEra) < 0;
|
|
209
208
|
const remainingEra = unlockingChunk.unlockEra - parseInt(currentEra);
|
|
210
209
|
const waitingTime = remainingEra * _constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug];
|
|
210
|
+
// const currentTimestampMs = Date.now();
|
|
211
|
+
// const targetTimestampMs = currentTimestampMs + waitingTime * 60 * 60 * 1000;
|
|
212
|
+
|
|
211
213
|
unstakingList.push({
|
|
212
214
|
chain: chainInfo.slug,
|
|
213
215
|
status: isClaimable ? _types.UnstakingStatus.CLAIMABLE : _types.UnstakingStatus.UNLOCKING,
|
|
214
216
|
claimable: unlockingChunk.amount.toString(),
|
|
215
217
|
waitingTime
|
|
218
|
+
// targetTimestampMs: targetTimestampMs
|
|
216
219
|
});
|
|
217
220
|
}
|
|
218
221
|
}
|
|
222
|
+
|
|
219
223
|
if (nominationList.length === 0 && unstakingList.length === 0) {
|
|
220
224
|
return {
|
|
221
225
|
balanceToken: this.nativeToken.slug,
|
|
@@ -144,13 +144,18 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
144
144
|
const remainingEra = scheduledRequest.whenExecutable - currentRound;
|
|
145
145
|
const waitingTime = remainingEra * _constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug];
|
|
146
146
|
const claimable = Object.values(scheduledRequest.action)[0];
|
|
147
|
+
// const currentTimestampMs = Date.now();
|
|
148
|
+
// const targetTimestampMs = currentTimestampMs + waitingTime * 60 * 60 * 1000;
|
|
149
|
+
|
|
147
150
|
unstakingMap[delegation.owner] = {
|
|
148
151
|
chain: chainInfo.slug,
|
|
149
152
|
status: isClaimable ? _types.UnstakingStatus.CLAIMABLE : _types.UnstakingStatus.UNLOCKING,
|
|
150
153
|
validatorAddress: delegation.owner,
|
|
151
154
|
claimable: claimable.toString(),
|
|
152
155
|
waitingTime
|
|
156
|
+
// targetTimestampMs: targetTimestampMs
|
|
153
157
|
};
|
|
158
|
+
|
|
154
159
|
hasUnstaking = true;
|
|
155
160
|
break; // only handle 1 scheduledRequest per collator
|
|
156
161
|
}
|
|
@@ -129,9 +129,9 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
129
129
|
/* Subscribe pool position */
|
|
130
130
|
|
|
131
131
|
async parseNominatorMetadata(chainInfo, address, substrateApi, ledger, currentEra, minStake, _deriveSessionProgress) {
|
|
132
|
-
var _substrateApi$api$que7, _substrateApi$api$que8, _substrateApi$api$que9, _substrateApi$api$que10;
|
|
132
|
+
var _substrateApi$api$que7, _substrateApi$api$que8, _substrateApi$api$que9, _substrateApi$api$que10, _substrateApi$api$que11, _substrateApi$api$que12;
|
|
133
133
|
const chain = chainInfo.slug;
|
|
134
|
-
const [_nominations, _bonded] = await Promise.all([(_substrateApi$api$que7 = substrateApi.api.query) === null || _substrateApi$api$que7 === void 0 ? void 0 : (_substrateApi$api$que8 = _substrateApi$api$que7.staking) === null || _substrateApi$api$que8 === void 0 ? void 0 : _substrateApi$api$que8.nominators(address), (_substrateApi$api$que9 = substrateApi.api.query) === null || _substrateApi$api$que9 === void 0 ? void 0 : (_substrateApi$api$que10 = _substrateApi$api$que9.staking) === null || _substrateApi$api$que10 === void 0 ? void 0 : _substrateApi$api$que10.bonded(address)]);
|
|
134
|
+
const [_nominations, _bonded, _activeEra] = await Promise.all([(_substrateApi$api$que7 = substrateApi.api.query) === null || _substrateApi$api$que7 === void 0 ? void 0 : (_substrateApi$api$que8 = _substrateApi$api$que7.staking) === null || _substrateApi$api$que8 === void 0 ? void 0 : _substrateApi$api$que8.nominators(address), (_substrateApi$api$que9 = substrateApi.api.query) === null || _substrateApi$api$que9 === void 0 ? void 0 : (_substrateApi$api$que10 = _substrateApi$api$que9.staking) === null || _substrateApi$api$que10 === void 0 ? void 0 : _substrateApi$api$que10.bonded(address), (_substrateApi$api$que11 = substrateApi.api.query) === null || _substrateApi$api$que11 === void 0 ? void 0 : (_substrateApi$api$que12 = _substrateApi$api$que11.staking) === null || _substrateApi$api$que12 === void 0 ? void 0 : _substrateApi$api$que12.activeEra()]);
|
|
135
135
|
const unlimitedNominatorRewarded = substrateApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
136
136
|
const _maxNominatorRewardedPerValidator = (substrateApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
137
137
|
const maxNominatorRewardedPerValidator = parseInt(_maxNominatorRewardedPerValidator);
|
|
@@ -188,21 +188,19 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
ledger.unlocking.forEach(unlockingChunk => {
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
const eraLength = _deriveSessionProgress.eraLength.toNumber();
|
|
196
|
-
const eraProgress = _deriveSessionProgress.eraProgress.toNumber();
|
|
197
|
-
const remainingSlots = eraLength - eraProgress;
|
|
198
|
-
const remainingHours = expectedBlockTime * remainingSlots / 60 / 60;
|
|
191
|
+
const activeEra = _activeEra.toPrimitive();
|
|
192
|
+
const era = parseInt(activeEra.index);
|
|
193
|
+
const startTimestampMs = parseInt(activeEra.start);
|
|
194
|
+
const remainingEra = unlockingChunk.era - era;
|
|
199
195
|
const eraTime = _constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug] || _constants._STAKING_ERA_LENGTH_MAP.default; // in hours
|
|
200
|
-
const
|
|
196
|
+
const remaningTimestampMs = remainingEra * eraTime * 60 * 60 * 1000;
|
|
197
|
+
const targetTimestampMs = startTimestampMs + remaningTimestampMs;
|
|
198
|
+
const isClaimable = targetTimestampMs - Date.now() <= 0;
|
|
201
199
|
unstakingList.push({
|
|
202
200
|
chain,
|
|
203
201
|
status: isClaimable ? _types.UnstakingStatus.CLAIMABLE : _types.UnstakingStatus.UNLOCKING,
|
|
204
202
|
claimable: unlockingChunk.value.toString(),
|
|
205
|
-
|
|
203
|
+
targetTimestampMs: targetTimestampMs
|
|
206
204
|
});
|
|
207
205
|
});
|
|
208
206
|
return {
|
|
@@ -217,19 +215,19 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
217
215
|
};
|
|
218
216
|
}
|
|
219
217
|
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
220
|
-
var _substrateApi$api$
|
|
218
|
+
var _substrateApi$api$que13;
|
|
221
219
|
let cancel = false;
|
|
222
220
|
const substrateApi = await this.substrateApi.isReady;
|
|
223
221
|
const defaultInfo = this.baseInfo;
|
|
224
222
|
const chainInfo = this.chainInfo;
|
|
225
|
-
const unsub = await ((_substrateApi$api$
|
|
223
|
+
const unsub = await ((_substrateApi$api$que13 = substrateApi.api.query.staking) === null || _substrateApi$api$que13 === void 0 ? void 0 : _substrateApi$api$que13.ledger.multi(useAddresses, async ledgers => {
|
|
226
224
|
if (cancel) {
|
|
227
225
|
unsub();
|
|
228
226
|
return;
|
|
229
227
|
}
|
|
230
228
|
if (ledgers) {
|
|
231
|
-
var _substrateApi$api$
|
|
232
|
-
const [_currentEra, _minimumActiveStake, _minNominatorBond, _deriveSessionProgress] = await Promise.all([(_substrateApi$api$
|
|
229
|
+
var _substrateApi$api$que14, _substrateApi$api$que15, _substrateApi$api$que16, _substrateApi$api$que17, _substrateApi$api$que18, _substrateApi$api$que19, _substrateApi$api$que20, _substrateApi$api$que21, _substrateApi$api$der, _substrateApi$api$der2;
|
|
230
|
+
const [_currentEra, _minimumActiveStake, _minNominatorBond, _deriveSessionProgress] = await Promise.all([(_substrateApi$api$que14 = substrateApi.api.query) === null || _substrateApi$api$que14 === void 0 ? void 0 : (_substrateApi$api$que15 = _substrateApi$api$que14.staking) === null || _substrateApi$api$que15 === void 0 ? void 0 : _substrateApi$api$que15.currentEra(), ((_substrateApi$api$que16 = substrateApi.api.query) === null || _substrateApi$api$que16 === void 0 ? void 0 : (_substrateApi$api$que17 = _substrateApi$api$que16.staking) === null || _substrateApi$api$que17 === void 0 ? void 0 : _substrateApi$api$que17.minimumActiveStake) && ((_substrateApi$api$que18 = substrateApi.api.query) === null || _substrateApi$api$que18 === void 0 ? void 0 : (_substrateApi$api$que19 = _substrateApi$api$que18.staking) === null || _substrateApi$api$que19 === void 0 ? void 0 : _substrateApi$api$que19.minimumActiveStake()), (_substrateApi$api$que20 = substrateApi.api.query) === null || _substrateApi$api$que20 === void 0 ? void 0 : (_substrateApi$api$que21 = _substrateApi$api$que20.staking) === null || _substrateApi$api$que21 === void 0 ? void 0 : _substrateApi$api$que21.minNominatorBond(), (_substrateApi$api$der = substrateApi.api.derive) === null || _substrateApi$api$der === void 0 ? void 0 : (_substrateApi$api$der2 = _substrateApi$api$der.session) === null || _substrateApi$api$der2 === void 0 ? void 0 : _substrateApi$api$der2.progress()]);
|
|
233
231
|
const currentEra = _currentEra.toString();
|
|
234
232
|
const minActiveStake = (_minimumActiveStake === null || _minimumActiveStake === void 0 ? void 0 : _minimumActiveStake.toString()) || '0';
|
|
235
233
|
const minNominatorBond = _minNominatorBond.toString();
|
|
@@ -158,7 +158,7 @@ class NominationPoolHandler extends _base.default {
|
|
|
158
158
|
const maxNominatorRewardedPerValidator = parseInt(_maxNominatorRewardedPerValidator);
|
|
159
159
|
const poolsPalletId = substrateApi.api.consts.nominationPools.palletId.toString();
|
|
160
160
|
const poolStashAccount = (0, _utils.parsePoolStashAddress)(substrateApi.api, 0, poolMemberInfo.poolId, poolsPalletId);
|
|
161
|
-
const [_nominations, _poolMetadata] = await Promise.all([substrateApi.api.query.staking.nominators(poolStashAccount), substrateApi.api.query.nominationPools.metadata(poolMemberInfo.poolId)]);
|
|
161
|
+
const [_nominations, _poolMetadata, _activeEra] = await Promise.all([substrateApi.api.query.staking.nominators(poolStashAccount), substrateApi.api.query.nominationPools.metadata(poolMemberInfo.poolId), substrateApi.api.query.staking.activeEra()]);
|
|
162
162
|
const poolMetadata = _poolMetadata.toPrimitive();
|
|
163
163
|
const nominations = _nominations.toJSON();
|
|
164
164
|
const poolName = (0, _util.isHex)(poolMetadata) ? (0, _util.hexToString)(poolMetadata) : poolMetadata;
|
|
@@ -193,22 +193,20 @@ class NominationPoolHandler extends _base.default {
|
|
|
193
193
|
let unstakingBalance = _util.BN_ZERO;
|
|
194
194
|
Object.entries(poolMemberInfo.unbondingEras).forEach(_ref => {
|
|
195
195
|
let [unlockingEra, amount] = _ref;
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
const
|
|
200
|
-
const eraLength = _deriveSessionProgress.eraLength.toNumber();
|
|
201
|
-
const eraProgress = _deriveSessionProgress.eraProgress.toNumber();
|
|
202
|
-
const remainingSlots = eraLength - eraProgress;
|
|
203
|
-
const remainingHours = expectedBlockTime * remainingSlots / 60 / 60;
|
|
196
|
+
const activeEra = _activeEra.toPrimitive();
|
|
197
|
+
const era = parseInt(activeEra.index);
|
|
198
|
+
const startTimestampMs = parseInt(activeEra.start);
|
|
199
|
+
const remainingEra = parseInt(unlockingEra) - era;
|
|
204
200
|
const eraTime = _constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug] || _constants._STAKING_ERA_LENGTH_MAP.default; // in hours
|
|
205
|
-
const
|
|
201
|
+
const remaningTimestampMs = remainingEra * eraTime * 60 * 60 * 1000;
|
|
202
|
+
const targetTimestampMs = startTimestampMs + remaningTimestampMs;
|
|
203
|
+
const isClaimable = targetTimestampMs - Date.now() <= 0;
|
|
206
204
|
unstakingBalance = unstakingBalance.add(new _util.BN(amount));
|
|
207
205
|
unstakings.push({
|
|
208
206
|
chain: chainInfo.slug,
|
|
209
207
|
status: isClaimable ? _types.UnstakingStatus.CLAIMABLE : _types.UnstakingStatus.UNLOCKING,
|
|
210
208
|
claimable: amount.toString(),
|
|
211
|
-
|
|
209
|
+
targetTimestampMs: targetTimestampMs
|
|
212
210
|
});
|
|
213
211
|
});
|
|
214
212
|
const bnActiveStake = new _util.BN(poolMemberInfo.points.toString());
|
|
@@ -48,6 +48,8 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
48
48
|
this.rate = rate;
|
|
49
49
|
this.exchangeRatePromise.resolve(true);
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
/** Exchange rate before divine with decimals */
|
|
51
53
|
async getExchangeRate() {
|
|
52
54
|
await this.exchangeRatePromise.promise;
|
|
53
55
|
return this.rate;
|
|
@@ -40,11 +40,15 @@ class EarningService {
|
|
|
40
40
|
yieldPositionSubject = new _rxjs.BehaviorSubject({});
|
|
41
41
|
yieldPositionListSubject = new _rxjs.BehaviorSubject([]); // virtual list of yieldPositionSubject with filter values
|
|
42
42
|
|
|
43
|
+
useOnlineCacheOnly = true;
|
|
43
44
|
constructor(state) {
|
|
44
45
|
this.state = state;
|
|
45
46
|
this.dbService = state.dbService;
|
|
46
47
|
this.eventService = state.eventService;
|
|
47
48
|
}
|
|
49
|
+
disableOnlineCacheOnly() {
|
|
50
|
+
this.useOnlineCacheOnly = false;
|
|
51
|
+
}
|
|
48
52
|
async initHandlers() {
|
|
49
53
|
await this.eventService.waitChainReady;
|
|
50
54
|
const chains = [];
|
|
@@ -132,6 +136,7 @@ class EarningService {
|
|
|
132
136
|
}
|
|
133
137
|
handleActions() {
|
|
134
138
|
this.eventService.onLazy((events, eventTypes) => {
|
|
139
|
+
let delayReload = false;
|
|
135
140
|
(async () => {
|
|
136
141
|
const removedAddresses = [];
|
|
137
142
|
const removeChains = [];
|
|
@@ -145,6 +150,13 @@ class EarningService {
|
|
|
145
150
|
removeChains.push(event.data[0]);
|
|
146
151
|
}
|
|
147
152
|
}
|
|
153
|
+
if (event.type === 'transaction.done') {
|
|
154
|
+
const transactionData = event.data[0];
|
|
155
|
+
const notRequireReloadTypes = [_KoniTypes.ExtrinsicType.TRANSFER_BALANCE, _KoniTypes.ExtrinsicType.TRANSFER_TOKEN, _KoniTypes.ExtrinsicType.TRANSFER_XCM, _KoniTypes.ExtrinsicType.SEND_NFT, _KoniTypes.ExtrinsicType.CROWDLOAN];
|
|
156
|
+
if (notRequireReloadTypes.indexOf(transactionData.extrinsicType) === -1) {
|
|
157
|
+
delayReload = true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
148
160
|
});
|
|
149
161
|
if (removeChains.length || removedAddresses.length) {
|
|
150
162
|
await this.removeYieldPositions(removeChains, removedAddresses);
|
|
@@ -153,8 +165,16 @@ class EarningService {
|
|
|
153
165
|
// Account changed or chain changed (active or inactive)
|
|
154
166
|
// Chain changed (active or inactive)
|
|
155
167
|
// Todo: Optimize performance of chain active or inactive in the future
|
|
156
|
-
if (eventTypes.includes('account.updateCurrent') || eventTypes.includes('account.remove') || eventTypes.includes('chain.updateState')) {
|
|
157
|
-
|
|
168
|
+
if (eventTypes.includes('account.updateCurrent') || eventTypes.includes('account.remove') || eventTypes.includes('chain.updateState') || delayReload) {
|
|
169
|
+
if (delayReload) {
|
|
170
|
+
this.delayReloadTimeout = setTimeout(() => {
|
|
171
|
+
this.reloadEarning().catch(console.error); // Timeout is removed inside reloadEarning > runUnsubscribePoolsPosition
|
|
172
|
+
}, 3000);
|
|
173
|
+
} else {
|
|
174
|
+
this.delayReloadTimeout && clearTimeout(this.delayReloadTimeout);
|
|
175
|
+
this.delayReloadTimeout = undefined;
|
|
176
|
+
await this.reloadEarning();
|
|
177
|
+
}
|
|
158
178
|
}
|
|
159
179
|
})().catch(console.error);
|
|
160
180
|
});
|
|
@@ -248,20 +268,25 @@ class EarningService {
|
|
|
248
268
|
}
|
|
249
269
|
async getYieldPool(slug) {
|
|
250
270
|
await this.eventService.waitEarningReady;
|
|
251
|
-
|
|
271
|
+
const poolInfoMap = this.yieldPoolInfoSubject.getValue();
|
|
272
|
+
return poolInfoMap[slug];
|
|
252
273
|
}
|
|
253
|
-
async subscribePoolsInfo(callback) {
|
|
274
|
+
async subscribePoolsInfo(onlineData, callback) {
|
|
254
275
|
let cancel = false;
|
|
255
276
|
await this.eventService.waitChainReady;
|
|
256
277
|
const unsubList = [];
|
|
257
278
|
for (const handler of Object.values(this.handlers)) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
279
|
+
// Force subscribe onchain data
|
|
280
|
+
const forceSubscribe = handler.type === _types2.YieldPoolType.LIQUID_STAKING || handler.type === _types2.YieldPoolType.LENDING;
|
|
281
|
+
if (!this.useOnlineCacheOnly || forceSubscribe) {
|
|
282
|
+
handler.subscribePoolInfo(callback).then(unsub => {
|
|
283
|
+
if (!cancel) {
|
|
284
|
+
unsubList.push(unsub);
|
|
285
|
+
} else {
|
|
286
|
+
unsub();
|
|
287
|
+
}
|
|
288
|
+
}).catch(console.error);
|
|
289
|
+
}
|
|
265
290
|
}
|
|
266
291
|
return () => {
|
|
267
292
|
cancel = true;
|
|
@@ -313,19 +338,20 @@ class EarningService {
|
|
|
313
338
|
Object.values(onlineData).forEach(item => {
|
|
314
339
|
this.updateYieldPoolInfo(item);
|
|
315
340
|
});
|
|
341
|
+
return onlineData;
|
|
316
342
|
}
|
|
317
343
|
async runSubscribePoolsInfo() {
|
|
318
344
|
await this.eventService.waitChainReady;
|
|
319
345
|
this.runUnsubscribePoolsInfo();
|
|
320
346
|
|
|
321
347
|
// Fetching online data
|
|
322
|
-
this.fetchingPoolsInfoOnline()
|
|
348
|
+
const onlineData = await this.fetchingPoolsInfoOnline();
|
|
323
349
|
const interval = setInterval(() => {
|
|
324
350
|
this.fetchingPoolsInfoOnline().catch(console.error);
|
|
325
351
|
}, _constants.CRON_REFRESH_CHAIN_STAKING_METADATA);
|
|
326
352
|
|
|
327
353
|
// Fetching from chains
|
|
328
|
-
this.subscribePoolsInfo(data => {
|
|
354
|
+
this.subscribePoolsInfo(onlineData, data => {
|
|
329
355
|
data.lastUpdated = Date.now();
|
|
330
356
|
this.updateYieldPoolInfo(data);
|
|
331
357
|
}).then(rs => {
|
|
@@ -470,6 +496,10 @@ class EarningService {
|
|
|
470
496
|
(_this$yieldPositionUn = this.yieldPositionUnsub) === null || _this$yieldPositionUn === void 0 ? void 0 : _this$yieldPositionUn.call(this);
|
|
471
497
|
(0, _utils2.removeLazy)('persistYieldPositionInfo');
|
|
472
498
|
this.yieldPositionPersistQueue = [];
|
|
499
|
+
|
|
500
|
+
// Remove delay reload
|
|
501
|
+
this.delayReloadTimeout && clearTimeout(this.delayReloadTimeout);
|
|
502
|
+
this.delayReloadTimeout = undefined;
|
|
473
503
|
}
|
|
474
504
|
|
|
475
505
|
/* Pools' position methods */
|
|
@@ -618,13 +648,16 @@ class EarningService {
|
|
|
618
648
|
* @return {Promise<YieldPoolTarget[]>} List of pool's target
|
|
619
649
|
* */
|
|
620
650
|
async getPoolTargets(slug) {
|
|
621
|
-
|
|
651
|
+
let targets = [];
|
|
652
|
+
if (this.useOnlineCacheOnly) {
|
|
653
|
+
targets = await (0, _fetchStaticCache.fetchStaticCache)(`earning/targets/${slug}.json`, []);
|
|
654
|
+
}
|
|
622
655
|
const handler = this.getPoolHandler(slug);
|
|
623
|
-
if (handler) {
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
return [];
|
|
656
|
+
if (!targets.length && handler) {
|
|
657
|
+
await this.eventService.waitChainReady;
|
|
658
|
+
targets = await handler.getPoolTargets();
|
|
627
659
|
}
|
|
660
|
+
return targets;
|
|
628
661
|
}
|
|
629
662
|
|
|
630
663
|
/* Get pool's targets */
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
8
|
+
var _utils2 = require("@subwallet/extension-base/services/fee-service/utils");
|
|
9
|
+
var _rxjs = require("rxjs");
|
|
10
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
13
|
+
class FeeService {
|
|
14
|
+
evmFeeSubject = new _rxjs.BehaviorSubject({});
|
|
15
|
+
constructor(state) {
|
|
16
|
+
this.state = state;
|
|
17
|
+
this.useInfura = true;
|
|
18
|
+
}
|
|
19
|
+
changeMode(useInfura) {
|
|
20
|
+
this.useInfura = useInfura;
|
|
21
|
+
}
|
|
22
|
+
async updateFees() {
|
|
23
|
+
await this.state.eventService.waitChainReady;
|
|
24
|
+
const activeNetworks = this.state.activeNetworks;
|
|
25
|
+
const chains = Object.values(activeNetworks).filter(chainInfo => (0, _utils._isChainEvmCompatible)(chainInfo)).map(chainInfo => chainInfo.slug);
|
|
26
|
+
const promises = [];
|
|
27
|
+
for (const chain of chains) {
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises,no-async-promise-executor
|
|
29
|
+
const promise = new Promise(async resolve => {
|
|
30
|
+
const api = this.state.getEvmApi(chain);
|
|
31
|
+
const result = await (0, _utils2.calculateGasFeeParams)(api, chain, this.useInfura);
|
|
32
|
+
this.updateChainFee(chain, result);
|
|
33
|
+
resolve();
|
|
34
|
+
});
|
|
35
|
+
promises.push(promise);
|
|
36
|
+
}
|
|
37
|
+
await Promise.all(promises);
|
|
38
|
+
}
|
|
39
|
+
updateChainFee(chain, info) {
|
|
40
|
+
const rs = Object.assign({}, this.evmFeeSubject.getValue());
|
|
41
|
+
rs[chain] = info;
|
|
42
|
+
this.evmFeeSubject.next(rs);
|
|
43
|
+
}
|
|
44
|
+
subscribeFees(callback) {
|
|
45
|
+
let cancel = false;
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line prefer-const
|
|
48
|
+
|
|
49
|
+
const fetchData = () => {
|
|
50
|
+
this.updateFees().finally(() => {
|
|
51
|
+
if (!cancel) {
|
|
52
|
+
callback(this.evmFeeSubject.getValue());
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
fetchData();
|
|
57
|
+
const interval = setInterval(() => {
|
|
58
|
+
if (cancel) {
|
|
59
|
+
clearInterval(interval);
|
|
60
|
+
} else {
|
|
61
|
+
fetchData();
|
|
62
|
+
}
|
|
63
|
+
}, 30 * 1000);
|
|
64
|
+
return () => {
|
|
65
|
+
cancel = true;
|
|
66
|
+
clearInterval(interval);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.default = FeeService;
|