@subwallet/extension-base 1.3.29-1 → 1.3.31-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 +16 -4
- package/background/errors/SwapError.js +1 -1
- package/cjs/background/errors/SwapError.js +1 -1
- package/cjs/constants/blocked-actions.js +2 -2
- package/cjs/constants/paraspell-chain-map.js +13 -0
- package/cjs/constants/remind-notification-time.js +3 -3
- package/cjs/core/logic-validation/swap.js +63 -4
- package/cjs/core/logic-validation/transfer.js +13 -1
- package/cjs/core/substrate/xcm-parser.js +5 -1
- package/cjs/core/utils.js +36 -15
- package/cjs/koni/background/handlers/Extension.js +141 -172
- package/cjs/koni/background/handlers/State.js +8 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/process.js +27 -0
- package/cjs/services/balance-service/index.js +9 -0
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +229 -0
- package/cjs/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/cjs/services/balance-service/transfer/xcm/index.js +96 -7
- package/cjs/services/balance-service/transfer/xcm/utils.js +213 -0
- package/cjs/services/chain-service/constants.js +2 -4
- package/cjs/services/chain-service/index.js +71 -17
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/base.js +6 -3
- package/cjs/services/earning-service/handlers/native-staking/base.js +4 -1
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +68 -50
- package/cjs/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/cjs/services/earning-service/handlers/special.js +18 -9
- package/cjs/services/earning-service/service.js +2 -1
- package/cjs/services/fee-service/utils/index.js +16 -4
- package/cjs/services/inapp-notification-service/index.js +19 -13
- package/cjs/services/keyring-service/context/handlers/Ledger.js +1 -1
- package/cjs/services/keyring-service/context/state.js +3 -0
- package/cjs/services/migration-service/scripts/DisableZeroBalanceTokens.js +60 -0
- package/cjs/services/migration-service/scripts/EnableChain.js +1 -1
- package/cjs/services/migration-service/scripts/index.js +3 -2
- package/cjs/services/swap-service/handler/asset-hub/handler.js +61 -314
- package/cjs/services/swap-service/handler/base-handler.js +406 -231
- package/cjs/services/swap-service/handler/chainflip-handler.js +18 -40
- package/cjs/services/swap-service/handler/hydradx-handler.js +77 -269
- package/cjs/services/swap-service/handler/simpleswap-handler.js +27 -48
- package/cjs/services/swap-service/handler/uniswap-handler.js +33 -54
- package/cjs/services/swap-service/index.js +154 -143
- package/cjs/services/swap-service/utils.js +107 -17
- package/cjs/services/transaction-service/index.js +1 -1
- package/cjs/services/transaction-service/utils.js +38 -14
- package/cjs/types/swap/index.js +13 -1
- package/cjs/utils/fee/transfer.js +52 -28
- package/cjs/utils/staticData/index.js +7 -2
- package/cjs/utils/swap.js +5 -1
- package/constants/blocked-actions.d.ts +1 -1
- package/constants/blocked-actions.js +1 -1
- package/constants/paraspell-chain-map.d.ts +1 -0
- package/constants/paraspell-chain-map.js +7 -0
- package/constants/remind-notification-time.d.ts +1 -1
- package/constants/remind-notification-time.js +1 -1
- package/core/logic-validation/swap.d.ts +15 -0
- package/core/logic-validation/swap.js +60 -4
- package/core/logic-validation/transfer.d.ts +1 -0
- package/core/logic-validation/transfer.js +12 -1
- package/core/substrate/xcm-parser.d.ts +1 -0
- package/core/substrate/xcm-parser.js +4 -1
- package/core/utils.d.ts +2 -2
- package/core/utils.js +36 -15
- package/koni/background/handlers/Extension.d.ts +1 -1
- package/koni/background/handlers/Extension.js +66 -98
- package/koni/background/handlers/State.d.ts +1 -0
- package/koni/background/handlers/State.js +7 -1
- package/package.json +23 -13
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/process.d.ts +2 -1
- package/services/balance-service/helpers/process.js +26 -0
- package/services/balance-service/index.js +11 -2
- package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +15 -0
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +216 -0
- package/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/services/balance-service/transfer/xcm/index.d.ts +5 -1
- package/services/balance-service/transfer/xcm/index.js +85 -1
- package/services/balance-service/transfer/xcm/utils.d.ts +11 -0
- package/services/balance-service/transfer/xcm/utils.js +208 -0
- package/services/base/types.d.ts +0 -4
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +1 -2
- package/services/chain-service/index.d.ts +9 -2
- package/services/chain-service/index.js +72 -18
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/base.d.ts +4 -3
- package/services/earning-service/handlers/base.js +6 -4
- package/services/earning-service/handlers/native-staking/base.js +4 -1
- package/services/earning-service/handlers/native-staking/dtao.d.ts +9 -6
- package/services/earning-service/handlers/native-staking/dtao.js +69 -48
- package/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/services/earning-service/handlers/special.js +19 -10
- package/services/earning-service/service.d.ts +2 -1
- package/services/earning-service/service.js +2 -1
- package/services/fee-service/utils/index.d.ts +1 -0
- package/services/fee-service/utils/index.js +14 -4
- package/services/inapp-notification-service/index.js +13 -7
- package/services/keyring-service/context/handlers/Ledger.js +1 -1
- package/services/keyring-service/context/state.d.ts +1 -0
- package/services/keyring-service/context/state.js +3 -0
- package/services/migration-service/scripts/DisableZeroBalanceTokens.d.ts +4 -0
- package/services/migration-service/scripts/DisableZeroBalanceTokens.js +51 -0
- package/services/migration-service/scripts/EnableChain.js +1 -1
- package/services/migration-service/scripts/index.js +3 -2
- package/services/swap-service/handler/asset-hub/handler.d.ts +2 -9
- package/services/swap-service/handler/asset-hub/handler.js +64 -317
- package/services/swap-service/handler/base-handler.d.ts +6 -9
- package/services/swap-service/handler/base-handler.js +405 -230
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -4
- package/services/swap-service/handler/chainflip-handler.js +15 -37
- package/services/swap-service/handler/hydradx-handler.d.ts +3 -10
- package/services/swap-service/handler/hydradx-handler.js +78 -270
- package/services/swap-service/handler/simpleswap-handler.d.ts +2 -4
- package/services/swap-service/handler/simpleswap-handler.js +24 -45
- package/services/swap-service/handler/uniswap-handler.d.ts +4 -6
- package/services/swap-service/handler/uniswap-handler.js +25 -46
- package/services/swap-service/index.d.ts +8 -14
- package/services/swap-service/index.js +141 -129
- package/services/swap-service/utils.d.ts +11 -3
- package/services/swap-service/utils.js +96 -15
- package/services/transaction-service/index.js +2 -2
- package/services/transaction-service/types.d.ts +3 -2
- package/services/transaction-service/utils.d.ts +1 -0
- package/services/transaction-service/utils.js +38 -15
- package/types/balance/transfer.d.ts +1 -0
- package/types/service-base.d.ts +2 -3
- package/types/swap/index.d.ts +25 -9
- package/types/swap/index.js +10 -0
- package/types/transaction/process.d.ts +19 -0
- package/types/transaction/request.d.ts +7 -0
- package/types/yield/actions/join/submit.d.ts +4 -1
- package/types/yield/actions/others.d.ts +2 -0
- package/utils/fee/transfer.d.ts +1 -0
- package/utils/fee/transfer.js +54 -30
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/paraSpellChainMap.json +1 -0
- package/utils/swap.d.ts +3 -0
- package/utils/swap.js +3 -0
- package/cjs/services/swap-service/interface.js +0 -14
- package/services/swap-service/interface.d.ts +0 -9
- package/services/swap-service/interface.js +0 -8
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.default = exports.DEFAULT_DTAO_MINBOND = void 0;
|
|
8
8
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
9
9
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
10
|
var _constants = require("@subwallet/extension-base/constants");
|
|
@@ -13,13 +13,11 @@ var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
|
13
13
|
var _basePara = _interopRequireDefault(require("@subwallet/extension-base/services/earning-service/handlers/native-staking/base-para"));
|
|
14
14
|
var _types = require("@subwallet/extension-base/types");
|
|
15
15
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
16
|
-
var _bignumber =
|
|
16
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
17
17
|
var _i18next = require("i18next");
|
|
18
18
|
var _util = require("@polkadot/util");
|
|
19
19
|
var _utils4 = require("../../utils");
|
|
20
20
|
var _tao = require("./tao");
|
|
21
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
21
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
24
22
|
// SPDX-License-Identifier: Apache-2.0
|
|
25
23
|
|
|
@@ -28,24 +26,30 @@ const DEFAULT_DTAO_MINBOND = '600000';
|
|
|
28
26
|
exports.DEFAULT_DTAO_MINBOND = DEFAULT_DTAO_MINBOND;
|
|
29
27
|
const getAlphaToTaoMapping = async substrateApi => {
|
|
30
28
|
const allSubnets = (await substrateApi.api.call.subnetInfoRuntimeApi.getAllDynamicInfo()).toJSON();
|
|
31
|
-
if (!allSubnets) {
|
|
29
|
+
if (!allSubnets || allSubnets.length === 0) {
|
|
32
30
|
return {};
|
|
33
31
|
}
|
|
34
|
-
|
|
32
|
+
const result = Object.create(null);
|
|
33
|
+
for (const subnet of allSubnets) {
|
|
35
34
|
const netuid = subnet === null || subnet === void 0 ? void 0 : subnet.netuid;
|
|
35
|
+
if (netuid === undefined) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
36
38
|
const taoIn = subnet !== null && subnet !== void 0 && subnet.taoIn ? new _bignumber.default(subnet.taoIn) : new _bignumber.default(0);
|
|
37
39
|
const alphaIn = subnet !== null && subnet !== void 0 && subnet.alphaIn ? new _bignumber.default(subnet.alphaIn) : new _bignumber.default(0);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return
|
|
46
|
-
}
|
|
40
|
+
result[netuid] = netuid === 0 || alphaIn.lte(0) ? '1' : taoIn.dividedBy(alphaIn).toString();
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
const getAlphaToTaoRate = async (substrateApi, netuid) => {
|
|
45
|
+
const subnetInfo = (await substrateApi.api.call.subnetInfoRuntimeApi.getDynamicInfo(netuid)).toJSON();
|
|
46
|
+
if (!subnetInfo) {
|
|
47
|
+
return '1';
|
|
48
|
+
}
|
|
49
|
+
const taoIn = subnetInfo.taoIn ? new _bignumber.default(subnetInfo.taoIn) : new _bignumber.default(0);
|
|
50
|
+
const alphaIn = subnetInfo.alphaIn ? new _bignumber.default(subnetInfo.alphaIn) : new _bignumber.default(0);
|
|
51
|
+
return netuid === 0 || alphaIn.lte(0) ? '1' : taoIn.dividedBy(alphaIn).toString();
|
|
47
52
|
};
|
|
48
|
-
exports.getAlphaToTaoMapping = getAlphaToTaoMapping;
|
|
49
53
|
class SubnetTaoStakingPoolHandler extends _basePara.default {
|
|
50
54
|
/* Unimplemented function */
|
|
51
55
|
handleYieldWithdraw(address, unstakingInfo) {
|
|
@@ -84,30 +88,40 @@ class SubnetTaoStakingPoolHandler extends _basePara.default {
|
|
|
84
88
|
async getEarningSlippage(params) {
|
|
85
89
|
const substrateApi = await this.substrateApi.isReady;
|
|
86
90
|
const subnetInfo = (await substrateApi.api.call.subnetInfoRuntimeApi.getDynamicInfo(params.netuid)).toJSON();
|
|
87
|
-
const alphaIn = new _bignumber.
|
|
88
|
-
const taoIn = new _bignumber.
|
|
91
|
+
const alphaIn = new _bignumber.default((subnetInfo === null || subnetInfo === void 0 ? void 0 : subnetInfo.alphaIn) || 0);
|
|
92
|
+
const taoIn = new _bignumber.default((subnetInfo === null || subnetInfo === void 0 ? void 0 : subnetInfo.taoIn) || 0);
|
|
89
93
|
const k = alphaIn.multipliedBy(taoIn);
|
|
90
|
-
const value = new _bignumber.
|
|
94
|
+
const value = new _bignumber.default(params.value);
|
|
95
|
+
const rate = taoIn.dividedBy(alphaIn);
|
|
91
96
|
if (params.type === _KoniTypes.ExtrinsicType.STAKING_BOND) {
|
|
92
97
|
const newTaoIn = taoIn.plus(value);
|
|
93
98
|
const newAlphaIn = k.dividedBy(newTaoIn);
|
|
94
99
|
const alphaReturned = alphaIn.minus(newAlphaIn);
|
|
95
100
|
const alphaIdeal = value.multipliedBy(alphaIn).dividedBy(taoIn);
|
|
96
101
|
const slippage = alphaIdeal.minus(alphaReturned).dividedBy(alphaIdeal);
|
|
97
|
-
return
|
|
102
|
+
return {
|
|
103
|
+
slippage: slippage.plus(0.0001).toNumber(),
|
|
104
|
+
rate: rate.toNumber()
|
|
105
|
+
};
|
|
98
106
|
} else if (params.type === _KoniTypes.ExtrinsicType.STAKING_UNBOND) {
|
|
99
107
|
const newAlphaIn = alphaIn.plus(value);
|
|
100
108
|
const newTaoReserve = k.dividedBy(newAlphaIn);
|
|
101
109
|
const taoReturned = taoIn.minus(newTaoReserve);
|
|
102
110
|
const taoIdeal = value.multipliedBy(taoIn).dividedBy(alphaIn);
|
|
103
111
|
const slippage = taoIdeal.minus(taoReturned).dividedBy(taoIdeal);
|
|
104
|
-
return
|
|
112
|
+
return {
|
|
113
|
+
slippage: slippage.plus(0.0001).toNumber(),
|
|
114
|
+
rate: rate.toNumber()
|
|
115
|
+
};
|
|
105
116
|
}
|
|
106
|
-
return
|
|
117
|
+
return {
|
|
118
|
+
slippage: 0,
|
|
119
|
+
rate: 1
|
|
120
|
+
};
|
|
107
121
|
}
|
|
108
122
|
get maintainBalance() {
|
|
109
|
-
const ed = new
|
|
110
|
-
const calculateMaintainBalance = new
|
|
123
|
+
const ed = new _bignumber.default(this.nativeToken.minAmount || '0');
|
|
124
|
+
const calculateMaintainBalance = new _bignumber.default(15).multipliedBy(ed).dividedBy(10);
|
|
111
125
|
const maintainBalance = calculateMaintainBalance;
|
|
112
126
|
return maintainBalance.toString();
|
|
113
127
|
}
|
|
@@ -134,7 +148,8 @@ class SubnetTaoStakingPoolHandler extends _basePara.default {
|
|
|
134
148
|
symbol,
|
|
135
149
|
ownerHotkey: dynInfo.ownerHotkey,
|
|
136
150
|
maxAllowedValidators: extraInfo ? extraInfo.maxAllowedValidators : 0,
|
|
137
|
-
taoIn: dynInfo.taoIn
|
|
151
|
+
taoIn: dynInfo.taoIn,
|
|
152
|
+
taoInEmission: dynInfo.taoInEmission
|
|
138
153
|
};
|
|
139
154
|
});
|
|
140
155
|
this.subnetData = mergedData;
|
|
@@ -164,7 +179,8 @@ class SubnetTaoStakingPoolHandler extends _basePara.default {
|
|
|
164
179
|
const netuid = subnet.netuid.toString().padStart(2, '0');
|
|
165
180
|
const subnetSlug = `${this.slug}__subnet_${netuid.padStart(2, '0')}`;
|
|
166
181
|
const subnetName = `${subnet.name || 'Unknown'} ${netuid}`;
|
|
167
|
-
const bnTaoIn = new
|
|
182
|
+
const bnTaoIn = new _bignumber.default(subnet.taoIn);
|
|
183
|
+
const emission = new _bignumber.default(subnet.taoInEmission).dividedBy(new _bignumber.default(10).pow(new _bignumber.default(7)));
|
|
168
184
|
const data = {
|
|
169
185
|
...this.baseInfo,
|
|
170
186
|
type: this.type,
|
|
@@ -193,7 +209,8 @@ class SubnetTaoStakingPoolHandler extends _basePara.default {
|
|
|
193
209
|
eraTime: 24,
|
|
194
210
|
era: 0,
|
|
195
211
|
unstakingPeriod: 1.2,
|
|
196
|
-
tvl: bnTaoIn.toString()
|
|
212
|
+
tvl: bnTaoIn.toString(),
|
|
213
|
+
totalApy: emission.toNumber()
|
|
197
214
|
}
|
|
198
215
|
};
|
|
199
216
|
callback(data);
|
|
@@ -361,7 +378,7 @@ class SubnetTaoStakingPoolHandler extends _basePara.default {
|
|
|
361
378
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
362
379
|
async getDevnetPoolTargets() {
|
|
363
380
|
const testnetDelegate = (await this.substrateApi.api.call.delegateInfoRuntimeApi.getDelegates()).toJSON();
|
|
364
|
-
const bnMinBond = new
|
|
381
|
+
const bnMinBond = new _bignumber.default(DEFAULT_DTAO_MINBOND);
|
|
365
382
|
const filteredDelegates = testnetDelegate.filter(delegate => {
|
|
366
383
|
return delegate.returnPer1000 !== 0;
|
|
367
384
|
});
|
|
@@ -382,14 +399,14 @@ class SubnetTaoStakingPoolHandler extends _basePara.default {
|
|
|
382
399
|
async getMainnetPoolTargets() {
|
|
383
400
|
const _topValidator = await this.bittensorCache.get();
|
|
384
401
|
const topValidator = _topValidator;
|
|
385
|
-
const bnMinBond = new
|
|
402
|
+
const bnMinBond = new _bignumber.default(DEFAULT_DTAO_MINBOND);
|
|
386
403
|
const validatorList = topValidator.data;
|
|
387
404
|
const validatorAddresses = Object.keys(validatorList);
|
|
388
405
|
const results = await Promise.all(validatorAddresses.map(i => {
|
|
389
406
|
const address = validatorList[i].hotkey.ss58;
|
|
390
|
-
const bnTotalStake = new
|
|
391
|
-
const bnOwnStake = new
|
|
392
|
-
const otherStake = bnTotalStake.
|
|
407
|
+
const bnTotalStake = new _bignumber.default(validatorList[i].stake);
|
|
408
|
+
const bnOwnStake = new _bignumber.default(validatorList[i].validator_stake);
|
|
409
|
+
const otherStake = bnTotalStake.minus(bnOwnStake);
|
|
393
410
|
const nominatorCount = validatorList[i].nominators;
|
|
394
411
|
const commission = validatorList[i].take;
|
|
395
412
|
const roundedCommission = (parseFloat(commission) * 100).toFixed(0);
|
|
@@ -431,15 +448,18 @@ class SubnetTaoStakingPoolHandler extends _basePara.default {
|
|
|
431
448
|
let bondDest = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Staked';
|
|
432
449
|
const {
|
|
433
450
|
amount,
|
|
434
|
-
|
|
435
|
-
|
|
451
|
+
selectedValidators: targetValidators,
|
|
452
|
+
subnetData
|
|
436
453
|
} = data;
|
|
454
|
+
const {
|
|
455
|
+
netuid,
|
|
456
|
+
slippage
|
|
457
|
+
} = subnetData;
|
|
437
458
|
const chainApi = await this.substrateApi.isReady;
|
|
438
|
-
const binaryAmount = new
|
|
439
|
-
const
|
|
440
|
-
const
|
|
441
|
-
const
|
|
442
|
-
const BNlimitPrice = new _util.BN(limitPrice.integerValue(_bignumber.BigNumber.ROUND_CEIL).toFixed());
|
|
459
|
+
const binaryAmount = new _bignumber.default(amount);
|
|
460
|
+
const alphaToTaoPrice = new _bignumber.default(await getAlphaToTaoRate(this.substrateApi, netuid));
|
|
461
|
+
const limitPrice = alphaToTaoPrice.multipliedBy(10 ** (0, _utils2._getAssetDecimals)(this.nativeToken)).multipliedBy(1 + (slippage || DEFAULT_BITTENSOR_SLIPPAGE));
|
|
462
|
+
const BNlimitPrice = new _bignumber.default(limitPrice.integerValue(_bignumber.default.ROUND_CEIL).toFixed());
|
|
443
463
|
const selectedValidatorInfo = targetValidators[0];
|
|
444
464
|
const hotkey = selectedValidatorInfo.address;
|
|
445
465
|
const extrinsic = chainApi.api.tx.subtensorModule.addStakeLimit(hotkey, netuid, binaryAmount, BNlimitPrice, false);
|
|
@@ -456,7 +476,7 @@ class SubnetTaoStakingPoolHandler extends _basePara.default {
|
|
|
456
476
|
const {
|
|
457
477
|
amount
|
|
458
478
|
} = data;
|
|
459
|
-
if (new
|
|
479
|
+
if (new _bignumber.default(amount).lt(new _bignumber.default(DEFAULT_DTAO_MINBOND))) {
|
|
460
480
|
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS, (0, _i18next.t)(`Insufficient stake. You need to stake at least ${(0, _utils3.formatNumber)(DEFAULT_DTAO_MINBOND, (0, _utils2._getAssetDecimals)(this.nativeToken))} ${(0, _utils2._getAssetSymbol)(this.nativeToken)} to earn rewards`))];
|
|
461
481
|
}
|
|
462
482
|
return baseErrors;
|
|
@@ -466,16 +486,15 @@ class SubnetTaoStakingPoolHandler extends _basePara.default {
|
|
|
466
486
|
|
|
467
487
|
/* Leave pool action */
|
|
468
488
|
|
|
469
|
-
async handleYieldUnstake(amount, address, selectedTarget, netuid) {
|
|
489
|
+
async handleYieldUnstake(amount, address, selectedTarget, netuid, slippage) {
|
|
470
490
|
const apiPromise = await this.substrateApi.isReady;
|
|
471
|
-
const binaryAmount = new _util.BN(amount);
|
|
472
|
-
const price = await getAlphaToTaoMapping(this.substrateApi);
|
|
473
|
-
const alphaToTaoPrice = new _bignumber.default(price[netuid]);
|
|
474
|
-
const limitPrice = alphaToTaoPrice.multipliedBy(10 ** (0, _utils2._getAssetDecimals)(this.nativeToken)).multipliedBy(1 - DEFAULT_BITTENSOR_SLIPPAGE);
|
|
475
|
-
const BNlimitPrice = new _util.BN(limitPrice.integerValue(_bignumber.BigNumber.ROUND_CEIL).toFixed());
|
|
476
491
|
if (!selectedTarget) {
|
|
477
492
|
return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS));
|
|
478
493
|
}
|
|
494
|
+
const binaryAmount = new _bignumber.default(amount);
|
|
495
|
+
const alphaToTaoPrice = new _bignumber.default(await getAlphaToTaoRate(this.substrateApi, netuid || 0));
|
|
496
|
+
const limitPrice = alphaToTaoPrice.multipliedBy(10 ** (0, _utils2._getAssetDecimals)(this.nativeToken)).multipliedBy(1 - (slippage || DEFAULT_BITTENSOR_SLIPPAGE));
|
|
497
|
+
const BNlimitPrice = new _bignumber.default(limitPrice.integerValue(_bignumber.default.ROUND_CEIL).toFixed());
|
|
479
498
|
const extrinsic = apiPromise.api.tx.subtensorModule.removeStakeLimit(selectedTarget, netuid, binaryAmount, BNlimitPrice, false);
|
|
480
499
|
return [_KoniTypes.ExtrinsicType.STAKING_UNBOND, extrinsic];
|
|
481
500
|
}
|
|
@@ -489,10 +508,9 @@ class SubnetTaoStakingPoolHandler extends _basePara.default {
|
|
|
489
508
|
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS)];
|
|
490
509
|
}
|
|
491
510
|
const netuid = (_poolInfo$metadata$su = poolInfo.metadata.subnetData) === null || _poolInfo$metadata$su === void 0 ? void 0 : _poolInfo$metadata$su.netuid;
|
|
492
|
-
const
|
|
493
|
-
const minUnstake = new _bignumber.default(DEFAULT_DTAO_MINBOND).dividedBy(
|
|
494
|
-
|
|
495
|
-
const formattedMinUnstake = minUnstake.dividedBy(1000000).integerValue(_bignumber.BigNumber.ROUND_CEIL).dividedBy(1000);
|
|
511
|
+
const alphaToTaoPrice = new _bignumber.default(await getAlphaToTaoRate(this.substrateApi, netuid || 0));
|
|
512
|
+
const minUnstake = new _bignumber.default(DEFAULT_DTAO_MINBOND).dividedBy(alphaToTaoPrice);
|
|
513
|
+
const formattedMinUnstake = minUnstake.dividedBy(1000000).integerValue(_bignumber.default.ROUND_CEIL).dividedBy(1000);
|
|
496
514
|
if (new _bignumber.default(amount).lt(formattedMinUnstake.multipliedBy(10 ** (0, _utils2._getAssetDecimals)(this.nativeToken)))) {
|
|
497
515
|
var _poolInfo$metadata$su2;
|
|
498
516
|
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS, (0, _i18next.t)(`Amount too low. You need to unstake at least ${formattedMinUnstake.toString()} ${((_poolInfo$metadata$su2 = poolInfo.metadata.subnetData) === null || _poolInfo$metadata$su2 === void 0 ? void 0 : _poolInfo$metadata$su2.subnetSymbol) || ''}`))];
|
|
@@ -82,7 +82,7 @@ class BittensorCache {
|
|
|
82
82
|
async fetchData() {
|
|
83
83
|
const apiKey = bittensorApiKey();
|
|
84
84
|
try {
|
|
85
|
-
const resp = await fetch('https://api.taostats.io/api/validator/latest/v1?limit=
|
|
85
|
+
const resp = await fetch('https://api.taostats.io/api/validator/latest/v1?limit=50', {
|
|
86
86
|
method: 'GET',
|
|
87
87
|
headers: {
|
|
88
88
|
'Content-Type': 'application/json',
|
|
@@ -194,8 +194,17 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
|
|
|
194
194
|
const minDelegatorStake = (await substrateApi.api.query.subtensorModule.nominatorMinRequiredStake()).toPrimitive() || 0;
|
|
195
195
|
const maxValidatorPerNominator = (await substrateApi.api.query.subtensorModule.maxAllowedValidators(0)).toPrimitive();
|
|
196
196
|
const taoIn = (await substrateApi.api.query.subtensorModule.subnetTAO(0)).toPrimitive();
|
|
197
|
+
const _topValidator = await this.bittensorCache.get();
|
|
198
|
+
const validators = _topValidator.data;
|
|
199
|
+
let highestApr = validators[0];
|
|
200
|
+
for (let i = 1; i < validators.length; i++) {
|
|
201
|
+
if (parseFloat(validators[i].apr) > parseFloat(highestApr.apr)) {
|
|
202
|
+
highestApr = validators[i];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
197
205
|
const bnTaoIn = new _util.BN(taoIn);
|
|
198
206
|
const BNminDelegatorStake = new _bignumber.default(minDelegatorStake.toString());
|
|
207
|
+
const apr = this.chain === 'bittensor' ? Number(highestApr.apr) * 100 : 0;
|
|
199
208
|
const data = {
|
|
200
209
|
...this.baseInfo,
|
|
201
210
|
type: this.type,
|
|
@@ -217,7 +226,8 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
|
|
|
217
226
|
eraTime: 24,
|
|
218
227
|
era: 0,
|
|
219
228
|
unstakingPeriod: 1.2,
|
|
220
|
-
tvl: bnTaoIn.toString()
|
|
229
|
+
tvl: bnTaoIn.toString(),
|
|
230
|
+
totalApy: apr
|
|
221
231
|
}
|
|
222
232
|
};
|
|
223
233
|
callback(data);
|
|
@@ -14,6 +14,7 @@ var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
|
14
14
|
var _types = require("@subwallet/extension-base/types");
|
|
15
15
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
16
16
|
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
17
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
17
18
|
var _i18next = require("i18next");
|
|
18
19
|
var _util = require("@polkadot/util");
|
|
19
20
|
var _base = _interopRequireDefault(require("./base"));
|
|
@@ -226,7 +227,7 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
226
227
|
const xcmOriginSubstrateApi = await this.state.getSubstrateApi(altInputTokenInfo.originChain).isReady;
|
|
227
228
|
const id = (0, _getId.getId)();
|
|
228
229
|
const feeInfo = await this.state.feeService.subscribeChainFee(id, altChainInfo.slug, 'substrate');
|
|
229
|
-
const
|
|
230
|
+
const xcmRequest = {
|
|
230
231
|
sender: address,
|
|
231
232
|
originTokenInfo: altInputTokenInfo,
|
|
232
233
|
destinationTokenInfo: inputTokenInfo,
|
|
@@ -236,16 +237,20 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
236
237
|
originChain: altChainInfo,
|
|
237
238
|
substrateApi: xcmOriginSubstrateApi,
|
|
238
239
|
feeInfo
|
|
239
|
-
}
|
|
240
|
-
const _xcmFeeInfo = await xcmTransfer.paymentInfo(address);
|
|
241
|
-
const xcmFeeInfo = _xcmFeeInfo.toPrimitive();
|
|
242
|
-
// TODO: calculate fee for destination chain
|
|
240
|
+
};
|
|
243
241
|
|
|
242
|
+
// TODO: calculate fee for destination chain
|
|
243
|
+
let xcmFee;
|
|
244
|
+
const xcmFeeByDryRun = await (0, _xcm.dryRunXcmExtrinsicV2)(xcmRequest);
|
|
245
|
+
if (xcmFeeByDryRun.fee) {
|
|
246
|
+
xcmFee = (0, _bignumber.default)(xcmFeeByDryRun.fee).multipliedBy(_constants.XCM_MIN_AMOUNT_RATIO).toFixed(0, 1);
|
|
247
|
+
} else {
|
|
248
|
+
throw new Error('Error estimating XCM fee');
|
|
249
|
+
}
|
|
244
250
|
const fee = {
|
|
245
251
|
slug: altInputTokenSlug,
|
|
246
|
-
amount:
|
|
252
|
+
amount: xcmFee
|
|
247
253
|
};
|
|
248
|
-
|
|
249
254
|
let bnTransferAmount = bnAmount.sub(bnInputTokenBalance);
|
|
250
255
|
if ((0, _utils2._isNativeToken)(altInputTokenInfo)) {
|
|
251
256
|
const bnXcmFee = new _util.BN(fee.amount || 0); // xcm fee is paid in native token but swap token is not always native token
|
|
@@ -449,7 +454,7 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
449
454
|
const bnTotalAmount = bnAmount.sub(bnInputTokenBalance).add(bnXcmFee);
|
|
450
455
|
const id = (0, _getId.getId)();
|
|
451
456
|
const feeInfo = await this.state.feeService.subscribeChainFee(id, originChainInfo.slug, 'substrate');
|
|
452
|
-
const
|
|
457
|
+
const xcmRequest = {
|
|
453
458
|
destinationTokenInfo,
|
|
454
459
|
originTokenInfo,
|
|
455
460
|
recipient: address,
|
|
@@ -459,7 +464,11 @@ class BaseSpecialStakingPoolHandler extends _base.default {
|
|
|
459
464
|
originChain: originChainInfo,
|
|
460
465
|
destinationChain: this.chainInfo,
|
|
461
466
|
feeInfo
|
|
462
|
-
}
|
|
467
|
+
};
|
|
468
|
+
const extrinsic = await (0, _xcm.createXcmExtrinsicV2)(xcmRequest);
|
|
469
|
+
if (!extrinsic) {
|
|
470
|
+
throw new Error('Error handling XCM extrinsic');
|
|
471
|
+
}
|
|
463
472
|
const xcmData = {
|
|
464
473
|
originNetworkKey: originChainInfo.slug,
|
|
465
474
|
destinationNetworkKey: destinationTokenInfo.originChain,
|
|
@@ -765,8 +765,9 @@ class EarningService {
|
|
|
765
765
|
} = params;
|
|
766
766
|
const handler = this.getPoolHandler(slug);
|
|
767
767
|
const netuid = (_params$poolInfo$meta = params.poolInfo.metadata.subnetData) === null || _params$poolInfo$meta === void 0 ? void 0 : _params$poolInfo$meta.netuid;
|
|
768
|
+
const slippage = params.slippage;
|
|
768
769
|
if (handler) {
|
|
769
|
-
return handler.handleYieldLeave(params.fastLeave, params.amount, params.address, params.selectedTarget, netuid);
|
|
770
|
+
return handler.handleYieldLeave(params.fastLeave, params.amount, params.address, params.selectedTarget, netuid, slippage);
|
|
770
771
|
} else {
|
|
771
772
|
return Promise.reject(new _TransactionError.TransactionError(_types2.BasicTxErrorType.INTERNAL_ERROR));
|
|
772
773
|
}
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.recalculateGasPrice = exports.parseInfuraFee = exports.getEIP1559GasFee = exports.fetchSubWalletFeeData = exports.fetchOnlineFeeData = exports.fetchInfuraFeeData = exports.calculateToAmountByReservePool = exports.calculateGasFeeParams = exports.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE = void 0;
|
|
7
|
+
exports.recalculateGasPrice = exports.parseInfuraFee = exports.getEIP1559GasFee = exports.fetchSubWalletFeeData = exports.fetchOnlineFeeData = exports.fetchInfuraFeeData = exports.enforceMinOneTip = exports.calculateToAmountByReservePool = exports.calculateGasFeeParams = exports.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE = void 0;
|
|
8
8
|
var _constants = require("@subwallet/extension-base/constants");
|
|
9
9
|
var _utils = require("@subwallet/extension-base/services/swap-service/handler/asset-hub/utils");
|
|
10
10
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
@@ -18,6 +18,7 @@ const INFURA_API_KEY_SECRET = process.env.INFURA_API_KEY_SECRET || '';
|
|
|
18
18
|
const INFURA_AUTH = 'Basic ' + Buffer.from(INFURA_API_KEY + ':' + INFURA_API_KEY_SECRET).toString('base64');
|
|
19
19
|
const FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE = 105; // percentage
|
|
20
20
|
exports.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE = FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE;
|
|
21
|
+
const EIP1559_MIN_PRIORITY_FEE = '1';
|
|
21
22
|
const parseInfuraFee = (info, threshold) => {
|
|
22
23
|
const base = new _bignumber.default(info.estimatedBaseFee).multipliedBy(_utils2.BN_WEI);
|
|
23
24
|
const thresholdBN = new _bignumber.default(threshold.busyThreshold).multipliedBy(_utils2.BN_WEI);
|
|
@@ -177,15 +178,18 @@ const calculateGasFeeParams = async function (web3, networkKey) {
|
|
|
177
178
|
const slowPriorityFee = history.reward.reduce((previous, rewards) => previous.plus(rewards[0]), _utils2.BN_ZERO).dividedBy(numBlock).decimalPlaces(0);
|
|
178
179
|
const averagePriorityFee = history.reward.reduce((previous, rewards) => previous.plus(rewards[1]), _utils2.BN_ZERO).dividedBy(numBlock).decimalPlaces(0);
|
|
179
180
|
const fastPriorityFee = history.reward.reduce((previous, rewards) => previous.plus(rewards[2]), _utils2.BN_ZERO).dividedBy(numBlock).decimalPlaces(0);
|
|
181
|
+
if (slowPriorityFee.eq(0) && averagePriorityFee.eq(0) && fastPriorityFee.eq(0)) {
|
|
182
|
+
throw new Error('Fee rates are currently same for all levels');
|
|
183
|
+
}
|
|
180
184
|
return {
|
|
181
185
|
type: 'evm',
|
|
182
186
|
gasPrice: undefined,
|
|
183
187
|
baseGasFee: baseGasFee.toString(),
|
|
184
188
|
busyNetwork,
|
|
185
189
|
options: {
|
|
186
|
-
slow: getEIP1559GasFee(baseGasFee, slowPriorityFee, 10, blockTime),
|
|
187
|
-
average: getEIP1559GasFee(baseGasFee, averagePriorityFee, 5, blockTime),
|
|
188
|
-
fast: getEIP1559GasFee(baseGasFee, fastPriorityFee, 3, blockTime),
|
|
190
|
+
slow: enforceMinOneTip(getEIP1559GasFee(baseGasFee, slowPriorityFee, 10, blockTime)),
|
|
191
|
+
average: enforceMinOneTip(getEIP1559GasFee(baseGasFee, averagePriorityFee, 5, blockTime)),
|
|
192
|
+
fast: enforceMinOneTip(getEIP1559GasFee(baseGasFee, fastPriorityFee, 3, blockTime)),
|
|
189
193
|
default: busyNetwork ? 'average' : 'slow'
|
|
190
194
|
}
|
|
191
195
|
};
|
|
@@ -202,6 +206,14 @@ const calculateGasFeeParams = async function (web3, networkKey) {
|
|
|
202
206
|
}
|
|
203
207
|
};
|
|
204
208
|
exports.calculateGasFeeParams = calculateGasFeeParams;
|
|
209
|
+
const enforceMinOneTip = feeOptionDetail => {
|
|
210
|
+
if (feeOptionDetail.maxPriorityFeePerGas === '0') {
|
|
211
|
+
feeOptionDetail.maxPriorityFeePerGas = EIP1559_MIN_PRIORITY_FEE;
|
|
212
|
+
return feeOptionDetail;
|
|
213
|
+
}
|
|
214
|
+
return feeOptionDetail;
|
|
215
|
+
};
|
|
216
|
+
exports.enforceMinOneTip = enforceMinOneTip;
|
|
205
217
|
const calculateToAmountByReservePool = async (api, fromToken, toToken, fromAmount) => {
|
|
206
218
|
const reserve = await (0, _utils.getReserveForPool)(api, fromToken, toToken);
|
|
207
219
|
return (0, _utils.estimateTokensForPool)(fromAmount, reserve);
|
|
@@ -13,8 +13,9 @@ var _constants2 = require("@subwallet/extension-base/services/earning-service/co
|
|
|
13
13
|
var _consts = require("@subwallet/extension-base/services/inapp-notification-service/consts");
|
|
14
14
|
var _interfaces = require("@subwallet/extension-base/services/inapp-notification-service/interfaces");
|
|
15
15
|
var _utils = require("@subwallet/extension-base/services/inapp-notification-service/utils");
|
|
16
|
+
var _utils2 = require("@subwallet/extension-base/services/swap-service/utils");
|
|
16
17
|
var _types2 = require("@subwallet/extension-base/types");
|
|
17
|
-
var
|
|
18
|
+
var _utils3 = require("@subwallet/extension-base/utils");
|
|
18
19
|
var _keyring = require("@subwallet/keyring");
|
|
19
20
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
20
21
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -155,7 +156,7 @@ class InappNotificationService {
|
|
|
155
156
|
const [comparedNotifications, remindTimeConfig] = await Promise.all([this.fetchNotificationsByParams({
|
|
156
157
|
notificationTab: _interfaces.NotificationTab.ALL,
|
|
157
158
|
proxyId
|
|
158
|
-
}), await (0, _remindNotificationTime.
|
|
159
|
+
}), await (0, _remindNotificationTime.fetchLatestRemindNotificationTime)()]);
|
|
159
160
|
for (const candidateNotification of notifications) {
|
|
160
161
|
candidateNotification.title = candidateNotification.title.replace('{{accountName}}', accountName);
|
|
161
162
|
if (this.passValidateNotification(candidateNotification, comparedNotifications, remindTimeConfig)) {
|
|
@@ -177,8 +178,8 @@ class InappNotificationService {
|
|
|
177
178
|
}
|
|
178
179
|
getCategorizedAddresses() {
|
|
179
180
|
const addresses = this.keyringService.context.getAllAddresses();
|
|
180
|
-
const evmAddresses = (0,
|
|
181
|
-
const substrateAddresses = (0,
|
|
181
|
+
const evmAddresses = (0, _utils3.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.EVM]);
|
|
182
|
+
const substrateAddresses = (0, _utils3.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.SUBSTRATE]);
|
|
182
183
|
return {
|
|
183
184
|
evmAddresses: evmAddresses,
|
|
184
185
|
substrateAddresses: substrateAddresses
|
|
@@ -260,7 +261,7 @@ class InappNotificationService {
|
|
|
260
261
|
address: address,
|
|
261
262
|
// address is receiverAddress
|
|
262
263
|
title: _consts.NotificationTitleMap[actionType].replace('{{tokenSymbol}}', symbol),
|
|
263
|
-
description: _consts.NotificationDescriptionMap[actionType]((0,
|
|
264
|
+
description: _consts.NotificationDescriptionMap[actionType]((0, _utils3.formatNumber)(amount, decimals), symbol),
|
|
264
265
|
time: timestamp,
|
|
265
266
|
extrinsicType: _KoniTypes.ExtrinsicType.CLAIM_BRIDGE,
|
|
266
267
|
isRead: false,
|
|
@@ -334,7 +335,7 @@ class InappNotificationService {
|
|
|
334
335
|
id: `${actionType}___${_id}___${timestamp}`,
|
|
335
336
|
address: address,
|
|
336
337
|
title: _consts.NotificationTitleMap[actionType].replace('{{tokenSymbol}}', symbol),
|
|
337
|
-
description: _consts.NotificationDescriptionMap[actionType]((0,
|
|
338
|
+
description: _consts.NotificationDescriptionMap[actionType]((0, _utils3.formatNumber)(amounts[0], decimals), symbol),
|
|
338
339
|
time: timestamp,
|
|
339
340
|
extrinsicType: _KoniTypes.ExtrinsicType.CLAIM_BRIDGE,
|
|
340
341
|
isRead: false,
|
|
@@ -356,12 +357,17 @@ class InappNotificationService {
|
|
|
356
357
|
actionType = _interfaces.NotificationActionType.SWAP;
|
|
357
358
|
extrinsicType = _KoniTypes.ExtrinsicType.SWAP;
|
|
358
359
|
const combineInfo = process.combineInfo;
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
360
|
+
const targetPair = (() => {
|
|
361
|
+
try {
|
|
362
|
+
return (0, _utils2.getTokenPairFromStep)(combineInfo.process.steps) || combineInfo.quote.pair;
|
|
363
|
+
} catch (e) {
|
|
364
|
+
return combineInfo.quote.pair;
|
|
365
|
+
}
|
|
366
|
+
})();
|
|
367
|
+
const fromAsset = this.chainService.getAssetBySlug(targetPair.from);
|
|
368
|
+
const toAsset = this.chainService.getAssetBySlug(targetPair.to);
|
|
363
369
|
title = '[{{accountName}}] SWAPPED {{fromAsset}}'.replace('{{fromAsset}}', fromAsset.symbol);
|
|
364
|
-
description = '{{fromAmount}} {{fromAsset}}
|
|
370
|
+
description = '{{fromAmount}} {{fromAsset}} swapped for {{toAmount}} {{toAsset}}. Click to view details'.replace('{{fromAmount}}', (0, _utils3.formatNumber)(combineInfo.quote.fromAmount, fromAsset.decimals || 0)).replace('{{fromAsset}}', fromAsset.symbol).replace('{{toAmount}}', (0, _utils3.formatNumber)(combineInfo.quote.toAmount, toAsset.decimals || 0)).replace('{{toAsset}}', toAsset.symbol);
|
|
365
371
|
} else {
|
|
366
372
|
actionType = _interfaces.NotificationActionType.EARNING;
|
|
367
373
|
extrinsicType = _KoniTypes.ExtrinsicType.JOIN_YIELD_POOL; // Not used
|
|
@@ -395,11 +401,11 @@ class InappNotificationService {
|
|
|
395
401
|
break;
|
|
396
402
|
}
|
|
397
403
|
title = '[{{accountName}}] STAKED {{asset}}'.replace('{{asset}}', asset.symbol);
|
|
398
|
-
description = '{{amount}} {{asset}} on {{chain}} staked via {{method}}. Click to view details'.replace('{{amount}}', (0,
|
|
404
|
+
description = '{{amount}} {{asset}} on {{chain}} staked via {{method}}. Click to view details'.replace('{{amount}}', (0, _utils3.formatNumber)(amount, asset.decimals || 0)).replace('{{asset}}', asset.symbol).replace('{{chain}}', chain.name).replace('{{method}}', method);
|
|
399
405
|
}
|
|
400
406
|
const notification = {
|
|
401
407
|
id: `${actionType}___${_id}___${timestamp}`,
|
|
402
|
-
address: (0,
|
|
408
|
+
address: (0, _utils3.reformatAddress)(address),
|
|
403
409
|
title,
|
|
404
410
|
actionType,
|
|
405
411
|
metadata: {
|
|
@@ -156,7 +156,7 @@ class AccountLedgerHandler extends _Base.AccountBaseHandler {
|
|
|
156
156
|
}
|
|
157
157
|
if (Object.keys(slugMap).length) {
|
|
158
158
|
for (const chainSlug of Object.keys(slugMap)) {
|
|
159
|
-
this.state.
|
|
159
|
+
this.state.enableChainWithPriorityAssets(chainSlug);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
return true;
|
|
@@ -638,6 +638,9 @@ class AccountState {
|
|
|
638
638
|
enableChain(slug) {
|
|
639
639
|
this.koniState.enableChain(slug, true).catch(console.error);
|
|
640
640
|
}
|
|
641
|
+
enableChainWithPriorityAssets(slug) {
|
|
642
|
+
this.koniState.enableChainWithPriorityAssets(slug, true).catch(console.error);
|
|
643
|
+
}
|
|
641
644
|
|
|
642
645
|
/* Others */
|
|
643
646
|
|
|
@@ -0,0 +1,60 @@
|
|
|
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 _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
9
|
+
var _Base = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/Base"));
|
|
10
|
+
var _utils2 = require("@subwallet/extension-base/utils");
|
|
11
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
12
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
13
|
+
|
|
14
|
+
// Usage:
|
|
15
|
+
// 1. Disable tokens with a balance of 0
|
|
16
|
+
// 2. Exclude tokens that belong to the popular list
|
|
17
|
+
// 3. Exclude tokens with the "auto enable" attribute
|
|
18
|
+
|
|
19
|
+
class DisableZeroBalanceTokens extends _Base.default {
|
|
20
|
+
async run() {
|
|
21
|
+
const state = this.state;
|
|
22
|
+
try {
|
|
23
|
+
const rawBalanceMap = await state.dbService.getStoredBalance();
|
|
24
|
+
const tokensList = await state.chainService.getAssetSettings();
|
|
25
|
+
const filteredEnabledTokens = Object.entries(tokensList).reduce((acc, _ref) => {
|
|
26
|
+
let [key, value] = _ref;
|
|
27
|
+
if (value.visible) {
|
|
28
|
+
acc[key] = value;
|
|
29
|
+
}
|
|
30
|
+
return acc;
|
|
31
|
+
}, {});
|
|
32
|
+
const balanceNonZero = rawBalanceMap.filter(item => {
|
|
33
|
+
return BigInt(item.free) + BigInt(item.locked) > 0;
|
|
34
|
+
});
|
|
35
|
+
const priorityTokensMap = (await (0, _utils2.fetchStaticData)('chain-assets/priority-tokens')) || {
|
|
36
|
+
tokenGroup: {},
|
|
37
|
+
token: {}
|
|
38
|
+
};
|
|
39
|
+
const priorityTokensList = priorityTokensMap.token && typeof priorityTokensMap.token === 'object' ? Object.keys(priorityTokensMap.token) : [];
|
|
40
|
+
const autoEnableTokenSlugs = Object.values(this.state.chainService.getAssetRegistry()).filter(asset => (0, _utils._isAssetAutoEnable)(asset)).map(asset => asset.slug);
|
|
41
|
+
// Extract the slugs of tokens with balance > 0
|
|
42
|
+
const nonZeroBalanceSlugs = new Set(balanceNonZero.map(item => item.tokenSlug));
|
|
43
|
+
const updatedSettings = structuredClone(tokensList);
|
|
44
|
+
Object.keys(filteredEnabledTokens).forEach(slug => {
|
|
45
|
+
const hasBalance = nonZeroBalanceSlugs.has(slug);
|
|
46
|
+
const isPopularToken = priorityTokensList.includes(slug);
|
|
47
|
+
const isAutoEnableToken = autoEnableTokenSlugs.includes(slug);
|
|
48
|
+
if (!hasBalance && !isPopularToken && !isAutoEnableToken) {
|
|
49
|
+
updatedSettings[slug] = {
|
|
50
|
+
visible: false
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
state.chainService.setAssetSettings(updatedSettings);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.default = DisableZeroBalanceTokens;
|
|
@@ -12,7 +12,7 @@ var _Base = _interopRequireDefault(require("@subwallet/extension-base/services/m
|
|
|
12
12
|
class EnableChain extends _Base.default {
|
|
13
13
|
async run() {
|
|
14
14
|
const state = this.state;
|
|
15
|
-
await state.
|
|
15
|
+
await state.enableChainWithPriorityAssets(this.slug, true);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.default = EnableChain;
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = exports.MYTHOS_MIGRATION_KEY = exports.EVERYTIME = void 0;
|
|
8
|
-
var _AutoEnableSomeTokens = _interopRequireDefault(require("./databases/AutoEnableSomeTokens"));
|
|
9
8
|
var _ClearMetadataDatabase = _interopRequireDefault(require("./databases/ClearMetadataDatabase"));
|
|
10
9
|
var _ClearMetadataForMythos = _interopRequireDefault(require("./databases/ClearMetadataForMythos"));
|
|
11
10
|
var _MigrateAssetSetting = _interopRequireDefault(require("./databases/MigrateAssetSetting"));
|
|
@@ -22,6 +21,7 @@ var _MigratePolygonUSDCProvider = _interopRequireDefault(require("./tokens/Migra
|
|
|
22
21
|
var _DeleteChain = _interopRequireDefault(require("./DeleteChain"));
|
|
23
22
|
var _DeleteChainStaking = _interopRequireDefault(require("./DeleteChainStaking"));
|
|
24
23
|
var _DeleteEarningData = _interopRequireDefault(require("./DeleteEarningData"));
|
|
24
|
+
var _DisableZeroBalanceTokens = _interopRequireDefault(require("./DisableZeroBalanceTokens"));
|
|
25
25
|
var _EnableVaraChain = _interopRequireDefault(require("./EnableVaraChain"));
|
|
26
26
|
var _MigrateAuthUrls = _interopRequireDefault(require("./MigrateAuthUrls"));
|
|
27
27
|
var _MigrateImportedToken = _interopRequireDefault(require("./MigrateImportedToken"));
|
|
@@ -61,7 +61,7 @@ var _default = {
|
|
|
61
61
|
'1.1.28-01': _MigrateEarningVersion.default,
|
|
62
62
|
'1.1.33-01': _MigrateLedgerAccountV.default,
|
|
63
63
|
'1.1.41-01': _DeleteChainStaking.default,
|
|
64
|
-
'1.1.46-01':
|
|
64
|
+
// '1.1.46-01': AutoEnableSomeTokens,
|
|
65
65
|
'1.2.28-01': _MigrateAssetSetting.default,
|
|
66
66
|
'1.2.28-02': _MigrateTransactionHistoryBySymbol.default,
|
|
67
67
|
'1.2.69-01': _MigrateRemoveGenesisHash.default,
|
|
@@ -69,6 +69,7 @@ var _default = {
|
|
|
69
69
|
'1.2.32-01': _MigratePairData.default,
|
|
70
70
|
'1.3.6-01': _MigrateTransactionHistoryBridge.default,
|
|
71
71
|
'1.3.10-01': _ClearMetadataDatabase.default,
|
|
72
|
+
'1.3.26-01': _DisableZeroBalanceTokens.default,
|
|
72
73
|
[MYTHOS_MIGRATION_KEY]: _ClearMetadataForMythos.default
|
|
73
74
|
// [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
|
|
74
75
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|