@subwallet/extension-base 1.1.41-0 → 1.1.43-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/cjs/koni/background/handlers/State.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/SubWalleEvmProvider.js +5 -9
- package/cjs/services/chain-service/constants.js +3 -3
- package/cjs/services/chain-service/index.js +27 -32
- package/cjs/services/earning-service/constants/chains.js +8 -3
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +139 -45
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +50 -0
- package/cjs/services/migration-service/scripts/index.js +3 -0
- package/koni/background/handlers/State.js +1 -1
- package/package.json +11 -6
- package/packageInfo.js +1 -1
- package/page/SubWalleEvmProvider.d.ts +0 -1
- package/page/SubWalleEvmProvider.js +5 -9
- package/services/chain-service/constants.js +3 -3
- package/services/chain-service/index.d.ts +1 -1
- package/services/chain-service/index.js +12 -18
- package/services/earning-service/constants/chains.d.ts +3 -0
- package/services/earning-service/constants/chains.js +5 -2
- package/services/earning-service/handlers/native-staking/para-chain.js +139 -45
- 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 +2 -0
|
@@ -824,7 +824,7 @@ class KoniState {
|
|
|
824
824
|
return this.chainService.getMultiChainAssetMap();
|
|
825
825
|
}
|
|
826
826
|
getXcmRefMap() {
|
|
827
|
-
return this.chainService.
|
|
827
|
+
return this.chainService.xcmRefMap;
|
|
828
828
|
}
|
|
829
829
|
getAssetByChainAndAsset(chain, assetTypes) {
|
|
830
830
|
return this.chainService.getAssetByChainAndType(chain, assetTypes);
|
package/cjs/packageInfo.js
CHANGED
|
@@ -14,7 +14,6 @@ class SubWalletEvmProvider extends _safeEventEmitter.default {
|
|
|
14
14
|
isSubWallet = true;
|
|
15
15
|
isMetaMask = false;
|
|
16
16
|
_connected = false;
|
|
17
|
-
_isEnable = false;
|
|
18
17
|
constructor(sendMessage, version) {
|
|
19
18
|
super();
|
|
20
19
|
this.version = version;
|
|
@@ -76,13 +75,11 @@ class SubWalletEvmProvider extends _safeEventEmitter.default {
|
|
|
76
75
|
method,
|
|
77
76
|
params
|
|
78
77
|
} = _ref2;
|
|
79
|
-
if (!this._isEnable) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
}
|
|
78
|
+
// if (!this._isEnable) {
|
|
79
|
+
// if (method === 'eth_accounts') {
|
|
80
|
+
// return this.request<T>({ method: 'eth_requestAccounts' });
|
|
81
|
+
// }
|
|
82
|
+
// }
|
|
86
83
|
|
|
87
84
|
// Subscribe events
|
|
88
85
|
switch (method) {
|
|
@@ -93,7 +90,6 @@ class SubWalletEvmProvider extends _safeEventEmitter.default {
|
|
|
93
90
|
origin,
|
|
94
91
|
accountAuthType: 'evm'
|
|
95
92
|
}).then(() => {
|
|
96
|
-
this._isEnable = true;
|
|
97
93
|
// Return account list
|
|
98
94
|
this.request({
|
|
99
95
|
method: 'eth_accounts'
|
|
@@ -40,7 +40,7 @@ const _BALANCE_CHAIN_GROUP = {
|
|
|
40
40
|
genshiro: ['genshiro_testnet', 'genshiro'],
|
|
41
41
|
equilibrium_parachain: ['equilibrium_parachain'],
|
|
42
42
|
bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'pendulum', 'amplitude', 'continuum_network'],
|
|
43
|
-
statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland'],
|
|
43
|
+
statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland', 'dentnet'],
|
|
44
44
|
kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
|
|
45
45
|
// perhaps there are some runtime updates
|
|
46
46
|
centrifuge: ['centrifuge'],
|
|
@@ -221,13 +221,13 @@ const _TRANSFER_CHAIN_GROUP = {
|
|
|
221
221
|
genshiro: ['genshiro_testnet', 'genshiro', 'equilibrium_parachain'],
|
|
222
222
|
crab: ['crab', 'pangolin'],
|
|
223
223
|
bitcountry: ['pioneer', 'bitcountry', 'bifrost', 'bifrost_dot'],
|
|
224
|
-
statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel', 'liberland', 'liberlandTest'],
|
|
224
|
+
statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel', 'liberland', 'liberlandTest', 'dentnet'],
|
|
225
225
|
riochain: ['riochain'],
|
|
226
226
|
sora_substrate: ['sora_substrate'],
|
|
227
227
|
avail: ['kate', 'goldberg_testnet'],
|
|
228
228
|
pendulum: ['pendulum', 'amplitude', 'amplitude_test', 'hydradx_main'],
|
|
229
229
|
centrifuge: ['centrifuge'],
|
|
230
|
-
disable_transfer: ['invarch'
|
|
230
|
+
disable_transfer: ['invarch']
|
|
231
231
|
};
|
|
232
232
|
exports._TRANSFER_CHAIN_GROUP = _TRANSFER_CHAIN_GROUP;
|
|
233
233
|
const _BALANCE_PARSING_CHAIN_GROUP = {
|
|
@@ -52,7 +52,7 @@ class ChainService {
|
|
|
52
52
|
this.chainInfoMapSubject.next(this.dataMap.chainInfoMap);
|
|
53
53
|
this.chainStateMapSubject.next(this.dataMap.chainStateMap);
|
|
54
54
|
this.assetRegistrySubject.next(this.dataMap.assetRegistry);
|
|
55
|
-
this.xcmRefMapSubject.next(this.
|
|
55
|
+
this.xcmRefMapSubject.next(this.xcmRefMap);
|
|
56
56
|
if (_utils2.MODULE_SUPPORT.MANTA_ZK) {
|
|
57
57
|
console.log('Init Manta ZK');
|
|
58
58
|
this.mantaChainHandler = new _MantaPrivateHandler.MantaPrivateHandler(dbService);
|
|
@@ -63,19 +63,16 @@ class ChainService {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// Getter
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
// return result;
|
|
66
|
+
get xcmRefMap() {
|
|
67
|
+
const result = {};
|
|
68
|
+
Object.entries(this.dataMap.assetRefMap).forEach(_ref => {
|
|
69
|
+
let [key, assetRef] = _ref;
|
|
70
|
+
if (assetRef.path === _types._AssetRefPath.XCM) {
|
|
71
|
+
result[key] = assetRef;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return result;
|
|
77
75
|
}
|
|
78
|
-
|
|
79
76
|
getEvmApi(slug) {
|
|
80
77
|
return this.evmChainHandler.getEvmApiByChain(slug);
|
|
81
78
|
}
|
|
@@ -199,11 +196,11 @@ class ChainService {
|
|
|
199
196
|
return this.getChainStatusMap()[key];
|
|
200
197
|
}
|
|
201
198
|
getActiveChains() {
|
|
202
|
-
return Object.entries(this.dataMap.chainStateMap).filter(
|
|
203
|
-
let [, chainState] =
|
|
199
|
+
return Object.entries(this.dataMap.chainStateMap).filter(_ref2 => {
|
|
200
|
+
let [, chainState] = _ref2;
|
|
204
201
|
return (0, _utils._isChainEnabled)(chainState);
|
|
205
|
-
}).map(
|
|
206
|
-
let [key] =
|
|
202
|
+
}).map(_ref3 => {
|
|
203
|
+
let [key] = _ref3;
|
|
207
204
|
return key;
|
|
208
205
|
});
|
|
209
206
|
}
|
|
@@ -274,7 +271,7 @@ class ChainService {
|
|
|
274
271
|
if (asset.originChain === destinationChainSlug) {
|
|
275
272
|
// check
|
|
276
273
|
const assetRefKey = (0, _utils._parseAssetRefKey)(originTokenSlug, asset.slug);
|
|
277
|
-
const assetRef = this.
|
|
274
|
+
const assetRef = this.xcmRefMap[assetRefKey];
|
|
278
275
|
if (assetRef && assetRef.path === _types._AssetRefPath.XCM) {
|
|
279
276
|
// there's only 1 corresponding token on 1 chain
|
|
280
277
|
destinationTokenInfo = asset;
|
|
@@ -369,8 +366,8 @@ class ChainService {
|
|
|
369
366
|
(0, _utils2.addLazy)('updateChainConnectionStatus', () => {
|
|
370
367
|
const chainStatusMap = this.getChainStatusMap();
|
|
371
368
|
let update = false;
|
|
372
|
-
Object.entries(this.connectionStatusQueueMap).forEach(
|
|
373
|
-
let [slug, status] =
|
|
369
|
+
Object.entries(this.connectionStatusQueueMap).forEach(_ref4 => {
|
|
370
|
+
let [slug, status] = _ref4;
|
|
374
371
|
if (chainStatusMap[slug]) {
|
|
375
372
|
if (chainStatusMap[slug].connectionStatus !== status) {
|
|
376
373
|
chainStatusMap[slug].connectionStatus = status;
|
|
@@ -451,7 +448,7 @@ class ChainService {
|
|
|
451
448
|
await this.initChains();
|
|
452
449
|
this.chainInfoMapSubject.next(this.getChainInfoMap());
|
|
453
450
|
this.assetRegistrySubject.next(this.getAssetRegistry());
|
|
454
|
-
this.xcmRefMapSubject.next(this.
|
|
451
|
+
this.xcmRefMapSubject.next(this.xcmRefMap);
|
|
455
452
|
await this.initApis();
|
|
456
453
|
await this.initAssetSettings();
|
|
457
454
|
await this.initAssetRefMap();
|
|
@@ -511,15 +508,13 @@ class ChainService {
|
|
|
511
508
|
delete updatedAssetRefMap[blockedAssetRef];
|
|
512
509
|
});
|
|
513
510
|
this.dataMap.assetRefMap = updatedAssetRefMap;
|
|
514
|
-
|
|
515
|
-
// this.dbService.setAssetRef(this.dataMap.assetRefMap).catch(console.error);
|
|
516
|
-
this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
|
|
511
|
+
this.xcmRefMapSubject.next(this.xcmRefMap);
|
|
517
512
|
this.logger.log('Finished updating latest asset ref');
|
|
518
513
|
}
|
|
519
514
|
handleLatestPriceId(latestPriceIds) {
|
|
520
515
|
let isUpdated = false;
|
|
521
|
-
Object.entries(latestPriceIds).forEach(
|
|
522
|
-
let [slug, priceId] =
|
|
516
|
+
Object.entries(latestPriceIds).forEach(_ref5 => {
|
|
517
|
+
let [slug, priceId] = _ref5;
|
|
523
518
|
if (this.dataMap.assetRegistry[slug] && this.dataMap.assetRegistry[slug].priceId !== priceId) {
|
|
524
519
|
isUpdated = true;
|
|
525
520
|
this.dataMap.assetRegistry[slug].priceId = priceId;
|
|
@@ -545,12 +540,12 @@ class ChainService {
|
|
|
545
540
|
async initApis() {
|
|
546
541
|
const chainInfoMap = this.getChainInfoMap();
|
|
547
542
|
const chainStateMap = this.getChainStateMap();
|
|
548
|
-
await Promise.all(Object.entries(chainInfoMap).filter(
|
|
543
|
+
await Promise.all(Object.entries(chainInfoMap).filter(_ref6 => {
|
|
549
544
|
var _chainStateMap$slug;
|
|
550
|
-
let [slug] =
|
|
545
|
+
let [slug] = _ref6;
|
|
551
546
|
return (_chainStateMap$slug = chainStateMap[slug]) === null || _chainStateMap$slug === void 0 ? void 0 : _chainStateMap$slug.active;
|
|
552
|
-
}).map(
|
|
553
|
-
let [, chainInfo] =
|
|
547
|
+
}).map(_ref7 => {
|
|
548
|
+
let [, chainInfo] = _ref7;
|
|
554
549
|
try {
|
|
555
550
|
return this.initApiForChain(chainInfo);
|
|
556
551
|
} catch (e) {
|
|
@@ -875,8 +870,8 @@ class ChainService {
|
|
|
875
870
|
}
|
|
876
871
|
|
|
877
872
|
// Fill in the missing chainState and storageData (new chains never before seen)
|
|
878
|
-
Object.entries(mergedChainInfoMap).forEach(
|
|
879
|
-
let [slug, chainInfo] =
|
|
873
|
+
Object.entries(mergedChainInfoMap).forEach(_ref8 => {
|
|
874
|
+
let [slug, chainInfo] = _ref8;
|
|
880
875
|
if (!(slug in this.dataMap.chainStateMap)) {
|
|
881
876
|
this.dataMap.chainStateMap[slug] = {
|
|
882
877
|
currentProvider: Object.keys(chainInfo.providers)[0],
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports._STAKING_CHAIN_GROUP = exports.ST_LIQUID_TOKEN_ABI = void 0;
|
|
6
|
+
exports._STAKING_CHAIN_GROUP = exports.ST_LIQUID_TOKEN_ABI = exports.MANTA_VALIDATOR_POINTS_PER_BLOCK = exports.MANTA_MIN_DELEGATION = void 0;
|
|
7
7
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
|
|
@@ -21,10 +21,15 @@ const _STAKING_CHAIN_GROUP = {
|
|
|
21
21
|
ternoa: ['ternoa'],
|
|
22
22
|
liquidStaking: ['bifrost_dot', 'acala', 'parallel', 'moonbeam'],
|
|
23
23
|
lending: ['interlay'],
|
|
24
|
-
krest_network: ['krest_network']
|
|
24
|
+
krest_network: ['krest_network'],
|
|
25
|
+
manta: ['manta_network']
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
28
29
|
exports._STAKING_CHAIN_GROUP = _STAKING_CHAIN_GROUP;
|
|
29
30
|
const ST_LIQUID_TOKEN_ABI = require('./abis/st_liquid_token_abi.json');
|
|
30
|
-
exports.ST_LIQUID_TOKEN_ABI = ST_LIQUID_TOKEN_ABI;
|
|
31
|
+
exports.ST_LIQUID_TOKEN_ABI = ST_LIQUID_TOKEN_ABI;
|
|
32
|
+
const MANTA_VALIDATOR_POINTS_PER_BLOCK = 20;
|
|
33
|
+
exports.MANTA_VALIDATOR_POINTS_PER_BLOCK = MANTA_VALIDATOR_POINTS_PER_BLOCK;
|
|
34
|
+
const MANTA_MIN_DELEGATION = 500;
|
|
35
|
+
exports.MANTA_MIN_DELEGATION = MANTA_MIN_DELEGATION;
|
|
@@ -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
|
|
|
@@ -258,52 +274,130 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
|
|
|
258
274
|
async getPoolTargets() {
|
|
259
275
|
const apiProps = await this.substrateApi.isReady;
|
|
260
276
|
const allCollators = [];
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
const
|
|
271
|
-
const
|
|
272
|
-
const
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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;
|
|
305
400
|
}
|
|
306
|
-
return allCollators;
|
|
307
401
|
}
|
|
308
402
|
|
|
309
403
|
/* Get pool targets */
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _Base = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/Base"));
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
class MigrateAssetSetting extends _Base.default {
|
|
13
|
+
async run() {
|
|
14
|
+
try {
|
|
15
|
+
const oldSlugs = ['ethereum-ERC20-WFTM-0x4E15361FD6b4BB609Fa63C81A2be19d873717870', 'moonbeam-ERC20-CSG-0x2Dfc76901bB2ac2A5fA5fc479590A490BBB10a5F', 'astar-LOCAL-aUSD', 'astarEvm-ERC20-aUSD-0xfFFFFfFF00000000000000010000000000000001',
|
|
16
|
+
//
|
|
17
|
+
'moonriver-LOCAL-xcaUSD',
|
|
18
|
+
//
|
|
19
|
+
'moonriver-LOCAL-xckBTC', 'bifrost-LOCAL-aUSD', 'calamari-LOCAL-AUSD', 'shiden-LOCAL-aUSD', 'shidenEvm-ERC20-aUSD-0xfFFfFFfF00000000000000010000000000000000',
|
|
20
|
+
//
|
|
21
|
+
'ethereum_goerli-NATIVE-GoerliETH', 'binance_test-NATIVE-BNB',
|
|
22
|
+
//
|
|
23
|
+
'pangolin-LOCAL-CKTON',
|
|
24
|
+
//
|
|
25
|
+
'zeta_test-NATIVE-aZETA' //
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const newSlugs = ['ethereum-ERC20-FTM-0x4E15361FD6b4BB609Fa63C81A2be19d873717870', 'moonbeam-ERC20-CGS-0x2Dfc76901bB2ac2A5fA5fc479590A490BBB10a5F', 'astar-LOCAL-aSEED', 'astarEvm-ERC20-aSEED-0xfFFFFfFF00000000000000010000000000000001', 'moonriver-LOCAL-xcaSeed', 'moonriver-LOCAL-xcKBTC', 'bifrost-LOCAL-KUSD', 'calamari-LOCAL-AUSD', 'shiden-LOCAL-aSEED', 'shidenEvm-ERC20-aSEED-0xfFFfFFfF00000000000000010000000000000000', 'ethereum_goerli-NATIVE-ETH', 'binance_test-NATIVE-tBNB', 'pangolin-LOCAL-PKTON', 'zeta_test-NATIVE-ZETA'];
|
|
29
|
+
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
30
|
+
const migratedAssetSetting = {};
|
|
31
|
+
for (let i = 0; i < oldSlugs.length; i++) {
|
|
32
|
+
const slug = oldSlugs[i];
|
|
33
|
+
if (Object.keys(assetSetting).includes(slug)) {
|
|
34
|
+
const isVisible = assetSetting[slug].visible;
|
|
35
|
+
const newSlug = newSlugs[i];
|
|
36
|
+
migratedAssetSetting[newSlug] = {
|
|
37
|
+
visible: isVisible
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
this.state.chainService.setAssetSettings({
|
|
42
|
+
...assetSetting,
|
|
43
|
+
...migratedAssetSetting
|
|
44
|
+
});
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.error(e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = MigrateAssetSetting;
|
|
@@ -28,6 +28,8 @@ var _MigrateWalletReference = _interopRequireDefault(require("./MigrateWalletRef
|
|
|
28
28
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
29
29
|
// SPDX-License-Identifier: Apache-2.0
|
|
30
30
|
|
|
31
|
+
// import MigrateAssetSetting from './databases/MigrateAssetSetting';
|
|
32
|
+
|
|
31
33
|
const EVERYTIME = '__everytime__';
|
|
32
34
|
exports.EVERYTIME = EVERYTIME;
|
|
33
35
|
var _default = {
|
|
@@ -52,6 +54,7 @@ var _default = {
|
|
|
52
54
|
'1.1.26-01': _MigratePolygonUSDCProvider.default,
|
|
53
55
|
'1.1.28-01': _MigrateEarningVersion.default,
|
|
54
56
|
'1.1.41-01': _DeleteChainStaking.default
|
|
57
|
+
// '1.1.41-02': MigrateAssetSetting
|
|
55
58
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
56
59
|
};
|
|
57
60
|
exports.default = _default;
|
|
@@ -810,7 +810,7 @@ export default class KoniState {
|
|
|
810
810
|
return this.chainService.getMultiChainAssetMap();
|
|
811
811
|
}
|
|
812
812
|
getXcmRefMap() {
|
|
813
|
-
return this.chainService.
|
|
813
|
+
return this.chainService.xcmRefMap;
|
|
814
814
|
}
|
|
815
815
|
getAssetByChainAndAsset(chain, assetTypes) {
|
|
816
816
|
return this.chainService.getAssetByChainAndType(chain, assetTypes);
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.1.
|
|
20
|
+
"version": "1.1.43-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -940,6 +940,11 @@
|
|
|
940
940
|
"require": "./cjs/services/migration-service/scripts/ClearOldStorage.js",
|
|
941
941
|
"default": "./services/migration-service/scripts/ClearOldStorage.js"
|
|
942
942
|
},
|
|
943
|
+
"./services/migration-service/scripts/databases/MigrateAssetSetting": {
|
|
944
|
+
"types": "./services/migration-service/scripts/databases/MigrateAssetSetting.d.ts",
|
|
945
|
+
"require": "./cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js",
|
|
946
|
+
"default": "./services/migration-service/scripts/databases/MigrateAssetSetting.js"
|
|
947
|
+
},
|
|
943
948
|
"./services/migration-service/scripts/databases/MigrateEarningHistory": {
|
|
944
949
|
"types": "./services/migration-service/scripts/databases/MigrateEarningHistory.d.ts",
|
|
945
950
|
"require": "./cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js",
|
|
@@ -1786,11 +1791,11 @@
|
|
|
1786
1791
|
"@reduxjs/toolkit": "^1.9.1",
|
|
1787
1792
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1788
1793
|
"@substrate/connect": "^0.7.26",
|
|
1789
|
-
"@subwallet/chain-list": "0.2.
|
|
1790
|
-
"@subwallet/extension-base": "^1.1.
|
|
1791
|
-
"@subwallet/extension-chains": "^1.1.
|
|
1792
|
-
"@subwallet/extension-dapp": "^1.1.
|
|
1793
|
-
"@subwallet/extension-inject": "^1.1.
|
|
1794
|
+
"@subwallet/chain-list": "0.2.43",
|
|
1795
|
+
"@subwallet/extension-base": "^1.1.43-0",
|
|
1796
|
+
"@subwallet/extension-chains": "^1.1.43-0",
|
|
1797
|
+
"@subwallet/extension-dapp": "^1.1.43-0",
|
|
1798
|
+
"@subwallet/extension-inject": "^1.1.43-0",
|
|
1794
1799
|
"@subwallet/keyring": "^0.1.3",
|
|
1795
1800
|
"@subwallet/ui-keyring": "^0.1.3",
|
|
1796
1801
|
"@walletconnect/sign-client": "^2.8.4",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.1.
|
|
10
|
+
version: '1.1.43-0'
|
|
11
11
|
};
|
|
@@ -12,7 +12,6 @@ export declare class SubWalletEvmProvider extends SafeEventEmitter implements Ev
|
|
|
12
12
|
readonly version: string;
|
|
13
13
|
protected sendMessage: SendRequest;
|
|
14
14
|
protected _connected: boolean;
|
|
15
|
-
private _isEnable;
|
|
16
15
|
constructor(sendMessage: SendRequest, version: string);
|
|
17
16
|
get connected(): boolean;
|
|
18
17
|
isConnected(): boolean;
|
|
@@ -7,7 +7,6 @@ export class SubWalletEvmProvider extends SafeEventEmitter {
|
|
|
7
7
|
isSubWallet = true;
|
|
8
8
|
isMetaMask = false;
|
|
9
9
|
_connected = false;
|
|
10
|
-
_isEnable = false;
|
|
11
10
|
constructor(sendMessage, version) {
|
|
12
11
|
super();
|
|
13
12
|
this.version = version;
|
|
@@ -67,13 +66,11 @@ export class SubWalletEvmProvider extends SafeEventEmitter {
|
|
|
67
66
|
method,
|
|
68
67
|
params
|
|
69
68
|
}) {
|
|
70
|
-
if (!this._isEnable) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
}
|
|
69
|
+
// if (!this._isEnable) {
|
|
70
|
+
// if (method === 'eth_accounts') {
|
|
71
|
+
// return this.request<T>({ method: 'eth_requestAccounts' });
|
|
72
|
+
// }
|
|
73
|
+
// }
|
|
77
74
|
|
|
78
75
|
// Subscribe events
|
|
79
76
|
switch (method) {
|
|
@@ -84,7 +81,6 @@ export class SubWalletEvmProvider extends SafeEventEmitter {
|
|
|
84
81
|
origin,
|
|
85
82
|
accountAuthType: 'evm'
|
|
86
83
|
}).then(() => {
|
|
87
|
-
this._isEnable = true;
|
|
88
84
|
// Return account list
|
|
89
85
|
this.request({
|
|
90
86
|
method: 'eth_accounts'
|
|
@@ -29,7 +29,7 @@ export const _BALANCE_CHAIN_GROUP = {
|
|
|
29
29
|
genshiro: ['genshiro_testnet', 'genshiro'],
|
|
30
30
|
equilibrium_parachain: ['equilibrium_parachain'],
|
|
31
31
|
bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'pendulum', 'amplitude', 'continuum_network'],
|
|
32
|
-
statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland'],
|
|
32
|
+
statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland', 'dentnet'],
|
|
33
33
|
kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
|
|
34
34
|
// perhaps there are some runtime updates
|
|
35
35
|
centrifuge: ['centrifuge'],
|
|
@@ -203,13 +203,13 @@ export const _TRANSFER_CHAIN_GROUP = {
|
|
|
203
203
|
genshiro: ['genshiro_testnet', 'genshiro', 'equilibrium_parachain'],
|
|
204
204
|
crab: ['crab', 'pangolin'],
|
|
205
205
|
bitcountry: ['pioneer', 'bitcountry', 'bifrost', 'bifrost_dot'],
|
|
206
|
-
statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel', 'liberland', 'liberlandTest'],
|
|
206
|
+
statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel', 'liberland', 'liberlandTest', 'dentnet'],
|
|
207
207
|
riochain: ['riochain'],
|
|
208
208
|
sora_substrate: ['sora_substrate'],
|
|
209
209
|
avail: ['kate', 'goldberg_testnet'],
|
|
210
210
|
pendulum: ['pendulum', 'amplitude', 'amplitude_test', 'hydradx_main'],
|
|
211
211
|
centrifuge: ['centrifuge'],
|
|
212
|
-
disable_transfer: ['invarch'
|
|
212
|
+
disable_transfer: ['invarch']
|
|
213
213
|
};
|
|
214
214
|
export const _BALANCE_PARSING_CHAIN_GROUP = {
|
|
215
215
|
bobabeam: ['bobabeam', 'bobabase']
|
|
@@ -27,7 +27,7 @@ export declare class ChainService {
|
|
|
27
27
|
private assetSettingSubject;
|
|
28
28
|
private logger;
|
|
29
29
|
constructor(dbService: DatabaseService, eventService: EventService);
|
|
30
|
-
|
|
30
|
+
get xcmRefMap(): Record<string, _AssetRef>;
|
|
31
31
|
getEvmApi(slug: string): import("./handler/EvmApi").EvmApi;
|
|
32
32
|
getEvmApiMap(): Record<string, import("./handler/EvmApi").EvmApi>;
|
|
33
33
|
getSubstrateApiMap(): Record<string, import("./handler/SubstrateApi").SubstrateApi>;
|
|
@@ -45,7 +45,7 @@ export class ChainService {
|
|
|
45
45
|
this.chainInfoMapSubject.next(this.dataMap.chainInfoMap);
|
|
46
46
|
this.chainStateMapSubject.next(this.dataMap.chainStateMap);
|
|
47
47
|
this.assetRegistrySubject.next(this.dataMap.assetRegistry);
|
|
48
|
-
this.xcmRefMapSubject.next(this.
|
|
48
|
+
this.xcmRefMapSubject.next(this.xcmRefMap);
|
|
49
49
|
if (MODULE_SUPPORT.MANTA_ZK) {
|
|
50
50
|
console.log('Init Manta ZK');
|
|
51
51
|
this.mantaChainHandler = new MantaPrivateHandler(dbService);
|
|
@@ -56,19 +56,15 @@ export class ChainService {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// Getter
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// });
|
|
68
|
-
//
|
|
69
|
-
// return result;
|
|
59
|
+
get xcmRefMap() {
|
|
60
|
+
const result = {};
|
|
61
|
+
Object.entries(this.dataMap.assetRefMap).forEach(([key, assetRef]) => {
|
|
62
|
+
if (assetRef.path === _AssetRefPath.XCM) {
|
|
63
|
+
result[key] = assetRef;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
getEvmApi(slug) {
|
|
73
69
|
return this.evmChainHandler.getEvmApiByChain(slug);
|
|
74
70
|
}
|
|
@@ -260,7 +256,7 @@ export class ChainService {
|
|
|
260
256
|
if (asset.originChain === destinationChainSlug) {
|
|
261
257
|
// check
|
|
262
258
|
const assetRefKey = _parseAssetRefKey(originTokenSlug, asset.slug);
|
|
263
|
-
const assetRef = this.
|
|
259
|
+
const assetRef = this.xcmRefMap[assetRefKey];
|
|
264
260
|
if (assetRef && assetRef.path === _AssetRefPath.XCM) {
|
|
265
261
|
// there's only 1 corresponding token on 1 chain
|
|
266
262
|
destinationTokenInfo = asset;
|
|
@@ -436,7 +432,7 @@ export class ChainService {
|
|
|
436
432
|
await this.initChains();
|
|
437
433
|
this.chainInfoMapSubject.next(this.getChainInfoMap());
|
|
438
434
|
this.assetRegistrySubject.next(this.getAssetRegistry());
|
|
439
|
-
this.xcmRefMapSubject.next(this.
|
|
435
|
+
this.xcmRefMapSubject.next(this.xcmRefMap);
|
|
440
436
|
await this.initApis();
|
|
441
437
|
await this.initAssetSettings();
|
|
442
438
|
await this.initAssetRefMap();
|
|
@@ -496,9 +492,7 @@ export class ChainService {
|
|
|
496
492
|
delete updatedAssetRefMap[blockedAssetRef];
|
|
497
493
|
});
|
|
498
494
|
this.dataMap.assetRefMap = updatedAssetRefMap;
|
|
499
|
-
|
|
500
|
-
// this.dbService.setAssetRef(this.dataMap.assetRefMap).catch(console.error);
|
|
501
|
-
this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
|
|
495
|
+
this.xcmRefMapSubject.next(this.xcmRefMap);
|
|
502
496
|
this.logger.log('Finished updating latest asset ref');
|
|
503
497
|
}
|
|
504
498
|
handleLatestPriceId(latestPriceIds) {
|
|
@@ -11,5 +11,8 @@ export declare const _STAKING_CHAIN_GROUP: {
|
|
|
11
11
|
liquidStaking: string[];
|
|
12
12
|
lending: string[];
|
|
13
13
|
krest_network: string[];
|
|
14
|
+
manta: string[];
|
|
14
15
|
};
|
|
15
16
|
export declare const ST_LIQUID_TOKEN_ABI: Record<string, any>;
|
|
17
|
+
export declare const MANTA_VALIDATOR_POINTS_PER_BLOCK = 20;
|
|
18
|
+
export declare const MANTA_MIN_DELEGATION = 500;
|
|
@@ -15,8 +15,11 @@ export const _STAKING_CHAIN_GROUP = {
|
|
|
15
15
|
ternoa: ['ternoa'],
|
|
16
16
|
liquidStaking: ['bifrost_dot', 'acala', 'parallel', 'moonbeam'],
|
|
17
17
|
lending: ['interlay'],
|
|
18
|
-
krest_network: ['krest_network']
|
|
18
|
+
krest_network: ['krest_network'],
|
|
19
|
+
manta: ['manta_network']
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
22
|
-
export const ST_LIQUID_TOKEN_ABI = require("./abis/st_liquid_token_abi.json");
|
|
23
|
+
export const ST_LIQUID_TOKEN_ABI = require("./abis/st_liquid_token_abi.json");
|
|
24
|
+
export const MANTA_VALIDATOR_POINTS_PER_BLOCK = 20;
|
|
25
|
+
export const MANTA_MIN_DELEGATION = 500;
|
|
@@ -5,11 +5,27 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
|
|
|
5
5
|
import { BasicTxErrorType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { getBondedValidators, getEarningStatusByNominations, getParaCurrentInflation, isUnstakeAll } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
7
7
|
import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
|
+
import { _STAKING_CHAIN_GROUP, MANTA_MIN_DELEGATION, MANTA_VALIDATOR_POINTS_PER_BLOCK } from '@subwallet/extension-base/services/earning-service/constants';
|
|
8
9
|
import { parseIdentity } from '@subwallet/extension-base/services/earning-service/utils';
|
|
9
10
|
import { EarningStatus, UnstakingStatus } from '@subwallet/extension-base/types';
|
|
10
11
|
import { balanceFormatter, formatNumber, parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
12
|
+
import BigN from 'bignumber.js';
|
|
11
13
|
import { BN, BN_ZERO } from '@polkadot/util';
|
|
12
14
|
import BaseParaNativeStakingPoolHandler from "./base-para.js";
|
|
15
|
+
function calculateMantaNominatorReturn(decimal, commission, totalActiveCollators, bnAnnualInflation, blocksPreviousRound, bnCollatorExpectedBlocksPerRound, bnCollatorTotalStaked, isCountCommission) {
|
|
16
|
+
const MIN_DELEGATION = new BigN(MANTA_MIN_DELEGATION);
|
|
17
|
+
const factor = new BigN(10).pow(decimal);
|
|
18
|
+
const annualInflation = bnAnnualInflation.dividedBy(factor);
|
|
19
|
+
const collatorTotalStaked = bnCollatorTotalStaked.dividedBy(factor);
|
|
20
|
+
const annualRewardsPerCollator = annualInflation.dividedBy(totalActiveCollators);
|
|
21
|
+
const adjustmentFactor = new BigN(blocksPreviousRound).dividedBy(bnCollatorExpectedBlocksPerRound);
|
|
22
|
+
const marginalReward = annualRewardsPerCollator.multipliedBy(MIN_DELEGATION).dividedBy(collatorTotalStaked.plus(MIN_DELEGATION));
|
|
23
|
+
let bnApy = new BigN(100).multipliedBy(adjustmentFactor).multipliedBy(marginalReward).dividedBy(MIN_DELEGATION);
|
|
24
|
+
if (isCountCommission) {
|
|
25
|
+
bnApy = new BigN((1 - commission) * 100).multipliedBy(adjustmentFactor).multipliedBy(marginalReward).dividedBy(MIN_DELEGATION);
|
|
26
|
+
}
|
|
27
|
+
return bnApy.toNumber();
|
|
28
|
+
}
|
|
13
29
|
export default class ParaNativeStakingPoolHandler extends BaseParaNativeStakingPoolHandler {
|
|
14
30
|
/* Subscribe pool info */
|
|
15
31
|
|
|
@@ -251,52 +267,130 @@ export default class ParaNativeStakingPoolHandler extends BaseParaNativeStakingP
|
|
|
251
267
|
async getPoolTargets() {
|
|
252
268
|
const apiProps = await this.substrateApi.isReady;
|
|
253
269
|
const allCollators = [];
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
const
|
|
264
|
-
const
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
270
|
+
if (_STAKING_CHAIN_GROUP.manta.includes(this.chain)) {
|
|
271
|
+
var _this$chainInfo$subst;
|
|
272
|
+
const DECIMAL = (_this$chainInfo$subst = this.chainInfo.substrateInfo) === null || _this$chainInfo$subst === void 0 ? void 0 : _this$chainInfo$subst.decimals;
|
|
273
|
+
const POINTS_PER_BLOCK = MANTA_VALIDATOR_POINTS_PER_BLOCK; // producing 1 block will get 20 points for validator
|
|
274
|
+
|
|
275
|
+
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()]);
|
|
276
|
+
|
|
277
|
+
// noted: Annual Inflation = Total Issuance * Annual Inflation Percent
|
|
278
|
+
const round = _round.toPrimitive();
|
|
279
|
+
const totalIssuance = _totalIssuance.toString();
|
|
280
|
+
const inflationConfig = _inflationConfig.toHuman();
|
|
281
|
+
const annualInflationPercent = parseFloat(inflationConfig.annual.ideal.slice(0, -1)) / 100;
|
|
282
|
+
const bnAnnualInflation = new BigN(totalIssuance).multipliedBy(annualInflationPercent);
|
|
283
|
+
|
|
284
|
+
// noted: allCollatorsPool -> all candidate collators; selectedCollators -> candidate collators selected in current round
|
|
285
|
+
const allCollatorsPoolInfo = _allCollatorsPool.toPrimitive();
|
|
286
|
+
const allCollatorsPool = allCollatorsPoolInfo.map(collator => collator.owner.toString());
|
|
287
|
+
const selectedCollators = _selectedCollators.toPrimitive();
|
|
288
|
+
const totalActiveCollators = selectedCollators.length;
|
|
289
|
+
const bnCollatorExpectedBlocksPerRound = new BigN(round.length).dividedBy(allCollatorsPool.length);
|
|
290
|
+
const maxDelegationPerCollator = apiProps.api.consts.parachainStaking.maxTopDelegationsPerCandidate.toString();
|
|
291
|
+
const rawCollatorCommission = _collatorCommission.toHuman();
|
|
292
|
+
const collatorCommission = parseFloat(rawCollatorCommission.split('%')[0]);
|
|
293
|
+
const collatorCommissionPercent = collatorCommission / 100;
|
|
294
|
+
for (const collator of _allCollators) {
|
|
295
|
+
const _collatorAddress = collator[0].toHuman();
|
|
296
|
+
const collatorAddress = _collatorAddress[0];
|
|
297
|
+
if (allCollatorsPool.includes(collatorAddress)) {
|
|
298
|
+
const collatorInfo = collator[1].toPrimitive();
|
|
299
|
+
const bnTotalStake = new BN(collatorInfo.totalCounted);
|
|
300
|
+
const bnOwnStake = new BN(collatorInfo.bond);
|
|
301
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
302
|
+
const bnMinBond = new BN(collatorInfo.lowestTopDelegationAmount);
|
|
303
|
+
allCollators.push({
|
|
304
|
+
commission: 0,
|
|
305
|
+
address: collatorAddress,
|
|
306
|
+
totalStake: bnTotalStake.toString(),
|
|
307
|
+
ownStake: bnOwnStake.toString(),
|
|
308
|
+
otherStake: bnOtherStake.toString(),
|
|
309
|
+
nominatorCount: collatorInfo.delegationCount,
|
|
310
|
+
blocked: false,
|
|
311
|
+
isVerified: false,
|
|
312
|
+
minBond: bnMinBond.toString(),
|
|
313
|
+
chain: this.chain,
|
|
314
|
+
isCrowded: parseInt(maxDelegationPerCollator) > 0
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
await Promise.all(allCollators.map(async collator => {
|
|
319
|
+
if (allCollatorsPool.includes(collator.address)) {
|
|
320
|
+
// noted: number of blocks = total points / points per block
|
|
321
|
+
const _collatorPoints = await apiProps.api.query.parachainStaking.awardedPts(parseInt(round.current) - 1, collator.address);
|
|
322
|
+
const collatorPoints = _collatorPoints.toPrimitive();
|
|
323
|
+
const blocksPreviousRound = collatorPoints / POINTS_PER_BLOCK;
|
|
324
|
+
collator.expectedReturn = calculateMantaNominatorReturn(DECIMAL, collatorCommissionPercent, totalActiveCollators, bnAnnualInflation, blocksPreviousRound, bnCollatorExpectedBlocksPerRound, new BigN(collator.totalStake), false);
|
|
325
|
+
}
|
|
326
|
+
}));
|
|
327
|
+
const extraInfoMap = {};
|
|
328
|
+
await Promise.all(allCollators.map(async collator => {
|
|
329
|
+
const [_info, [identity, isReasonable]] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), parseIdentity(apiProps, collator.address)]);
|
|
330
|
+
const rawInfo = _info.toHuman();
|
|
331
|
+
const active = (rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.status) === 'Active';
|
|
332
|
+
extraInfoMap[collator.address] = {
|
|
333
|
+
identity,
|
|
334
|
+
isVerified: isReasonable,
|
|
335
|
+
active
|
|
336
|
+
};
|
|
337
|
+
}));
|
|
338
|
+
for (const validator of allCollators) {
|
|
339
|
+
validator.blocked = !extraInfoMap[validator.address].active;
|
|
340
|
+
validator.identity = extraInfoMap[validator.address].identity;
|
|
341
|
+
validator.isVerified = extraInfoMap[validator.address].isVerified;
|
|
342
|
+
// @ts-ignore
|
|
343
|
+
validator.commission = collatorCommission;
|
|
344
|
+
}
|
|
345
|
+
return allCollators;
|
|
346
|
+
} else {
|
|
347
|
+
const [_allCollators, _collatorCommission] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo.entries(), apiProps.api.query.parachainStaking.collatorCommission()]);
|
|
348
|
+
const maxDelegationPerCollator = apiProps.api.consts.parachainStaking.maxTopDelegationsPerCandidate.toString();
|
|
349
|
+
const rawCollatorCommission = _collatorCommission.toHuman();
|
|
350
|
+
const collatorCommission = parseFloat(rawCollatorCommission.split('%')[0]);
|
|
351
|
+
for (const collator of _allCollators) {
|
|
352
|
+
const _collatorAddress = collator[0].toHuman();
|
|
353
|
+
const collatorAddress = _collatorAddress[0];
|
|
354
|
+
const collatorInfo = collator[1].toPrimitive();
|
|
355
|
+
const bnTotalStake = new BN(collatorInfo.totalCounted);
|
|
356
|
+
const bnOwnStake = new BN(collatorInfo.bond);
|
|
357
|
+
const bnOtherStake = bnTotalStake.sub(bnOwnStake);
|
|
358
|
+
const bnMinBond = new BN(collatorInfo.lowestTopDelegationAmount);
|
|
359
|
+
allCollators.push({
|
|
360
|
+
commission: 0,
|
|
361
|
+
expectedReturn: 0,
|
|
362
|
+
address: collatorAddress,
|
|
363
|
+
totalStake: bnTotalStake.toString(),
|
|
364
|
+
ownStake: bnOwnStake.toString(),
|
|
365
|
+
otherStake: bnOtherStake.toString(),
|
|
366
|
+
nominatorCount: collatorInfo.delegationCount,
|
|
367
|
+
blocked: false,
|
|
368
|
+
isVerified: false,
|
|
369
|
+
minBond: bnMinBond.toString(),
|
|
370
|
+
chain: this.chain,
|
|
371
|
+
isCrowded: parseInt(maxDelegationPerCollator) > 0
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
const extraInfoMap = {};
|
|
375
|
+
await Promise.all(allCollators.map(async collator => {
|
|
376
|
+
const [_info, [identity, isReasonable]] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), parseIdentity(apiProps, collator.address)]);
|
|
377
|
+
const rawInfo = _info.toHuman();
|
|
378
|
+
const active = (rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.status) === 'Active';
|
|
379
|
+
extraInfoMap[collator.address] = {
|
|
380
|
+
identity,
|
|
381
|
+
isVerified: isReasonable,
|
|
382
|
+
active
|
|
383
|
+
};
|
|
384
|
+
}));
|
|
385
|
+
for (const validator of allCollators) {
|
|
386
|
+
validator.blocked = !extraInfoMap[validator.address].active;
|
|
387
|
+
validator.identity = extraInfoMap[validator.address].identity;
|
|
388
|
+
validator.isVerified = extraInfoMap[validator.address].isVerified;
|
|
389
|
+
// @ts-ignore
|
|
390
|
+
validator.commission = collatorCommission;
|
|
391
|
+
}
|
|
392
|
+
return allCollators;
|
|
298
393
|
}
|
|
299
|
-
return allCollators;
|
|
300
394
|
}
|
|
301
395
|
|
|
302
396
|
/* Get pool targets */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
export default class MigrateAssetSetting extends BaseMigrationJob {
|
|
6
|
+
async run() {
|
|
7
|
+
try {
|
|
8
|
+
const oldSlugs = ['ethereum-ERC20-WFTM-0x4E15361FD6b4BB609Fa63C81A2be19d873717870', 'moonbeam-ERC20-CSG-0x2Dfc76901bB2ac2A5fA5fc479590A490BBB10a5F', 'astar-LOCAL-aUSD', 'astarEvm-ERC20-aUSD-0xfFFFFfFF00000000000000010000000000000001',
|
|
9
|
+
//
|
|
10
|
+
'moonriver-LOCAL-xcaUSD',
|
|
11
|
+
//
|
|
12
|
+
'moonriver-LOCAL-xckBTC', 'bifrost-LOCAL-aUSD', 'calamari-LOCAL-AUSD', 'shiden-LOCAL-aUSD', 'shidenEvm-ERC20-aUSD-0xfFFfFFfF00000000000000010000000000000000',
|
|
13
|
+
//
|
|
14
|
+
'ethereum_goerli-NATIVE-GoerliETH', 'binance_test-NATIVE-BNB',
|
|
15
|
+
//
|
|
16
|
+
'pangolin-LOCAL-CKTON',
|
|
17
|
+
//
|
|
18
|
+
'zeta_test-NATIVE-aZETA' //
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const newSlugs = ['ethereum-ERC20-FTM-0x4E15361FD6b4BB609Fa63C81A2be19d873717870', 'moonbeam-ERC20-CGS-0x2Dfc76901bB2ac2A5fA5fc479590A490BBB10a5F', 'astar-LOCAL-aSEED', 'astarEvm-ERC20-aSEED-0xfFFFFfFF00000000000000010000000000000001', 'moonriver-LOCAL-xcaSeed', 'moonriver-LOCAL-xcKBTC', 'bifrost-LOCAL-KUSD', 'calamari-LOCAL-AUSD', 'shiden-LOCAL-aSEED', 'shidenEvm-ERC20-aSEED-0xfFFfFFfF00000000000000010000000000000000', 'ethereum_goerli-NATIVE-ETH', 'binance_test-NATIVE-tBNB', 'pangolin-LOCAL-PKTON', 'zeta_test-NATIVE-ZETA'];
|
|
22
|
+
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
23
|
+
const migratedAssetSetting = {};
|
|
24
|
+
for (let i = 0; i < oldSlugs.length; i++) {
|
|
25
|
+
const slug = oldSlugs[i];
|
|
26
|
+
if (Object.keys(assetSetting).includes(slug)) {
|
|
27
|
+
const isVisible = assetSetting[slug].visible;
|
|
28
|
+
const newSlug = newSlugs[i];
|
|
29
|
+
migratedAssetSetting[newSlug] = {
|
|
30
|
+
visible: isVisible
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
this.state.chainService.setAssetSettings({
|
|
35
|
+
...assetSetting,
|
|
36
|
+
...migratedAssetSetting
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error(e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import DeleteEarningData from '@subwallet/extension-base/services/migration-service/scripts/DeleteEarningData';
|
|
5
|
+
// import MigrateAssetSetting from './databases/MigrateAssetSetting';
|
|
5
6
|
import MigrateEarningVersion from "./databases/MigrateEarningVersion.js";
|
|
6
7
|
import MigrateEthProvider from "./providers/MigrateEthProvider.js";
|
|
7
8
|
import MigratePioneerProvider from "./providers/MigratePioneerProvider.js";
|
|
@@ -44,5 +45,6 @@ export default {
|
|
|
44
45
|
'1.1.26-01': MigratePolygonUSDCProvider,
|
|
45
46
|
'1.1.28-01': MigrateEarningVersion,
|
|
46
47
|
'1.1.41-01': DeleteChainStaking
|
|
48
|
+
// '1.1.41-02': MigrateAssetSetting
|
|
47
49
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
48
50
|
};
|