@subwallet/extension-base 1.1.40-1 → 1.1.42-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 +42 -10
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/SubWalleEvmProvider.js +5 -9
- 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 +88 -79
- package/cjs/services/chain-service/utils.js +11 -6
- package/cjs/services/earning-service/constants/chains.js +10 -5
- 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 +144 -45
- 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/databases/MigrateAssetSetting.js +50 -0
- package/cjs/services/migration-service/scripts/index.js +6 -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 +33 -2
- package/package.json +36 -6
- package/packageInfo.js +1 -1
- package/page/SubWalleEvmProvider.d.ts +0 -1
- package/page/SubWalleEvmProvider.js +5 -9
- 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 +8 -4
- package/services/chain-service/index.js +74 -67
- 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.d.ts +3 -0
- package/services/earning-service/constants/chains.js +7 -4
- 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 +144 -45
- 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/databases/MigrateAssetSetting.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +42 -0
- package/services/migration-service/scripts/index.js +5 -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,
|
|
@@ -9,14 +9,30 @@ var _TransactionError = require("@subwallet/extension-base/background/errors/Tra
|
|
|
9
9
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
10
|
var _utils = require("@subwallet/extension-base/koni/api/staking/bonding/utils");
|
|
11
11
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
12
|
+
var _constants2 = require("@subwallet/extension-base/services/earning-service/constants");
|
|
12
13
|
var _utils2 = require("@subwallet/extension-base/services/earning-service/utils");
|
|
13
14
|
var _types = require("@subwallet/extension-base/types");
|
|
14
15
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
16
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
15
17
|
var _util = require("@polkadot/util");
|
|
16
18
|
var _basePara = _interopRequireDefault(require("./base-para"));
|
|
17
19
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
18
20
|
// SPDX-License-Identifier: Apache-2.0
|
|
19
21
|
|
|
22
|
+
function calculateMantaNominatorReturn(decimal, commission, totalActiveCollators, bnAnnualInflation, blocksPreviousRound, bnCollatorExpectedBlocksPerRound, bnCollatorTotalStaked, isCountCommission) {
|
|
23
|
+
const MIN_DELEGATION = new _bignumber.default(_constants2.MANTA_MIN_DELEGATION);
|
|
24
|
+
const factor = new _bignumber.default(10).pow(decimal);
|
|
25
|
+
const annualInflation = bnAnnualInflation.dividedBy(factor);
|
|
26
|
+
const collatorTotalStaked = bnCollatorTotalStaked.dividedBy(factor);
|
|
27
|
+
const annualRewardsPerCollator = annualInflation.dividedBy(totalActiveCollators);
|
|
28
|
+
const adjustmentFactor = new _bignumber.default(blocksPreviousRound).dividedBy(bnCollatorExpectedBlocksPerRound);
|
|
29
|
+
const marginalReward = annualRewardsPerCollator.multipliedBy(MIN_DELEGATION).dividedBy(collatorTotalStaked.plus(MIN_DELEGATION));
|
|
30
|
+
let bnApy = new _bignumber.default(100).multipliedBy(adjustmentFactor).multipliedBy(marginalReward).dividedBy(MIN_DELEGATION);
|
|
31
|
+
if (isCountCommission) {
|
|
32
|
+
bnApy = new _bignumber.default((1 - commission) * 100).multipliedBy(adjustmentFactor).multipliedBy(marginalReward).dividedBy(MIN_DELEGATION);
|
|
33
|
+
}
|
|
34
|
+
return bnApy.toNumber();
|
|
35
|
+
}
|
|
20
36
|
class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
21
37
|
/* Subscribe pool info */
|
|
22
38
|
|
|
@@ -144,13 +160,18 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
144
160
|
const remainingEra = scheduledRequest.whenExecutable - currentRound;
|
|
145
161
|
const waitingTime = remainingEra * _constants._STAKING_ERA_LENGTH_MAP[chainInfo.slug];
|
|
146
162
|
const claimable = Object.values(scheduledRequest.action)[0];
|
|
163
|
+
// const currentTimestampMs = Date.now();
|
|
164
|
+
// const targetTimestampMs = currentTimestampMs + waitingTime * 60 * 60 * 1000;
|
|
165
|
+
|
|
147
166
|
unstakingMap[delegation.owner] = {
|
|
148
167
|
chain: chainInfo.slug,
|
|
149
168
|
status: isClaimable ? _types.UnstakingStatus.CLAIMABLE : _types.UnstakingStatus.UNLOCKING,
|
|
150
169
|
validatorAddress: delegation.owner,
|
|
151
170
|
claimable: claimable.toString(),
|
|
152
171
|
waitingTime
|
|
172
|
+
// targetTimestampMs: targetTimestampMs
|
|
153
173
|
};
|
|
174
|
+
|
|
154
175
|
hasUnstaking = true;
|
|
155
176
|
break; // only handle 1 scheduledRequest per collator
|
|
156
177
|
}
|
|
@@ -253,52 +274,130 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
253
274
|
async getPoolTargets() {
|
|
254
275
|
const apiProps = await this.substrateApi.isReady;
|
|
255
276
|
const allCollators = [];
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
const
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
277
|
+
if (_constants2._STAKING_CHAIN_GROUP.manta.includes(this.chain)) {
|
|
278
|
+
var _this$chainInfo$subst;
|
|
279
|
+
const DECIMAL = (_this$chainInfo$subst = this.chainInfo.substrateInfo) === null || _this$chainInfo$subst === void 0 ? void 0 : _this$chainInfo$subst.decimals;
|
|
280
|
+
const POINTS_PER_BLOCK = _constants2.MANTA_VALIDATOR_POINTS_PER_BLOCK; // producing 1 block will get 20 points for validator
|
|
281
|
+
|
|
282
|
+
const [_allCollators, _collatorCommission, _allCollatorsPool, _selectedCollators, _round, _totalIssuance, _inflationConfig] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo.entries(), apiProps.api.query.parachainStaking.collatorCommission(), apiProps.api.query.parachainStaking.candidatePool(), apiProps.api.query.parachainStaking.selectedCandidates(), apiProps.api.query.parachainStaking.round(), apiProps.api.query.balances.totalIssuance(), apiProps.api.query.parachainStaking.inflationConfig()]);
|
|
283
|
+
|
|
284
|
+
// noted: Annual Inflation = Total Issuance * Annual Inflation Percent
|
|
285
|
+
const round = _round.toPrimitive();
|
|
286
|
+
const totalIssuance = _totalIssuance.toString();
|
|
287
|
+
const inflationConfig = _inflationConfig.toHuman();
|
|
288
|
+
const annualInflationPercent = parseFloat(inflationConfig.annual.ideal.slice(0, -1)) / 100;
|
|
289
|
+
const bnAnnualInflation = new _bignumber.default(totalIssuance).multipliedBy(annualInflationPercent);
|
|
290
|
+
|
|
291
|
+
// noted: allCollatorsPool -> all candidate collators; selectedCollators -> candidate collators selected in current round
|
|
292
|
+
const allCollatorsPoolInfo = _allCollatorsPool.toPrimitive();
|
|
293
|
+
const allCollatorsPool = allCollatorsPoolInfo.map(collator => collator.owner.toString());
|
|
294
|
+
const selectedCollators = _selectedCollators.toPrimitive();
|
|
295
|
+
const totalActiveCollators = selectedCollators.length;
|
|
296
|
+
const bnCollatorExpectedBlocksPerRound = new _bignumber.default(round.length).dividedBy(allCollatorsPool.length);
|
|
297
|
+
const maxDelegationPerCollator = apiProps.api.consts.parachainStaking.maxTopDelegationsPerCandidate.toString();
|
|
298
|
+
const rawCollatorCommission = _collatorCommission.toHuman();
|
|
299
|
+
const collatorCommission = parseFloat(rawCollatorCommission.split('%')[0]);
|
|
300
|
+
const collatorCommissionPercent = collatorCommission / 100;
|
|
301
|
+
for (const collator of _allCollators) {
|
|
302
|
+
const _collatorAddress = collator[0].toHuman();
|
|
303
|
+
const collatorAddress = _collatorAddress[0];
|
|
304
|
+
if (allCollatorsPool.includes(collatorAddress)) {
|
|
305
|
+
const collatorInfo = collator[1].toPrimitive();
|
|
306
|
+
const bnTotalStake = new _util.BN(collatorInfo.totalCounted);
|
|
307
|
+
const bnOwnStake = new _util.BN(collatorInfo.bond);
|
|
308
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
309
|
+
const bnMinBond = new _util.BN(collatorInfo.lowestTopDelegationAmount);
|
|
310
|
+
allCollators.push({
|
|
311
|
+
commission: 0,
|
|
312
|
+
address: collatorAddress,
|
|
313
|
+
totalStake: bnTotalStake.toString(),
|
|
314
|
+
ownStake: bnOwnStake.toString(),
|
|
315
|
+
otherStake: bnOtherStake.toString(),
|
|
316
|
+
nominatorCount: collatorInfo.delegationCount,
|
|
317
|
+
blocked: false,
|
|
318
|
+
isVerified: false,
|
|
319
|
+
minBond: bnMinBond.toString(),
|
|
320
|
+
chain: this.chain,
|
|
321
|
+
isCrowded: parseInt(maxDelegationPerCollator) > 0
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
await Promise.all(allCollators.map(async collator => {
|
|
326
|
+
if (allCollatorsPool.includes(collator.address)) {
|
|
327
|
+
// noted: number of blocks = total points / points per block
|
|
328
|
+
const _collatorPoints = await apiProps.api.query.parachainStaking.awardedPts(parseInt(round.current) - 1, collator.address);
|
|
329
|
+
const collatorPoints = _collatorPoints.toPrimitive();
|
|
330
|
+
const blocksPreviousRound = collatorPoints / POINTS_PER_BLOCK;
|
|
331
|
+
collator.expectedReturn = calculateMantaNominatorReturn(DECIMAL, collatorCommissionPercent, totalActiveCollators, bnAnnualInflation, blocksPreviousRound, bnCollatorExpectedBlocksPerRound, new _bignumber.default(collator.totalStake), false);
|
|
332
|
+
}
|
|
333
|
+
}));
|
|
334
|
+
const extraInfoMap = {};
|
|
335
|
+
await Promise.all(allCollators.map(async collator => {
|
|
336
|
+
const [_info, [identity, isReasonable]] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), (0, _utils2.parseIdentity)(apiProps, collator.address)]);
|
|
337
|
+
const rawInfo = _info.toHuman();
|
|
338
|
+
const active = (rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.status) === 'Active';
|
|
339
|
+
extraInfoMap[collator.address] = {
|
|
340
|
+
identity,
|
|
341
|
+
isVerified: isReasonable,
|
|
342
|
+
active
|
|
343
|
+
};
|
|
344
|
+
}));
|
|
345
|
+
for (const validator of allCollators) {
|
|
346
|
+
validator.blocked = !extraInfoMap[validator.address].active;
|
|
347
|
+
validator.identity = extraInfoMap[validator.address].identity;
|
|
348
|
+
validator.isVerified = extraInfoMap[validator.address].isVerified;
|
|
349
|
+
// @ts-ignore
|
|
350
|
+
validator.commission = collatorCommission;
|
|
351
|
+
}
|
|
352
|
+
return allCollators;
|
|
353
|
+
} else {
|
|
354
|
+
const [_allCollators, _collatorCommission] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo.entries(), apiProps.api.query.parachainStaking.collatorCommission()]);
|
|
355
|
+
const maxDelegationPerCollator = apiProps.api.consts.parachainStaking.maxTopDelegationsPerCandidate.toString();
|
|
356
|
+
const rawCollatorCommission = _collatorCommission.toHuman();
|
|
357
|
+
const collatorCommission = parseFloat(rawCollatorCommission.split('%')[0]);
|
|
358
|
+
for (const collator of _allCollators) {
|
|
359
|
+
const _collatorAddress = collator[0].toHuman();
|
|
360
|
+
const collatorAddress = _collatorAddress[0];
|
|
361
|
+
const collatorInfo = collator[1].toPrimitive();
|
|
362
|
+
const bnTotalStake = new _util.BN(collatorInfo.totalCounted);
|
|
363
|
+
const bnOwnStake = new _util.BN(collatorInfo.bond);
|
|
364
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
365
|
+
const bnMinBond = new _util.BN(collatorInfo.lowestTopDelegationAmount);
|
|
366
|
+
allCollators.push({
|
|
367
|
+
commission: 0,
|
|
368
|
+
expectedReturn: 0,
|
|
369
|
+
address: collatorAddress,
|
|
370
|
+
totalStake: bnTotalStake.toString(),
|
|
371
|
+
ownStake: bnOwnStake.toString(),
|
|
372
|
+
otherStake: bnOtherStake.toString(),
|
|
373
|
+
nominatorCount: collatorInfo.delegationCount,
|
|
374
|
+
blocked: false,
|
|
375
|
+
isVerified: false,
|
|
376
|
+
minBond: bnMinBond.toString(),
|
|
377
|
+
chain: this.chain,
|
|
378
|
+
isCrowded: parseInt(maxDelegationPerCollator) > 0
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
const extraInfoMap = {};
|
|
382
|
+
await Promise.all(allCollators.map(async collator => {
|
|
383
|
+
const [_info, [identity, isReasonable]] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), (0, _utils2.parseIdentity)(apiProps, collator.address)]);
|
|
384
|
+
const rawInfo = _info.toHuman();
|
|
385
|
+
const active = (rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.status) === 'Active';
|
|
386
|
+
extraInfoMap[collator.address] = {
|
|
387
|
+
identity,
|
|
388
|
+
isVerified: isReasonable,
|
|
389
|
+
active
|
|
390
|
+
};
|
|
391
|
+
}));
|
|
392
|
+
for (const validator of allCollators) {
|
|
393
|
+
validator.blocked = !extraInfoMap[validator.address].active;
|
|
394
|
+
validator.identity = extraInfoMap[validator.address].identity;
|
|
395
|
+
validator.isVerified = extraInfoMap[validator.address].isVerified;
|
|
396
|
+
// @ts-ignore
|
|
397
|
+
validator.commission = collatorCommission;
|
|
398
|
+
}
|
|
399
|
+
return allCollators;
|
|
300
400
|
}
|
|
301
|
-
return allCollators;
|
|
302
401
|
}
|
|
303
402
|
|
|
304
403
|
/* Get pool targets */
|
|
@@ -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;
|