@subwallet/extension-base 1.2.3-1 → 1.2.5-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 +0 -153
- package/background/KoniTypes.js +0 -21
- package/cjs/background/KoniTypes.js +1 -22
- package/cjs/core/logic-validation/earning.js +2 -2
- package/cjs/core/logic-validation/transfer.js +0 -7
- package/cjs/core/substrate/nominationpools-pallet.js +11 -1
- package/cjs/core/substrate/system-pallet.js +2 -3
- package/cjs/core/substrate/xcm-parser.js +190 -0
- package/cjs/koni/api/dotsama/transfer.js +10 -119
- package/cjs/koni/api/staking/bonding/utils.js +38 -6
- package/cjs/koni/api/xcm/polkadotXcm.js +12 -20
- package/cjs/koni/api/xcm/utils.js +8 -126
- package/cjs/koni/api/xcm/xTokens.js +10 -8
- package/cjs/koni/api/xcm/xcmPallet.js +6 -6
- package/cjs/koni/background/handlers/Extension.js +90 -113
- package/cjs/koni/background/handlers/Tabs.js +3 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/index.js +4 -2
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +6 -3
- package/cjs/services/chain-service/constants.js +2 -2
- package/cjs/services/chain-service/utils/index.js +7 -2
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +104 -113
- package/cjs/services/earning-service/handlers/special.js +3 -3
- package/cjs/services/earning-service/service.js +1 -1
- package/cjs/services/earning-service/utils/index.js +6 -1
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
- package/cjs/services/migration-service/scripts/index.js +2 -2
- package/cjs/services/request-service/constants.js +5 -3
- package/cjs/services/request-service/handler/AuthRequestHandler.js +32 -12
- package/cjs/services/swap-service/handler/base-handler.js +5 -3
- package/cjs/services/swap-service/handler/hydradx-handler.js +1 -1
- package/core/logic-validation/earning.d.ts +1 -1
- package/core/logic-validation/earning.js +2 -2
- package/core/logic-validation/transfer.js +0 -7
- package/core/substrate/nominationpools-pallet.d.ts +4 -1
- package/core/substrate/nominationpools-pallet.js +8 -1
- package/core/substrate/system-pallet.js +2 -3
- package/core/substrate/xcm-parser.d.ts +49 -0
- package/core/substrate/xcm-parser.js +181 -0
- package/koni/api/dotsama/transfer.d.ts +0 -3
- package/koni/api/dotsama/transfer.js +12 -119
- package/koni/api/staking/bonding/utils.d.ts +6 -2
- package/koni/api/staking/bonding/utils.js +33 -4
- package/koni/api/xcm/polkadotXcm.js +14 -22
- package/koni/api/xcm/utils.d.ts +3 -48
- package/koni/api/xcm/utils.js +5 -114
- package/koni/api/xcm/xTokens.js +12 -10
- package/koni/api/xcm/xcmPallet.js +7 -7
- package/koni/background/handlers/Extension.d.ts +1 -3
- package/koni/background/handlers/Extension.js +8 -28
- package/koni/background/handlers/Tabs.js +3 -2
- package/package.json +11 -6
- package/packageInfo.js +1 -1
- package/page/index.d.ts +2 -2
- package/page/index.js +4 -2
- package/services/balance-service/helpers/subscribe/substrate/index.js +8 -5
- package/services/chain-service/constants.js +2 -2
- package/services/chain-service/utils/index.d.ts +3 -2
- package/services/chain-service/utils/index.js +5 -2
- package/services/earning-service/handlers/native-staking/relay-chain.d.ts +5 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +106 -115
- package/services/earning-service/handlers/special.js +3 -3
- package/services/earning-service/service.js +1 -1
- package/services/earning-service/utils/index.d.ts +2 -0
- package/services/earning-service/utils/index.js +6 -2
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
- package/services/migration-service/scripts/index.js +2 -2
- package/services/request-service/constants.d.ts +1 -0
- package/services/request-service/constants.js +4 -2
- package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
- package/services/request-service/handler/AuthRequestHandler.js +22 -3
- package/services/swap-service/handler/base-handler.js +5 -3
- package/services/swap-service/handler/hydradx-handler.js +1 -1
|
@@ -45,7 +45,7 @@ const _BALANCE_CHAIN_GROUP = {
|
|
|
45
45
|
kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
|
|
46
46
|
// perhaps there are some runtime updates
|
|
47
47
|
centrifuge: ['centrifuge'],
|
|
48
|
-
supportBridged: ['rococo_assethub']
|
|
48
|
+
supportBridged: ['rococo_assethub', 'statemint', 'statemine']
|
|
49
49
|
};
|
|
50
50
|
exports._BALANCE_CHAIN_GROUP = _BALANCE_CHAIN_GROUP;
|
|
51
51
|
const _BALANCE_TOKEN_GROUP = {
|
|
@@ -271,7 +271,7 @@ const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
|
|
|
271
271
|
// XCM------------------------------------------------------------------------------------------------------------------
|
|
272
272
|
exports._DEFAULT_MANTA_ZK_CHAIN = _DEFAULT_MANTA_ZK_CHAIN;
|
|
273
273
|
const _XCM_CHAIN_GROUP = {
|
|
274
|
-
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain'],
|
|
274
|
+
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub'],
|
|
275
275
|
xcmPallet: ['polkadot', 'kusama']
|
|
276
276
|
// default is xTokens pallet
|
|
277
277
|
};
|
|
@@ -54,6 +54,7 @@ var _exportNames = {
|
|
|
54
54
|
_getXcmAssetId: true,
|
|
55
55
|
_getXcmAssetMultilocation: true,
|
|
56
56
|
_getXcmTransferType: true,
|
|
57
|
+
_isRelayChain: true,
|
|
57
58
|
_isSubstrateRelayChain: true,
|
|
58
59
|
_isSubstrateParaChain: true,
|
|
59
60
|
_getEvmAbiExplorer: true,
|
|
@@ -145,6 +146,7 @@ exports._isNativeTokenBySlug = _isNativeTokenBySlug;
|
|
|
145
146
|
exports._isNativeTokenTransferredByEvm = _isNativeTokenTransferredByEvm;
|
|
146
147
|
exports._isPureEvmChain = _isPureEvmChain;
|
|
147
148
|
exports._isPureSubstrateChain = _isPureSubstrateChain;
|
|
149
|
+
exports._isRelayChain = _isRelayChain;
|
|
148
150
|
exports._isSmartContractToken = _isSmartContractToken;
|
|
149
151
|
exports._isSubstrateChain = _isSubstrateChain;
|
|
150
152
|
exports._isSubstrateParaChain = _isSubstrateParaChain;
|
|
@@ -305,7 +307,7 @@ function _isSubstrateChain(chainInfo) {
|
|
|
305
307
|
|
|
306
308
|
function _getEvmChainId(chainInfo) {
|
|
307
309
|
var _chainInfo$evmInfo;
|
|
308
|
-
return (
|
|
310
|
+
return (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId; // fallback to Ethereum
|
|
309
311
|
}
|
|
310
312
|
|
|
311
313
|
function _getSubstrateParaId(chainInfo) {
|
|
@@ -314,7 +316,7 @@ function _getSubstrateParaId(chainInfo) {
|
|
|
314
316
|
}
|
|
315
317
|
function _getSubstrateRelayParent(chainInfo) {
|
|
316
318
|
var _chainInfo$substrateI2;
|
|
317
|
-
return (
|
|
319
|
+
return (_chainInfo$substrateI2 = chainInfo.substrateInfo) === null || _chainInfo$substrateI2 === void 0 ? void 0 : _chainInfo$substrateI2.relaySlug;
|
|
318
320
|
}
|
|
319
321
|
function _getSubstrateGenesisHash(chainInfo) {
|
|
320
322
|
var _chainInfo$substrateI3;
|
|
@@ -467,6 +469,9 @@ function _getXcmTransferType(originChainInfo, destinationChainInfo) {
|
|
|
467
469
|
var _originChainInfo$subs, _destinationChainInfo;
|
|
468
470
|
return `${((_originChainInfo$subs = originChainInfo.substrateInfo) === null || _originChainInfo$subs === void 0 ? void 0 : _originChainInfo$subs.chainType) || ''}-${((_destinationChainInfo = destinationChainInfo.substrateInfo) === null || _destinationChainInfo === void 0 ? void 0 : _destinationChainInfo.chainType) || ''}`;
|
|
469
471
|
}
|
|
472
|
+
function _isRelayChain(chainInfo) {
|
|
473
|
+
return _isSubstrateRelayChain(chainInfo) || _isPureEvmChain(chainInfo);
|
|
474
|
+
}
|
|
470
475
|
function _isSubstrateRelayChain(chainInfo) {
|
|
471
476
|
var _chainInfo$substrateI14;
|
|
472
477
|
return ((_chainInfo$substrateI14 = chainInfo.substrateInfo) === null || _chainInfo$substrateI14 === void 0 ? void 0 : _chainInfo$substrateI14.chainType) === _types._SubstrateChainType.RELAYCHAIN;
|
|
@@ -51,17 +51,14 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
51
51
|
await defaultCallback();
|
|
52
52
|
await substrateApi.isReady;
|
|
53
53
|
const unsub = await ((_substrateApi$api$que = substrateApi.api.query.staking) === null || _substrateApi$api$que === void 0 ? void 0 : _substrateApi$api$que.currentEra(async _currentEra => {
|
|
54
|
-
var _substrateApi$api$con, _substrateApi$api$
|
|
54
|
+
var _substrateApi$api$con, _substrateApi$api$que2, _substrateApi$api$que3, _substrateApi$api$que4, _substrateApi$api$que5, _substrateApi$api$que6;
|
|
55
55
|
if (cancel) {
|
|
56
56
|
unsub();
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
|
-
let maxNominations = ((_substrateApi$api$con = substrateApi.api.consts.staking) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.maxNominations) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) || '16';
|
|
60
59
|
const unlimitedNominatorRewarded = substrateApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
61
|
-
const maxNominatorRewarded = (_substrateApi$api$
|
|
62
|
-
const
|
|
63
|
-
const maxNominationsByNominationQuota = _maxNominationsByNominationQuota === null || _maxNominationsByNominationQuota === void 0 ? void 0 : _maxNominationsByNominationQuota.toString();
|
|
64
|
-
maxNominations = maxNominationsByNominationQuota !== null && maxNominationsByNominationQuota !== void 0 ? maxNominationsByNominationQuota : maxNominations;
|
|
60
|
+
const maxNominatorRewarded = (_substrateApi$api$con = substrateApi.api.consts.staking.maxNominatorRewardedPerValidator) === null || _substrateApi$api$con === void 0 ? void 0 : _substrateApi$api$con.toString();
|
|
61
|
+
const maxNominations = await (0, _utils.getRelayMaxNominations)(substrateApi);
|
|
65
62
|
const currentEra = _currentEra.toString();
|
|
66
63
|
const maxUnlockingChunks = substrateApi.api.consts.staking.maxUnlockingChunks.toString();
|
|
67
64
|
const unlockingEras = substrateApi.api.consts.staking.bondingDuration.toString();
|
|
@@ -140,54 +137,15 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
140
137
|
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()]);
|
|
141
138
|
const unlimitedNominatorRewarded = substrateApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
142
139
|
const _maxNominatorRewardedPerValidator = (substrateApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
143
|
-
const maxNominatorRewardedPerValidator = parseInt(_maxNominatorRewardedPerValidator);
|
|
140
|
+
const maxNominatorRewardedPerValidator = unlimitedNominatorRewarded ? undefined : parseInt(_maxNominatorRewardedPerValidator);
|
|
144
141
|
const nominations = _nominations.toPrimitive();
|
|
145
142
|
const bonded = _bonded.toHuman();
|
|
143
|
+
const addressFormatted = (0, _utils4.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo));
|
|
146
144
|
const activeStake = ledger.active.toString();
|
|
147
145
|
const totalStake = ledger.total.toString();
|
|
148
146
|
const unstakingBalance = (ledger.total - ledger.active).toString();
|
|
149
|
-
const nominationList = [];
|
|
150
147
|
const unstakingList = [];
|
|
151
|
-
|
|
152
|
-
const validatorList = nominations.targets;
|
|
153
|
-
await Promise.all(validatorList.map(async validatorAddress => {
|
|
154
|
-
let nominationStatus = _types.EarningStatus.NOT_EARNING;
|
|
155
|
-
let eraStakerOtherList = [];
|
|
156
|
-
let identity;
|
|
157
|
-
if (_constants2._UPDATED_RUNTIME_STAKING_GROUP.includes(this.chain)) {
|
|
158
|
-
// todo: review all relaychains later
|
|
159
|
-
const [[_identity], _eraStaker] = await Promise.all([(0, _utils3.parseIdentity)(substrateApi, validatorAddress), substrateApi.api.query.staking.erasStakersPaged.entries(currentEra, validatorAddress)]);
|
|
160
|
-
identity = _identity;
|
|
161
|
-
eraStakerOtherList = _eraStaker.flatMap(paged => paged[1].toPrimitive().others);
|
|
162
|
-
} else {
|
|
163
|
-
const [[_identity], _eraStaker] = await Promise.all([(0, _utils3.parseIdentity)(substrateApi, validatorAddress), substrateApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
164
|
-
identity = _identity;
|
|
165
|
-
const eraStaker = _eraStaker.toPrimitive();
|
|
166
|
-
eraStakerOtherList = eraStaker.others;
|
|
167
|
-
}
|
|
168
|
-
const sortedNominators = eraStakerOtherList.sort((a, b) => {
|
|
169
|
-
return new _bignumber.default(b.value).minus(a.value).toNumber();
|
|
170
|
-
});
|
|
171
|
-
const topNominators = sortedNominators.map(nominator => {
|
|
172
|
-
return nominator.who;
|
|
173
|
-
});
|
|
174
|
-
if (!topNominators.includes((0, _utils4.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
175
|
-
// if nominator has target but not in nominator list
|
|
176
|
-
nominationStatus = _types.EarningStatus.WAITING;
|
|
177
|
-
} else if (topNominators.slice(0, unlimitedNominatorRewarded ? undefined : maxNominatorRewardedPerValidator).includes((0, _utils4.reformatAddress)(address, (0, _utils2._getChainSubstrateAddressPrefix)(chainInfo)))) {
|
|
178
|
-
// if address in top nominators
|
|
179
|
-
nominationStatus = _types.EarningStatus.EARNING_REWARD;
|
|
180
|
-
}
|
|
181
|
-
nominationList.push({
|
|
182
|
-
chain,
|
|
183
|
-
validatorAddress,
|
|
184
|
-
status: nominationStatus,
|
|
185
|
-
validatorIdentity: identity,
|
|
186
|
-
activeStake: '0' // relaychain allocates stake accordingly
|
|
187
|
-
});
|
|
188
|
-
}));
|
|
189
|
-
}
|
|
190
|
-
|
|
148
|
+
const nominationList = (await this.handleNominationsList(substrateApi, chain, nominations, currentEra, addressFormatted, maxNominatorRewardedPerValidator)) || [];
|
|
191
149
|
let stakingStatus = _types.EarningStatus.NOT_EARNING;
|
|
192
150
|
const bnActiveStake = new _util.BN(activeStake);
|
|
193
151
|
let waitingNominationCount = 0;
|
|
@@ -231,6 +189,51 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
231
189
|
unstakings: unstakingList
|
|
232
190
|
};
|
|
233
191
|
}
|
|
192
|
+
async handleNominationsList(substrateApi, chain, nominations, currentEra, address, maxNominatorRewardedPerValidator) {
|
|
193
|
+
const nominationList = [];
|
|
194
|
+
if (!nominations) {
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
const validatorList = nominations.targets;
|
|
198
|
+
await Promise.all(validatorList.map(async validatorAddress => {
|
|
199
|
+
let nominationStatus = _types.EarningStatus.NOT_EARNING;
|
|
200
|
+
let eraStakerOtherList = [];
|
|
201
|
+
let identity;
|
|
202
|
+
if (_constants2._UPDATED_RUNTIME_STAKING_GROUP.includes(this.chain)) {
|
|
203
|
+
// todo: review all relaychains later
|
|
204
|
+
const [[_identity], _eraStaker] = await Promise.all([(0, _utils3.parseIdentity)(substrateApi, validatorAddress), substrateApi.api.query.staking.erasStakersPaged.entries(currentEra, validatorAddress)]);
|
|
205
|
+
identity = _identity;
|
|
206
|
+
eraStakerOtherList = _eraStaker.flatMap(paged => paged[1].toPrimitive().others);
|
|
207
|
+
} else {
|
|
208
|
+
const [[_identity], _eraStaker] = await Promise.all([(0, _utils3.parseIdentity)(substrateApi, validatorAddress), substrateApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
209
|
+
identity = _identity;
|
|
210
|
+
const eraStaker = _eraStaker.toPrimitive();
|
|
211
|
+
eraStakerOtherList = eraStaker.others;
|
|
212
|
+
}
|
|
213
|
+
const sortedNominators = eraStakerOtherList.sort((a, b) => {
|
|
214
|
+
return new _bignumber.default(b.value).minus(a.value).toNumber();
|
|
215
|
+
});
|
|
216
|
+
const topNominators = sortedNominators.map(nominator => {
|
|
217
|
+
return nominator.who;
|
|
218
|
+
});
|
|
219
|
+
if (!topNominators.includes(address)) {
|
|
220
|
+
// if nominator has target but not in nominator list
|
|
221
|
+
nominationStatus = _types.EarningStatus.WAITING;
|
|
222
|
+
} else if (topNominators.slice(0, maxNominatorRewardedPerValidator).includes(address)) {
|
|
223
|
+
// if address in top nominators
|
|
224
|
+
nominationStatus = _types.EarningStatus.EARNING_REWARD;
|
|
225
|
+
}
|
|
226
|
+
nominationList.push({
|
|
227
|
+
chain,
|
|
228
|
+
validatorAddress,
|
|
229
|
+
status: nominationStatus,
|
|
230
|
+
validatorIdentity: identity,
|
|
231
|
+
activeStake: '0' // relaychain allocates stake accordingly
|
|
232
|
+
});
|
|
233
|
+
}));
|
|
234
|
+
|
|
235
|
+
return nominationList;
|
|
236
|
+
}
|
|
234
237
|
async subscribePoolPosition(useAddresses, resultCallback) {
|
|
235
238
|
var _substrateApi$api$que13;
|
|
236
239
|
let cancel = false;
|
|
@@ -292,7 +295,6 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
292
295
|
|
|
293
296
|
async getPoolTargets() {
|
|
294
297
|
var _chainApi$api$query$s;
|
|
295
|
-
const decimals = this.nativeToken.decimals || 0;
|
|
296
298
|
const chainApi = await this.substrateApi.isReady;
|
|
297
299
|
const poolInfo = await this.getPoolInfo();
|
|
298
300
|
if (!poolInfo || !poolInfo.statistic) {
|
|
@@ -302,11 +304,9 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
302
304
|
const currentEra = _era.toString();
|
|
303
305
|
const activeEraInfo = _activeEraInfo.toPrimitive();
|
|
304
306
|
const activeEra = activeEraInfo.index;
|
|
305
|
-
const allValidators = [];
|
|
306
|
-
const validatorInfoList = [];
|
|
307
307
|
const maxEraRewardPointsEras = _constants2.MaxEraRewardPointsEras;
|
|
308
308
|
const endEraForPoints = parseInt(activeEra) - 1;
|
|
309
|
-
|
|
309
|
+
const startEraForPoints = Math.max(endEraForPoints - maxEraRewardPointsEras + 1, 0);
|
|
310
310
|
let _eraStakersPromise;
|
|
311
311
|
if (_constants2._UPDATED_RUNTIME_STAKING_GROUP.includes(this.chain)) {
|
|
312
312
|
// todo: review all relaychains later
|
|
@@ -315,43 +315,65 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
315
315
|
_eraStakersPromise = chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra));
|
|
316
316
|
}
|
|
317
317
|
const [_totalEraStake, _eraStakers, _minBond, _stakingRewards, _validators, ..._eraRewardPoints] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), _eraStakersPromise, chainApi.api.query.staking.minNominatorBond(), ((_chainApi$api$query$s = chainApi.api.query.stakingRewards) === null || _chainApi$api$query$s === void 0 ? void 0 : _chainApi$api$query$s.data) && chainApi.api.query.stakingRewards.data(), chainApi.api.query.staking.validators.entries(), chainApi.api.query.staking.erasRewardPoints.multi([...Array(maxEraRewardPointsEras).keys()].map(i => i + startEraForPoints))]);
|
|
318
|
-
const eraRewardMap =
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
startEraForPoints++;
|
|
322
|
-
}
|
|
323
|
-
const validatorPointsMap = (0, _utils.getValidatorPointsMap)(eraRewardMap);
|
|
324
|
-
const topValidatorList = (0, _utils.getTopValidatorByPoints)(validatorPointsMap);
|
|
325
|
-
|
|
326
|
-
// filter blocked validators
|
|
318
|
+
const eraRewardMap = (0, _utils.getRelayEraRewardMap)(_eraRewardPoints[0], startEraForPoints);
|
|
319
|
+
const validatorPointsMap = (0, _utils.getRelayValidatorPointsMap)(eraRewardMap);
|
|
320
|
+
const topValidatorList = (0, _utils.getRelayTopValidatorByPoints)(validatorPointsMap);
|
|
327
321
|
const validators = _validators;
|
|
328
|
-
const
|
|
329
|
-
for (const validator of validators) {
|
|
330
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
331
|
-
const validatorAddress = validator[0].toHuman()[0];
|
|
332
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
333
|
-
const validatorPrefs = validator[1].toHuman();
|
|
334
|
-
const isBlocked = validatorPrefs.blocked;
|
|
335
|
-
if (isBlocked) {
|
|
336
|
-
blockValidatorList.push(validatorAddress);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
const stakingRewards = _stakingRewards === null || _stakingRewards === void 0 ? void 0 : _stakingRewards.toPrimitive();
|
|
322
|
+
const blockedValidatorList = (0, _utils.getRelayBlockedValidatorList)(validators);
|
|
340
323
|
const unlimitedNominatorRewarded = chainApi.api.consts.staking.maxExposurePageSize !== undefined;
|
|
341
324
|
const maxNominatorRewarded = (chainApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
|
|
342
325
|
const bnTotalEraStake = new _util.BN(_totalEraStake.toString());
|
|
343
|
-
const
|
|
344
|
-
const
|
|
326
|
+
const minBond = _minBond.toPrimitive();
|
|
327
|
+
const [totalStakeMap, allValidatorAddresses, validatorInfoList] = this.parseEraStakerData(_eraStakers, blockedValidatorList, topValidatorList, validatorPointsMap, minBond, maxNominatorRewarded, unlimitedNominatorRewarded);
|
|
328
|
+
const extraInfoMap = {};
|
|
329
|
+
await Promise.all(allValidatorAddresses.map(async address => {
|
|
330
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
331
|
+
const [_commissionInfo, [identity, isVerified]] = await Promise.all([chainApi.api.query.staking.validators(address), (0, _utils3.parseIdentity)(chainApi, address)]);
|
|
332
|
+
const commissionInfo = _commissionInfo.toHuman();
|
|
333
|
+
extraInfoMap[address] = {
|
|
334
|
+
commission: commissionInfo.commission,
|
|
335
|
+
blocked: commissionInfo.blocked,
|
|
336
|
+
identity,
|
|
337
|
+
isVerified: isVerified
|
|
338
|
+
};
|
|
339
|
+
}));
|
|
340
|
+
const decimals = this.nativeToken.decimals || 0;
|
|
341
|
+
const bnAvgStake = (0, _utils3.applyDecimal)(bnTotalEraStake.divn(validatorInfoList.length), decimals);
|
|
342
|
+
for (const validator of validatorInfoList) {
|
|
343
|
+
const commissionString = extraInfoMap[validator.address].commission;
|
|
344
|
+
const commission = (0, _utils.getCommission)(commissionString);
|
|
345
|
+
validator.expectedReturn = this.getValidatorExpectedReturn(this.chain, validator, poolInfo.statistic.totalApy, commission, _stakingRewards, allValidatorAddresses, decimals, totalStakeMap, bnAvgStake);
|
|
346
|
+
validator.commission = commission;
|
|
347
|
+
validator.blocked = extraInfoMap[validator.address].blocked;
|
|
348
|
+
validator.identity = extraInfoMap[validator.address].identity;
|
|
349
|
+
validator.isVerified = extraInfoMap[validator.address].isVerified;
|
|
350
|
+
}
|
|
351
|
+
return validatorInfoList;
|
|
352
|
+
}
|
|
353
|
+
getValidatorExpectedReturn(chain, validator, totalApy, commission, _stakingRewards, allValidatorAddresses, decimals, totalStakeMap, bnAvgStake) {
|
|
354
|
+
if (_constants2._STAKING_CHAIN_GROUP.aleph.includes(chain)) {
|
|
355
|
+
return (0, _utils.calculateAlephZeroValidatorReturn)(totalApy, commission);
|
|
356
|
+
} else if (_constants2._STAKING_CHAIN_GROUP.ternoa.includes(chain)) {
|
|
357
|
+
const stakingRewards = _stakingRewards === null || _stakingRewards === void 0 ? void 0 : _stakingRewards.toPrimitive();
|
|
358
|
+
const rewardPerValidator = (0, _utils3.applyDecimal)(new _util.BN(stakingRewards.sessionExtraRewardPayout).divn(allValidatorAddresses.length), decimals);
|
|
359
|
+
const validatorStake = (0, _utils3.applyDecimal)(totalStakeMap[validator.address], decimals).toNumber();
|
|
360
|
+
return (0, _utils.calculateTernoaValidatorReturn)(rewardPerValidator.toNumber(), validatorStake, commission);
|
|
361
|
+
} else {
|
|
362
|
+
const bnValidatorStake = (0, _utils3.applyDecimal)(totalStakeMap[validator.address], decimals);
|
|
363
|
+
return (0, _utils.calculateValidatorStakedReturn)(totalApy, bnValidatorStake, bnAvgStake, commission);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
parseEraStakerData(_eraStakers, blockedValidatorList, topValidatorList, validatorPointsMap, minBond, maxNominatorRewarded, unlimitedNominatorRewarded) {
|
|
345
367
|
const totalStakeMap = {};
|
|
346
|
-
const
|
|
347
|
-
const
|
|
348
|
-
for (const item of
|
|
368
|
+
const allValidatorAddresses = [];
|
|
369
|
+
const validatorInfoList = [];
|
|
370
|
+
for (const item of _eraStakers) {
|
|
349
371
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
350
372
|
const rawValidatorInfo = item[0].toHuman();
|
|
351
373
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
352
374
|
const rawValidatorStat = item[1].toPrimitive();
|
|
353
375
|
const validatorAddress = rawValidatorInfo[1];
|
|
354
|
-
if (!
|
|
376
|
+
if (!blockedValidatorList.includes(validatorAddress)) {
|
|
355
377
|
var _validatorPointsMap$v;
|
|
356
378
|
let isTopQuartile = false;
|
|
357
379
|
if (topValidatorList.includes(validatorAddress)) {
|
|
@@ -372,7 +394,7 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
372
394
|
nominatorCount = others.length;
|
|
373
395
|
}
|
|
374
396
|
}
|
|
375
|
-
|
|
397
|
+
allValidatorAddresses.push(validatorAddress);
|
|
376
398
|
validatorInfoList.push({
|
|
377
399
|
address: validatorAddress,
|
|
378
400
|
totalStake: bnTotalStake.toString(),
|
|
@@ -384,46 +406,15 @@ class RelayNativeStakingPoolHandler extends _base.default {
|
|
|
384
406
|
expectedReturn: 0,
|
|
385
407
|
blocked: false,
|
|
386
408
|
isVerified: false,
|
|
387
|
-
minBond,
|
|
409
|
+
minBond: minBond.toString(),
|
|
388
410
|
isCrowded: unlimitedNominatorRewarded ? false : nominatorCount > parseInt(maxNominatorRewarded),
|
|
389
411
|
eraRewardPoint: ((_validatorPointsMap$v = validatorPointsMap[validatorAddress]) !== null && _validatorPointsMap$v !== void 0 ? _validatorPointsMap$v : _util.BN_ZERO).toString(),
|
|
390
412
|
topQuartile: isTopQuartile
|
|
391
413
|
});
|
|
392
414
|
}
|
|
393
415
|
}
|
|
394
|
-
|
|
395
|
-
await Promise.all(allValidators.map(async address => {
|
|
396
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
397
|
-
const [_commissionInfo, [identity, isVerified]] = await Promise.all([chainApi.api.query.staking.validators(address), (0, _utils3.parseIdentity)(chainApi, address)]);
|
|
398
|
-
const commissionInfo = _commissionInfo.toHuman();
|
|
399
|
-
extraInfoMap[address] = {
|
|
400
|
-
commission: commissionInfo.commission,
|
|
401
|
-
blocked: commissionInfo.blocked,
|
|
402
|
-
identity,
|
|
403
|
-
isVerified: isVerified
|
|
404
|
-
};
|
|
405
|
-
}));
|
|
406
|
-
const bnAvgStake = bnTotalEraStake.divn(validatorInfoList.length).div(bnDecimals);
|
|
407
|
-
for (const validator of validatorInfoList) {
|
|
408
|
-
const commission = extraInfoMap[validator.address].commission;
|
|
409
|
-
const bnValidatorStake = totalStakeMap[validator.address].div(bnDecimals);
|
|
410
|
-
if (_constants2._STAKING_CHAIN_GROUP.aleph.includes(this.chain)) {
|
|
411
|
-
validator.expectedReturn = (0, _utils.calculateAlephZeroValidatorReturn)(poolInfo.statistic.totalApy, (0, _utils.getCommission)(commission));
|
|
412
|
-
} else if (_constants2._STAKING_CHAIN_GROUP.ternoa.includes(this.chain)) {
|
|
413
|
-
const rewardPerValidator = new _util.BN(stakingRewards.sessionExtraRewardPayout).divn(allValidators.length).div(bnDecimals);
|
|
414
|
-
const validatorStake = totalStakeMap[validator.address].div(bnDecimals).toNumber();
|
|
415
|
-
validator.expectedReturn = (0, _utils.calculateTernoaValidatorReturn)(rewardPerValidator.toNumber(), validatorStake, (0, _utils.getCommission)(commission));
|
|
416
|
-
} else {
|
|
417
|
-
validator.expectedReturn = (0, _utils.calculateValidatorStakedReturn)(poolInfo.statistic.totalApy, bnValidatorStake, bnAvgStake, (0, _utils.getCommission)(commission));
|
|
418
|
-
}
|
|
419
|
-
validator.commission = parseFloat(commission.split('%')[0]);
|
|
420
|
-
validator.blocked = extraInfoMap[validator.address].blocked;
|
|
421
|
-
validator.identity = extraInfoMap[validator.address].identity;
|
|
422
|
-
validator.isVerified = extraInfoMap[validator.address].isVerified;
|
|
423
|
-
}
|
|
424
|
-
return validatorInfoList;
|
|
416
|
+
return [totalStakeMap, allValidatorAddresses, validatorInfoList];
|
|
425
417
|
}
|
|
426
|
-
|
|
427
418
|
/* Get pool targets */
|
|
428
419
|
|
|
429
420
|
/* Join pool action */
|
|
@@ -284,11 +284,11 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
284
284
|
const xcmFee = new _util.BN(path.totalFee[1].amount || '0');
|
|
285
285
|
const xcmAmount = missingAmount.add(xcmFee);
|
|
286
286
|
const bnAltInputTokenBalance = new _util.BN(altInputTokenBalance.value || '0');
|
|
287
|
-
if (!bnAltInputTokenBalance.sub(xcmAmount).gt(_util.BN_ZERO)) {
|
|
287
|
+
if (!bnAltInputTokenBalance.sub(xcmAmount).sub(xcmFee).gt(_util.BN_ZERO)) {
|
|
288
288
|
processValidation.failedStep = path.steps[1];
|
|
289
289
|
processValidation.ok = false;
|
|
290
290
|
processValidation.status = _types.YieldValidationStatus.NOT_ENOUGH_BALANCE;
|
|
291
|
-
const maxBn = bnInputTokenBalance.add(new _util.BN(altInputTokenBalance.value)).sub(xcmFee);
|
|
291
|
+
const maxBn = bnInputTokenBalance.add(new _util.BN(altInputTokenBalance.value)).sub(xcmFee).sub(xcmFee);
|
|
292
292
|
const maxValue = (0, _utils3.formatNumber)(maxBn.toString(), inputTokenInfo.decimals || 0);
|
|
293
293
|
const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
|
|
294
294
|
const symbol = altInputTokenInfo.symbol;
|
|
@@ -296,7 +296,7 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
296
296
|
const inputNetworkName = this.chainInfo.name;
|
|
297
297
|
const altNetworkName = altNetwork.name;
|
|
298
298
|
const currentValue = (0, _utils3.formatNumber)(bnInputTokenBalance.toString(), inputTokenInfo.decimals || 0);
|
|
299
|
-
const bnMaxXCM = new _util.BN(altInputTokenBalance.value).sub(xcmFee);
|
|
299
|
+
const bnMaxXCM = new _util.BN(altInputTokenBalance.value).sub(xcmFee).sub(xcmFee);
|
|
300
300
|
const maxXCMValue = (0, _utils3.formatNumber)(bnMaxXCM.toString(), inputTokenInfo.decimals || 0);
|
|
301
301
|
processValidation.message = (0, _i18next.t)('You can only enter a maximum of {{maxValue}} {{symbol}}, which is {{currentValue}} {{symbol}} ({{inputNetworkName}}) and {{maxXCMValue}} {{symbol}} ({{altNetworkName}}). Lower your amount and try again.', {
|
|
302
302
|
replace: {
|
|
@@ -40,7 +40,7 @@ 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 =
|
|
43
|
+
useOnlineCacheOnly = true;
|
|
44
44
|
constructor(state) {
|
|
45
45
|
this.state = state;
|
|
46
46
|
this.dbService = state.dbService;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.applyDecimal = applyDecimal;
|
|
6
7
|
exports.calculateReward = calculateReward;
|
|
7
8
|
exports.isActionFromValidator = isActionFromValidator;
|
|
8
9
|
exports.isNominationPool = exports.isNativeStakingPool = exports.isLiquidPool = exports.isLendingPool = void 0;
|
|
@@ -133,4 +134,8 @@ exports.isLiquidPool = isLiquidPool;
|
|
|
133
134
|
const isLendingPool = pool => {
|
|
134
135
|
return pool.type === _types.YieldPoolType.LENDING;
|
|
135
136
|
};
|
|
136
|
-
exports.isLendingPool = isLendingPool;
|
|
137
|
+
exports.isLendingPool = isLendingPool;
|
|
138
|
+
function applyDecimal(bnNumber, decimals) {
|
|
139
|
+
const bnDecimals = new _util.BN((10 ** decimals).toString());
|
|
140
|
+
return bnNumber.div(bnDecimals);
|
|
141
|
+
}
|
|
@@ -14,7 +14,8 @@ class MigrateTransactionHistoryBySymbol extends _Base.default {
|
|
|
14
14
|
const state = this.state;
|
|
15
15
|
try {
|
|
16
16
|
const changeSlugsMap = {
|
|
17
|
-
'
|
|
17
|
+
'bobMainnet-LOCAL-wBTC-0x03C7054BCB39f7b2e5B2c7AcB37583e32D70Cfa3': 'bobMainnet-LOCAL-WBTC-0x03C7054BCB39f7b2e5B2c7AcB37583e32D70Cfa3',
|
|
18
|
+
'hydradx_main-LOCAL-LRNA': 'hydradx_main-LOCAL-H2O'
|
|
18
19
|
};
|
|
19
20
|
const allTxs = [];
|
|
20
21
|
await Promise.all(Object.entries(changeSlugsMap).map(async (_ref, i) => {
|
|
@@ -13,7 +13,8 @@ class MigrateAssetSetting extends _Base.default {
|
|
|
13
13
|
async run() {
|
|
14
14
|
try {
|
|
15
15
|
const changeSlugsMap = {
|
|
16
|
-
'
|
|
16
|
+
'bobMainnet-LOCAL-wBTC-0x03C7054BCB39f7b2e5B2c7AcB37583e32D70Cfa3': 'bobMainnet-LOCAL-WBTC-0x03C7054BCB39f7b2e5B2c7AcB37583e32D70Cfa3',
|
|
17
|
+
'hydradx_main-LOCAL-LRNA': 'hydradx_main-LOCAL-H2O'
|
|
17
18
|
};
|
|
18
19
|
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
19
20
|
const migratedAssetSetting = {};
|
|
@@ -57,8 +57,8 @@ var _default = {
|
|
|
57
57
|
'1.1.28-01': _MigrateEarningVersion.default,
|
|
58
58
|
'1.1.41-01': _DeleteChainStaking.default,
|
|
59
59
|
'1.1.46-01': _AutoEnableSomeTokens.default,
|
|
60
|
-
'1.1.
|
|
61
|
-
'1.1.
|
|
60
|
+
'1.1.69-03': _MigrateAssetSetting.default,
|
|
61
|
+
'1.1.69-02': _MigrateTransactionHistoryBySymbol.default,
|
|
62
62
|
'1.2.69-01': _MigrateRemoveGenesisHash.default
|
|
63
63
|
// [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
|
|
64
64
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.WEB_APP_URL = exports.PREDEFINED_CHAIN_DAPP_CHAIN_MAP = exports.EXTENSION_REQUEST_URL = void 0;
|
|
6
|
+
exports.WEB_APP_URL = exports.PREDEFINED_CHAIN_DAPP_CHAIN_MAP = exports.EXTENSION_REQUEST_URL = exports.DAPP_CONNECT_ALL_TYPE_ACCOUNT_URL = void 0;
|
|
7
7
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
9
|
|
|
@@ -21,6 +21,8 @@ const WEB_APP_URL = [
|
|
|
21
21
|
// Local
|
|
22
22
|
'subwallet-webapp.pages.dev',
|
|
23
23
|
// Pull request build
|
|
24
|
-
'web.subwallet.app' // Production
|
|
24
|
+
'web.subwallet.app' // Production,
|
|
25
25
|
];
|
|
26
|
-
exports.WEB_APP_URL = WEB_APP_URL;
|
|
26
|
+
exports.WEB_APP_URL = WEB_APP_URL;
|
|
27
|
+
const DAPP_CONNECT_ALL_TYPE_ACCOUNT_URL = ['https://polkadot.js.org/apps/', 'https://ipfs.io/ipns/dotapps.io'];
|
|
28
|
+
exports.DAPP_CONNECT_ALL_TYPE_ACCOUNT_URL = DAPP_CONNECT_ALL_TYPE_ACCOUNT_URL;
|
|
@@ -29,6 +29,25 @@ class AuthRequestHandler {
|
|
|
29
29
|
this.keyringService = keyringService;
|
|
30
30
|
this.#requestService = requestService;
|
|
31
31
|
this.#chainService = chainService;
|
|
32
|
+
this.init().catch(console.error);
|
|
33
|
+
}
|
|
34
|
+
async init() {
|
|
35
|
+
const authList = await this.getAuthList();
|
|
36
|
+
let needUpdateAuthList = false;
|
|
37
|
+
Object.entries(authList).forEach(_ref => {
|
|
38
|
+
let [key, value] = _ref;
|
|
39
|
+
const existKeyAllBothConnect = _constants.DAPP_CONNECT_ALL_TYPE_ACCOUNT_URL.find(url_ => url_.includes(key));
|
|
40
|
+
if (existKeyAllBothConnect && value.accountAuthType !== 'both') {
|
|
41
|
+
needUpdateAuthList = true;
|
|
42
|
+
authList[key] = {
|
|
43
|
+
...value,
|
|
44
|
+
accountAuthType: 'both'
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (needUpdateAuthList) {
|
|
49
|
+
this.setAuthorize(authList);
|
|
50
|
+
}
|
|
32
51
|
}
|
|
33
52
|
getAddressList() {
|
|
34
53
|
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
@@ -42,12 +61,12 @@ class AuthRequestHandler {
|
|
|
42
61
|
return Object.keys(this.#authRequestsV2).length;
|
|
43
62
|
}
|
|
44
63
|
get allAuthRequestsV2() {
|
|
45
|
-
return Object.values(this.#authRequestsV2).map(
|
|
64
|
+
return Object.values(this.#authRequestsV2).map(_ref2 => {
|
|
46
65
|
let {
|
|
47
66
|
id,
|
|
48
67
|
request,
|
|
49
68
|
url
|
|
50
|
-
} =
|
|
69
|
+
} = _ref2;
|
|
51
70
|
return {
|
|
52
71
|
id,
|
|
53
72
|
request,
|
|
@@ -200,11 +219,11 @@ class AuthRequestHandler {
|
|
|
200
219
|
reject(error);
|
|
201
220
|
});
|
|
202
221
|
},
|
|
203
|
-
resolve:
|
|
222
|
+
resolve: _ref3 => {
|
|
204
223
|
let {
|
|
205
224
|
accounts,
|
|
206
225
|
result
|
|
207
|
-
} =
|
|
226
|
+
} = _ref3;
|
|
208
227
|
complete(result, () => {
|
|
209
228
|
resolve(result);
|
|
210
229
|
}, accounts);
|
|
@@ -214,7 +233,9 @@ class AuthRequestHandler {
|
|
|
214
233
|
authorizePromiseMap = {};
|
|
215
234
|
async authorizeUrlV2(url, request) {
|
|
216
235
|
let authList = await this.getAuthList();
|
|
217
|
-
|
|
236
|
+
const idStr = (0, _utils2.stripUrl)(url);
|
|
237
|
+
const isAllowedDappConnectAllType = !!_constants.DAPP_CONNECT_ALL_TYPE_ACCOUNT_URL.find(url_ => url.includes(url_));
|
|
238
|
+
let accountAuthType = isAllowedDappConnectAllType ? 'both' : request.accountAuthType || 'substrate';
|
|
218
239
|
request.accountAuthType = accountAuthType;
|
|
219
240
|
if (!authList) {
|
|
220
241
|
authList = {};
|
|
@@ -226,9 +247,8 @@ class AuthRequestHandler {
|
|
|
226
247
|
reject,
|
|
227
248
|
resolve
|
|
228
249
|
} = promiseHandler;
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
let [key, data] = _ref3;
|
|
250
|
+
const isExistedAuthBothBefore = Object.entries(this.authorizeUrlSubject.value).find(_ref4 => {
|
|
251
|
+
let [key, data] = _ref4;
|
|
232
252
|
return key === idStr && data.accountAuthType === 'both';
|
|
233
253
|
});
|
|
234
254
|
if (isExistedAuthBothBefore) {
|
|
@@ -244,8 +264,8 @@ class AuthRequestHandler {
|
|
|
244
264
|
|
|
245
265
|
// Do not enqueue duplicate authorization requests.
|
|
246
266
|
const mergeKeys = [];
|
|
247
|
-
Object.entries(this.#authRequestsV2).forEach(
|
|
248
|
-
let [key, _request] =
|
|
267
|
+
Object.entries(this.#authRequestsV2).forEach(_ref5 => {
|
|
268
|
+
let [key, _request] = _ref5;
|
|
249
269
|
if (_request.idStr === idStr) {
|
|
250
270
|
if (_request.accountAuthType !== request.accountAuthType) {
|
|
251
271
|
request.accountAuthType = 'both';
|
|
@@ -276,8 +296,8 @@ class AuthRequestHandler {
|
|
|
276
296
|
if (inBlackList) {
|
|
277
297
|
throw new Error('The source {{url}} is not allowed to interact with this extension'.replace('{{url}}', url));
|
|
278
298
|
}
|
|
279
|
-
request.allowedAccounts = Object.entries(existedAuth.isAllowedMap).map(
|
|
280
|
-
let [address, allowed] =
|
|
299
|
+
request.allowedAccounts = Object.entries(existedAuth.isAllowedMap).map(_ref6 => {
|
|
300
|
+
let [address, allowed] = _ref6;
|
|
281
301
|
return allowed ? address : '';
|
|
282
302
|
}).filter(item => item !== '');
|
|
283
303
|
let allowedListByRequestType = [...request.allowedAccounts];
|
|
@@ -68,11 +68,13 @@ class SwapBaseHandler {
|
|
|
68
68
|
const xcmFeeComponent = params.process.totalFee[stepIndex].feeComponent[0]; // todo: can do better than indexing
|
|
69
69
|
const xcmFee = new _bignumber.default(xcmFeeComponent.amount || '0');
|
|
70
70
|
let xcmAmount = bnAmount.minus(bnFromAssetBalance);
|
|
71
|
+
let editedXcmFee = new _bignumber.default(0);
|
|
71
72
|
if ((0, _utils._isNativeToken)(alternativeAsset)) {
|
|
72
73
|
xcmAmount = xcmAmount.plus(xcmFee);
|
|
74
|
+
editedXcmFee = xcmFee.times(2);
|
|
73
75
|
}
|
|
74
|
-
if (!bnAlternativeAssetBalance.minus(xcmAmount).gt(0)) {
|
|
75
|
-
const maxBn = bnFromAssetBalance.plus(new _bignumber.default(alternativeAssetBalance.value)).minus(xcmFee);
|
|
76
|
+
if (!bnAlternativeAssetBalance.minus((0, _utils._isNativeToken)(alternativeAsset) ? xcmAmount.plus(xcmFee) : xcmFee).gt(0)) {
|
|
77
|
+
const maxBn = bnFromAssetBalance.plus(new _bignumber.default(alternativeAssetBalance.value)).minus((0, _utils._isNativeToken)(alternativeAsset) ? editedXcmFee : xcmFee);
|
|
76
78
|
const maxValue = (0, _utils3.formatNumber)(maxBn.toString(), fromAsset.decimals || 0);
|
|
77
79
|
const altInputTokenInfo = this.chainService.getAssetBySlug(alternativeAssetSlug);
|
|
78
80
|
const symbol = altInputTokenInfo.symbol;
|
|
@@ -81,7 +83,7 @@ class SwapBaseHandler {
|
|
|
81
83
|
const inputNetworkName = chain.name;
|
|
82
84
|
const altNetworkName = alternativeChain.name;
|
|
83
85
|
const currentValue = (0, _utils3.formatNumber)(bnFromAssetBalance.toString(), fromAsset.decimals || 0);
|
|
84
|
-
const bnMaxXCM = new _bignumber.default(alternativeAssetBalance.value).minus(xcmFee);
|
|
86
|
+
const bnMaxXCM = new _bignumber.default(alternativeAssetBalance.value).minus((0, _utils._isNativeToken)(alternativeAsset) ? editedXcmFee : xcmFee);
|
|
85
87
|
const maxXCMValue = (0, _utils3.formatNumber)(bnMaxXCM.toString(), fromAsset.decimals || 0);
|
|
86
88
|
if (maxBn.lte(0) || bnFromAssetBalance.lte(0) || bnMaxXCM.lte(0)) {
|
|
87
89
|
return [new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.NOT_ENOUGH_BALANCE, (0, _i18next.t)(`Insufficient balance. Deposit ${fromAsset.symbol} and try again.`))];
|
|
@@ -34,7 +34,7 @@ class HydradxHandler {
|
|
|
34
34
|
this.swapBaseHandler = new _baseHandler.SwapBaseHandler({
|
|
35
35
|
balanceService,
|
|
36
36
|
chainService,
|
|
37
|
-
providerName: isTestnet ? '
|
|
37
|
+
providerName: isTestnet ? 'Hydration Testnet' : 'Hydration',
|
|
38
38
|
providerSlug: isTestnet ? _swap2.SwapProviderId.HYDRADX_TESTNET : _swap2.SwapProviderId.HYDRADX_MAINNET
|
|
39
39
|
});
|
|
40
40
|
this.providerSlug = isTestnet ? _swap2.SwapProviderId.HYDRADX_TESTNET : _swap2.SwapProviderId.HYDRADX_MAINNET;
|
|
@@ -4,7 +4,7 @@ export declare function _handleDisplayForEarningError(error: TransactionError):
|
|
|
4
4
|
message: string;
|
|
5
5
|
} | undefined;
|
|
6
6
|
export declare const INSUFFICIENT_MESSAGES: string[];
|
|
7
|
-
export declare function _handleDisplayInsufficientEarningError(error: Error, availableBalance: string, amount: string, minJoinPool: string): {
|
|
7
|
+
export declare function _handleDisplayInsufficientEarningError(error: Error, isXCM: boolean, availableBalance: string, amount: string, minJoinPool: string): {
|
|
8
8
|
title: string;
|
|
9
9
|
message: string;
|
|
10
10
|
} | undefined;
|
|
@@ -12,8 +12,8 @@ export function _handleDisplayForEarningError(error) {
|
|
|
12
12
|
return undefined;
|
|
13
13
|
}
|
|
14
14
|
export const INSUFFICIENT_MESSAGES = ['残高不足', 'Недостаточный баланс', 'Insufficient balance'];
|
|
15
|
-
export function _handleDisplayInsufficientEarningError(error, availableBalance, amount, minJoinPool) {
|
|
16
|
-
if (!INSUFFICIENT_MESSAGES.some(v => error.message.includes(v))) {
|
|
15
|
+
export function _handleDisplayInsufficientEarningError(error, isXCM, availableBalance, amount, minJoinPool) {
|
|
16
|
+
if (isXCM || !INSUFFICIENT_MESSAGES.some(v => error.message.includes(v))) {
|
|
17
17
|
return undefined;
|
|
18
18
|
}
|
|
19
19
|
const bnAvailableBalance = new BigN(availableBalance);
|
|
@@ -170,13 +170,6 @@ export function checkBalanceWithTransactionFee(validationResponse, transactionIn
|
|
|
170
170
|
// todo: estimateFee should be must-have, need to refactor interface
|
|
171
171
|
return;
|
|
172
172
|
}
|
|
173
|
-
|
|
174
|
-
// if (!nativeTokenAvailable.metadata) {
|
|
175
|
-
// validationResponse.errors.push(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
|
|
176
|
-
//
|
|
177
|
-
// return;
|
|
178
|
-
// }
|
|
179
|
-
|
|
180
173
|
const {
|
|
181
174
|
edAsWarning,
|
|
182
175
|
extrinsicType,
|