@subwallet/extension-base 1.3.29-1 → 1.3.30-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.
Files changed (80) hide show
  1. package/background/KoniTypes.d.ts +4 -4
  2. package/background/errors/SwapError.js +1 -1
  3. package/cjs/background/errors/SwapError.js +1 -1
  4. package/cjs/constants/blocked-actions.js +2 -2
  5. package/cjs/constants/remind-notification-time.js +3 -3
  6. package/cjs/core/logic-validation/swap.js +63 -4
  7. package/cjs/core/utils.js +1 -1
  8. package/cjs/koni/background/handlers/Extension.js +5 -82
  9. package/cjs/packageInfo.js +1 -1
  10. package/cjs/services/balance-service/transfer/xcm/availBridge.js +6 -6
  11. package/cjs/services/earning-service/handlers/base.js +6 -3
  12. package/cjs/services/earning-service/handlers/native-staking/base.js +4 -1
  13. package/cjs/services/earning-service/handlers/native-staking/dtao.js +68 -50
  14. package/cjs/services/earning-service/handlers/native-staking/tao.js +12 -2
  15. package/cjs/services/earning-service/service.js +2 -1
  16. package/cjs/services/fee-service/utils/index.js +16 -4
  17. package/cjs/services/inapp-notification-service/index.js +19 -13
  18. package/cjs/services/swap-service/handler/asset-hub/handler.js +61 -314
  19. package/cjs/services/swap-service/handler/base-handler.js +393 -231
  20. package/cjs/services/swap-service/handler/chainflip-handler.js +18 -40
  21. package/cjs/services/swap-service/handler/hydradx-handler.js +77 -269
  22. package/cjs/services/swap-service/handler/simpleswap-handler.js +27 -48
  23. package/cjs/services/swap-service/handler/uniswap-handler.js +33 -54
  24. package/cjs/services/swap-service/index.js +154 -143
  25. package/cjs/services/swap-service/utils.js +107 -17
  26. package/cjs/services/transaction-service/index.js +1 -1
  27. package/cjs/types/swap/index.js +13 -1
  28. package/cjs/utils/swap.js +5 -1
  29. package/constants/blocked-actions.d.ts +1 -1
  30. package/constants/blocked-actions.js +1 -1
  31. package/constants/remind-notification-time.d.ts +1 -1
  32. package/constants/remind-notification-time.js +1 -1
  33. package/core/logic-validation/swap.d.ts +15 -0
  34. package/core/logic-validation/swap.js +60 -4
  35. package/core/utils.js +1 -1
  36. package/koni/background/handlers/Extension.d.ts +0 -1
  37. package/koni/background/handlers/Extension.js +6 -83
  38. package/package.json +6 -12
  39. package/packageInfo.js +1 -1
  40. package/services/balance-service/transfer/xcm/availBridge.js +6 -6
  41. package/services/base/types.d.ts +0 -4
  42. package/services/earning-service/handlers/base.d.ts +4 -3
  43. package/services/earning-service/handlers/base.js +6 -4
  44. package/services/earning-service/handlers/native-staking/base.js +4 -1
  45. package/services/earning-service/handlers/native-staking/dtao.d.ts +9 -6
  46. package/services/earning-service/handlers/native-staking/dtao.js +69 -48
  47. package/services/earning-service/handlers/native-staking/tao.js +12 -2
  48. package/services/earning-service/service.d.ts +2 -1
  49. package/services/earning-service/service.js +2 -1
  50. package/services/fee-service/utils/index.d.ts +1 -0
  51. package/services/fee-service/utils/index.js +14 -4
  52. package/services/inapp-notification-service/index.js +13 -7
  53. package/services/swap-service/handler/asset-hub/handler.d.ts +2 -9
  54. package/services/swap-service/handler/asset-hub/handler.js +64 -317
  55. package/services/swap-service/handler/base-handler.d.ts +6 -9
  56. package/services/swap-service/handler/base-handler.js +391 -229
  57. package/services/swap-service/handler/chainflip-handler.d.ts +2 -4
  58. package/services/swap-service/handler/chainflip-handler.js +15 -37
  59. package/services/swap-service/handler/hydradx-handler.d.ts +3 -10
  60. package/services/swap-service/handler/hydradx-handler.js +78 -270
  61. package/services/swap-service/handler/simpleswap-handler.d.ts +2 -4
  62. package/services/swap-service/handler/simpleswap-handler.js +24 -45
  63. package/services/swap-service/handler/uniswap-handler.d.ts +4 -6
  64. package/services/swap-service/handler/uniswap-handler.js +25 -46
  65. package/services/swap-service/index.d.ts +8 -14
  66. package/services/swap-service/index.js +141 -129
  67. package/services/swap-service/utils.d.ts +11 -3
  68. package/services/swap-service/utils.js +96 -15
  69. package/services/transaction-service/index.js +2 -2
  70. package/types/service-base.d.ts +2 -3
  71. package/types/swap/index.d.ts +25 -9
  72. package/types/swap/index.js +10 -0
  73. package/types/transaction/process.d.ts +19 -0
  74. package/types/yield/actions/join/submit.d.ts +4 -1
  75. package/types/yield/actions/others.d.ts +2 -0
  76. package/utils/swap.d.ts +3 -0
  77. package/utils/swap.js +3 -0
  78. package/cjs/services/swap-service/interface.js +0 -14
  79. package/services/swap-service/interface.d.ts +0 -9
  80. 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.getAlphaToTaoMapping = exports.default = exports.DEFAULT_DTAO_MINBOND = void 0;
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 = _interopRequireWildcard(require("bignumber.js"));
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
- return allSubnets.reduce((acc, subnet) => {
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
- if (netuid === 0) {
39
- acc[netuid] = '1';
40
- } else if (alphaIn.gt(0)) {
41
- acc[netuid] = taoIn.dividedBy(alphaIn).toString();
42
- } else {
43
- acc[netuid] = '1';
44
- }
45
- return acc;
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.BigNumber((subnetInfo === null || subnetInfo === void 0 ? void 0 : subnetInfo.alphaIn) || 0);
88
- const taoIn = new _bignumber.BigNumber((subnetInfo === null || subnetInfo === void 0 ? void 0 : subnetInfo.taoIn) || 0);
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.BigNumber(params.value);
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 slippage.toNumber();
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 slippage.toNumber();
112
+ return {
113
+ slippage: slippage.plus(0.0001).toNumber(),
114
+ rate: rate.toNumber()
115
+ };
105
116
  }
106
- return 0;
117
+ return {
118
+ slippage: 0,
119
+ rate: 1
120
+ };
107
121
  }
108
122
  get maintainBalance() {
109
- const ed = new _util.BN(this.nativeToken.minAmount || '0');
110
- const calculateMaintainBalance = new _util.BN(15).mul(ed).div(_util.BN_TEN);
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 _util.BN(subnet.taoIn);
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 _util.BN(DEFAULT_DTAO_MINBOND);
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 _util.BN(DEFAULT_DTAO_MINBOND);
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 _util.BN(validatorList[i].stake);
391
- const bnOwnStake = new _util.BN(validatorList[i].validator_stake);
392
- const otherStake = bnTotalStake.sub(bnOwnStake);
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
- netuid,
435
- selectedValidators: targetValidators
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 _util.BN(amount);
439
- const price = await getAlphaToTaoMapping(this.substrateApi);
440
- const alphaToTaoPrice = new _bignumber.default(price[netuid]);
441
- const limitPrice = alphaToTaoPrice.multipliedBy(10 ** (0, _utils2._getAssetDecimals)(this.nativeToken)).multipliedBy(1 + DEFAULT_BITTENSOR_SLIPPAGE);
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 _util.BN(amount).lt(new _util.BN(DEFAULT_DTAO_MINBOND))) {
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 price = await getAlphaToTaoMapping(this.substrateApi);
493
- const minUnstake = new _bignumber.default(DEFAULT_DTAO_MINBOND).dividedBy(new _bignumber.default(price[netuid]));
494
- console.log('minUnstake', minUnstake.dividedBy(10 ** (0, _utils2._getAssetDecimals)(this.nativeToken)).toString());
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=200', {
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);
@@ -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 _utils2 = require("@subwallet/extension-base/utils");
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.fetchLastestRemindNotificationTime)()]);
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, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.EVM]);
181
- const substrateAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.SUBSTRATE]);
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, _utils2.formatNumber)(amount, decimals), symbol),
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, _utils2.formatNumber)(amounts[0], decimals), symbol),
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 fromAsset = this.chainService.getAssetBySlug(combineInfo.quote.pair.from);
360
- const toAsset = this.chainService.getAssetBySlug(combineInfo.quote.pair.to);
361
- const fromChain = this.chainService.getChainInfoByKey(fromAsset.originChain);
362
- const toChain = this.chainService.getChainInfoByKey(toAsset.originChain);
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}} on {{fromChain}} swapped for {{toAmount}} {{toAsset}} on {{toChain}}. Click to view details'.replace('{{fromAmount}}', (0, _utils2.formatNumber)(combineInfo.quote.fromAmount, fromAsset.decimals || 0)).replace('{{fromAsset}}', fromAsset.symbol).replace('{{fromChain}}', fromChain.name).replace('{{toAmount}}', (0, _utils2.formatNumber)(combineInfo.quote.toAmount, toAsset.decimals || 0)).replace('{{toAsset}}', toAsset.symbol).replace('{{toChain}}', toChain.name);
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, _utils2.formatNumber)(amount, asset.decimals || 0)).replace('{{asset}}', asset.symbol).replace('{{chain}}', chain.name).replace('{{method}}', method);
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, _utils2.reformatAddress)(address),
408
+ address: (0, _utils3.reformatAddress)(address),
403
409
  title,
404
410
  actionType,
405
411
  metadata: {