@subwallet/extension-base 1.1.35-beta.2 → 1.1.36-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 (89) hide show
  1. package/background/KoniTypes.d.ts +12 -0
  2. package/background/KoniTypes.js +3 -0
  3. package/cjs/background/KoniTypes.js +3 -0
  4. package/cjs/koni/api/nft/config.js +11 -6
  5. package/cjs/koni/api/nft/index.js +4 -2
  6. package/cjs/koni/api/nft/transfer.js +7 -19
  7. package/cjs/koni/api/nft/unique_network_nft/index.js +154 -0
  8. package/cjs/koni/api/staking/bonding/utils.js +44 -0
  9. package/cjs/koni/api/tokens/evm/transfer.js +35 -19
  10. package/cjs/koni/api/yield/helper/utils.js +6 -3
  11. package/cjs/koni/background/handlers/Extension.js +20 -12
  12. package/cjs/koni/background/handlers/State.js +15 -5
  13. package/cjs/packageInfo.js +1 -1
  14. package/cjs/services/balance-service/index.js +1 -1
  15. package/cjs/services/chain-service/constants.js +1 -1
  16. package/cjs/services/chain-service/index.js +3 -5
  17. package/cjs/services/earning-service/handlers/liquid-staking/base.js +2 -1
  18. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +2 -1
  19. package/cjs/services/earning-service/handlers/liquid-staking/index.js +7 -0
  20. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
  21. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +10 -2
  22. package/cjs/services/earning-service/handlers/nomination-pool/index.js +10 -2
  23. package/cjs/services/earning-service/handlers/special.js +7 -3
  24. package/cjs/services/earning-service/service.js +38 -14
  25. package/cjs/services/notification-service/NotificationService.js +7 -4
  26. package/cjs/services/request-service/handler/EvmRequestHandler.js +46 -29
  27. package/cjs/services/transaction-service/constants.js +1 -1
  28. package/cjs/services/transaction-service/index.js +44 -15
  29. package/cjs/signers/web3/QrSigner.js +2 -0
  30. package/cjs/types/yield/actions/join/step.js +1 -0
  31. package/cjs/utils/eth/mergeTransactionAndSignature.js +25 -10
  32. package/cjs/utils/eth.js +60 -2
  33. package/cjs/utils/number.js +5 -1
  34. package/koni/api/nft/config.d.ts +3 -2
  35. package/koni/api/nft/config.js +8 -3
  36. package/koni/api/nft/index.js +3 -2
  37. package/koni/api/nft/transfer.d.ts +0 -1
  38. package/koni/api/nft/transfer.js +7 -18
  39. package/koni/api/nft/unique_network_nft/index.d.ts +9 -0
  40. package/koni/api/nft/unique_network_nft/index.js +146 -0
  41. package/koni/api/staking/bonding/utils.d.ts +5 -0
  42. package/koni/api/staking/bonding/utils.js +40 -0
  43. package/koni/api/tokens/evm/transfer.js +36 -21
  44. package/koni/api/yield/helper/utils.d.ts +1 -1
  45. package/koni/api/yield/helper/utils.js +5 -3
  46. package/koni/background/handlers/Extension.js +21 -13
  47. package/koni/background/handlers/State.js +16 -6
  48. package/package.json +21 -12
  49. package/packageInfo.js +1 -1
  50. package/services/balance-service/index.js +1 -1
  51. package/services/chain-service/constants.js +1 -1
  52. package/services/chain-service/index.js +4 -6
  53. package/services/earning-service/handlers/liquid-staking/base.d.ts +1 -1
  54. package/services/earning-service/handlers/liquid-staking/base.js +2 -1
  55. package/services/earning-service/handlers/liquid-staking/bifrost-manta.d.ts +37 -0
  56. package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +132 -0
  57. package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +3 -3
  58. package/services/earning-service/handlers/liquid-staking/bifrost.js +2 -1
  59. package/services/earning-service/handlers/liquid-staking/index.d.ts +1 -0
  60. package/services/earning-service/handlers/liquid-staking/index.js +1 -0
  61. package/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
  62. package/services/earning-service/handlers/native-staking/relay-chain.js +11 -3
  63. package/services/earning-service/handlers/nomination-pool/index.js +11 -3
  64. package/services/earning-service/handlers/special.js +7 -3
  65. package/services/earning-service/service.d.ts +4 -2
  66. package/services/earning-service/service.js +40 -16
  67. package/services/notification-service/NotificationService.js +7 -4
  68. package/services/request-service/handler/EvmRequestHandler.d.ts +2 -2
  69. package/services/request-service/handler/EvmRequestHandler.js +46 -29
  70. package/services/transaction-service/constants.js +1 -1
  71. package/services/transaction-service/index.js +45 -16
  72. package/services/transaction-service/types.d.ts +2 -2
  73. package/signers/types.d.ts +2 -0
  74. package/signers/web3/QrSigner.js +2 -0
  75. package/types/yield/actions/join/step.d.ts +1 -0
  76. package/types/yield/actions/join/step.js +1 -0
  77. package/utils/eth/mergeTransactionAndSignature.js +25 -10
  78. package/utils/eth.d.ts +14 -0
  79. package/utils/eth.js +57 -0
  80. package/utils/number.d.ts +2 -0
  81. package/utils/number.js +2 -0
  82. package/cjs/koni/api/dotsama/balance.js +0 -464
  83. package/cjs/services/migration-service/scripts/MigrateEthProvider.js +0 -17
  84. package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +0 -17
  85. package/cjs/services/migration-service/scripts/MigrateProvider.js +0 -29
  86. package/cjs/services/storage-service/index.js +0 -241
  87. package/cjs/types.js +0 -1
  88. package/cjs/utils/address.js +0 -34
  89. package/cjs/utils/keyring.js +0 -57
@@ -22,6 +22,7 @@ var _utils3 = require("@subwallet/extension-base/utils");
22
22
  var _eth = require("@subwallet/extension-base/utils/eth");
23
23
  var _mergeTransactionAndSignature = require("@subwallet/extension-base/utils/eth/mergeTransactionAndSignature");
24
24
  var _parseTransaction = require("@subwallet/extension-base/utils/eth/parseTransaction");
25
+ var _number = require("@subwallet/extension-base/utils/number");
25
26
  var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
26
27
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
27
28
  var _ethereumjsUtil = require("ethereumjs-util");
@@ -100,7 +101,8 @@ class TransactionService {
100
101
  const estimateFee = {
101
102
  symbol: '',
102
103
  decimals: 0,
103
- value: ''
104
+ value: '',
105
+ tooHigh: false
104
106
  };
105
107
  const chainInfo = this.state.chainService.getChainInfoByKey(chain);
106
108
  if (!chainInfo) {
@@ -121,10 +123,16 @@ class TransactionService {
121
123
  if (!web3) {
122
124
  validationResponse.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
123
125
  } else {
124
- const _price = await web3.api.eth.getGasPrice();
125
- const gasPrice = (0, _eth.recalculateGasPrice)(_price, chainInfo.slug);
126
126
  const gasLimit = await web3.api.eth.estimateGas(transaction);
127
- estimateFee.value = (gasLimit * parseInt(gasPrice)).toString();
127
+ const priority = await (0, _eth.calculateGasFeeParams)(web3, chainInfo.slug);
128
+ if (priority.baseGasFee) {
129
+ const priorityFee = priority.baseGasFee.plus(priority.maxPriorityFeePerGas);
130
+ const maxFee = priority.maxFeePerGas.lte(priorityFee) ? priority.maxFeePerGas : priorityFee;
131
+ estimateFee.value = maxFee.multipliedBy(gasLimit).toFixed(0);
132
+ } else {
133
+ estimateFee.value = new _bignumber.default(priority.gasPrice).multipliedBy(gasLimit).toFixed(0);
134
+ }
135
+ estimateFee.tooHigh = priority.busyNetwork;
128
136
  }
129
137
  }
130
138
  } catch (e) {
@@ -529,6 +537,7 @@ class TransactionService {
529
537
  case _KoniTypes.ExtrinsicType.MINT_QDOT:
530
538
  case _KoniTypes.ExtrinsicType.MINT_LDOT:
531
539
  case _KoniTypes.ExtrinsicType.MINT_SDOT:
540
+ case _KoniTypes.ExtrinsicType.MINT_VMANTA:
532
541
 
533
542
  // eslint-disable-next-line no-fallthrough
534
543
  case _KoniTypes.ExtrinsicType.MINT_VDOT:
@@ -582,12 +591,14 @@ class TransactionService {
582
591
  break;
583
592
  }
584
593
  case _KoniTypes.ExtrinsicType.UNSTAKE_VDOT:
594
+ case _KoniTypes.ExtrinsicType.UNSTAKE_VMANTA:
585
595
  case _KoniTypes.ExtrinsicType.UNSTAKE_LDOT:
586
596
  case _KoniTypes.ExtrinsicType.UNSTAKE_SDOT:
587
597
  case _KoniTypes.ExtrinsicType.UNSTAKE_STDOT:
588
598
  case _KoniTypes.ExtrinsicType.REDEEM_STDOT:
589
599
  case _KoniTypes.ExtrinsicType.REDEEM_LDOT:
590
600
  case _KoniTypes.ExtrinsicType.REDEEM_SDOT:
601
+ case _KoniTypes.ExtrinsicType.REDEEM_VMANTA:
591
602
 
592
603
  // eslint-disable-next-line no-fallthrough
593
604
  case _KoniTypes.ExtrinsicType.REDEEM_VDOT:
@@ -703,7 +714,7 @@ class TransactionService {
703
714
  this.state.historyService.updateHistoryByExtrinsicHash(id, updateData).catch(console.error);
704
715
  console.debug(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
705
716
  const transaction = this.getTransaction(id);
706
- if ([_KoniTypes.ExtrinsicType.STAKING_JOIN_POOL, _KoniTypes.ExtrinsicType.JOIN_YIELD_POOL, _KoniTypes.ExtrinsicType.MINT_LDOT, _KoniTypes.ExtrinsicType.MINT_QDOT, _KoniTypes.ExtrinsicType.MINT_SDOT, _KoniTypes.ExtrinsicType.MINT_VDOT].includes(transaction.extrinsicType)) {
717
+ if ([_KoniTypes.ExtrinsicType.STAKING_JOIN_POOL, _KoniTypes.ExtrinsicType.STAKING_BOND, _KoniTypes.ExtrinsicType.JOIN_YIELD_POOL, _KoniTypes.ExtrinsicType.MINT_LDOT, _KoniTypes.ExtrinsicType.MINT_QDOT, _KoniTypes.ExtrinsicType.MINT_SDOT, _KoniTypes.ExtrinsicType.MINT_STDOT, _KoniTypes.ExtrinsicType.MINT_VDOT, _KoniTypes.ExtrinsicType.MINT_VMANTA].includes(transaction.extrinsicType)) {
707
718
  this.handlePostEarningTransaction(id);
708
719
  }
709
720
  }
@@ -850,17 +861,33 @@ class TransactionService {
850
861
  this.eventService.emit('transaction.timeout', transaction);
851
862
  }
852
863
  generateHashPayload(chain, transaction) {
853
- var _transaction$nonce;
854
864
  const chainInfo = this.state.chainService.getChainInfoByKey(chain);
855
- const txObject = {
856
- nonce: (_transaction$nonce = transaction.nonce) !== null && _transaction$nonce !== void 0 ? _transaction$nonce : 0,
857
- gasPrice: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.gasPrice).toString(16)),
858
- gasLimit: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.gas).toString(16)),
859
- to: transaction.to !== undefined ? transaction.to : '',
860
- value: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.value).toString(16)),
861
- data: transaction.data,
862
- chainId: (0, _utils._getEvmChainId)(chainInfo)
863
- };
865
+ let txObject;
866
+ const max = (0, _eth.anyNumberToBN)(transaction.maxFeePerGas);
867
+ if (max.gt(_number.BN_ZERO)) {
868
+ var _transaction$nonce;
869
+ txObject = {
870
+ nonce: (_transaction$nonce = transaction.nonce) !== null && _transaction$nonce !== void 0 ? _transaction$nonce : 0,
871
+ maxFeePerGas: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.maxFeePerGas).toString(16)),
872
+ maxPriorityFeePerGas: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.maxPriorityFeePerGas).toString(16)),
873
+ gasLimit: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.gas).toString(16)),
874
+ to: transaction.to !== undefined ? transaction.to : '',
875
+ value: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.value).toString(16)),
876
+ data: transaction.data,
877
+ chainId: (0, _utils._getEvmChainId)(chainInfo)
878
+ };
879
+ } else {
880
+ var _transaction$nonce2;
881
+ txObject = {
882
+ nonce: (_transaction$nonce2 = transaction.nonce) !== null && _transaction$nonce2 !== void 0 ? _transaction$nonce2 : 0,
883
+ gasPrice: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.gasPrice).toString(16)),
884
+ gasLimit: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.gas).toString(16)),
885
+ to: transaction.to !== undefined ? transaction.to : '',
886
+ value: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.value).toString(16)),
887
+ data: transaction.data,
888
+ chainId: (0, _utils._getEvmChainId)(chainInfo)
889
+ };
890
+ }
864
891
  return _ethers.ethers.Transaction.from(txObject).unsignedSerialized;
865
892
  }
866
893
  async signAndSendEvmTransaction(_ref7) {
@@ -926,6 +953,8 @@ class TransactionService {
926
953
  nonce: (_payload$nonce = payload.nonce) !== null && _payload$nonce !== void 0 ? _payload$nonce : 0,
927
954
  from: payload.from,
928
955
  gasPrice: (0, _eth.anyNumberToBN)(payload.gasPrice).toNumber(),
956
+ maxFeePerGas: (0, _eth.anyNumberToBN)(payload.maxFeePerGas).toNumber(),
957
+ maxPriorityFeePerGas: (0, _eth.anyNumberToBN)(payload.maxPriorityFeePerGas).toNumber(),
929
958
  gasLimit: (0, _eth.anyNumberToBN)(payload.gas).toNumber(),
930
959
  to: payload.to !== undefined ? payload.to : '',
931
960
  value: (0, _eth.anyNumberToBN)(payload.value).toNumber(),
@@ -33,6 +33,8 @@ class QrSigner {
33
33
  const txObject = {
34
34
  nonce: (_tx$nonce = tx.nonce) !== null && _tx$nonce !== void 0 ? _tx$nonce : 0,
35
35
  gasPrice: (0, _ethereumjsUtil.addHexPrefix)(tx.gasPrice.toString(16)),
36
+ maxPriorityFeePerGas: (0, _ethereumjsUtil.addHexPrefix)(tx.maxPriorityFeePerGas.toString(16)),
37
+ maxFeePerGas: (0, _ethereumjsUtil.addHexPrefix)(tx.maxFeePerGas.toString(16)),
36
38
  gasLimit: (0, _ethereumjsUtil.addHexPrefix)(tx.gasLimit.toString(16)),
37
39
  to: tx.to !== undefined ? tx.to : '',
38
40
  value: (0, _ethereumjsUtil.addHexPrefix)(tx.value.toString(16)),
@@ -39,6 +39,7 @@ exports.YieldStepType = YieldStepType;
39
39
  YieldStepType["NOMINATE"] = "NOMINATE";
40
40
  YieldStepType["JOIN_NOMINATION_POOL"] = "JOIN_NOMINATION_POOL";
41
41
  YieldStepType["MINT_VDOT"] = "MINT_VDOT";
42
+ YieldStepType["MINT_VMANTA"] = "MINT_VMANTA";
42
43
  YieldStepType["MINT_LDOT"] = "MINT_LDOT";
43
44
  YieldStepType["MINT_QDOT"] = "MINT_QDOT";
44
45
  YieldStepType["MINT_SDOT"] = "MINT_SDOT";
@@ -16,16 +16,31 @@ const mergeTransactionAndSignature = (tx, _rawSignature) => {
16
16
  s: `0x${_signature.substring(64, 128)}`,
17
17
  v: parseInt(`0x${_signature.substring(128)}`)
18
18
  };
19
- const transaction = {
20
- nonce: tx.nonce,
21
- gasPrice: (0, _ethereumjsUtil.addHexPrefix)(tx.gasPrice.toString(16)),
22
- gasLimit: (0, _ethereumjsUtil.addHexPrefix)(tx.gasLimit.toString(16)),
23
- to: tx.to,
24
- value: (0, _ethereumjsUtil.addHexPrefix)(tx.value.toString(16)),
25
- data: tx.data,
26
- chainId: tx.chainId,
27
- signature: signature
28
- };
19
+ let transaction;
20
+ if (tx.maxFeePerGas) {
21
+ transaction = {
22
+ nonce: tx.nonce,
23
+ maxFeePerGas: (0, _ethereumjsUtil.addHexPrefix)(tx.maxFeePerGas.toString(16)),
24
+ maxPriorityFeePerGas: (0, _ethereumjsUtil.addHexPrefix)(tx.maxPriorityFeePerGas.toString(16)),
25
+ gasLimit: (0, _ethereumjsUtil.addHexPrefix)(tx.gasLimit.toString(16)),
26
+ to: tx.to,
27
+ value: (0, _ethereumjsUtil.addHexPrefix)(tx.value.toString(16)),
28
+ data: tx.data,
29
+ chainId: tx.chainId,
30
+ signature: signature
31
+ };
32
+ } else {
33
+ transaction = {
34
+ nonce: tx.nonce,
35
+ gasPrice: (0, _ethereumjsUtil.addHexPrefix)(tx.gasPrice.toString(16)),
36
+ gasLimit: (0, _ethereumjsUtil.addHexPrefix)(tx.gasLimit.toString(16)),
37
+ to: tx.to,
38
+ value: (0, _ethereumjsUtil.addHexPrefix)(tx.value.toString(16)),
39
+ data: tx.data,
40
+ chainId: tx.chainId,
41
+ signature: signature
42
+ };
43
+ }
29
44
  return _ethers.ethers.Transaction.from(transaction).serialized;
30
45
  };
31
46
  exports.mergeTransactionAndSignature = mergeTransactionAndSignature;
package/cjs/utils/eth.js CHANGED
@@ -4,11 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.signatureToHex = exports.recalculateGasPrice = exports.createTransactionFromRLP = exports.anyNumberToBN = exports.Transaction = void 0;
7
+ exports.signatureToHex = exports.recalculateGasPrice = exports.createTransactionFromRLP = exports.calculateGasFeeParams = exports.anyNumberToBN = exports.Transaction = void 0;
8
8
  var _constants = require("@subwallet/extension-base/constants");
9
9
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
10
10
  var _ethers = require("ethers");
11
11
  var _util = require("@polkadot/util");
12
+ var _number = require("./number");
12
13
  // Copyright 2019-2022 @subwallet/extension-base
13
14
  // SPDX-License-Identifier: Apache-2.0
14
15
 
@@ -75,4 +76,61 @@ const recalculateGasPrice = (_price, chain) => {
75
76
  const needMulti = _constants.NETWORK_MULTI_GAS_FEE.includes(chain) || _constants.NETWORK_MULTI_GAS_FEE.includes('*');
76
77
  return needMulti ? new _bignumber.default(_price).multipliedBy(_constants.GAS_PRICE_RATIO).toFixed(0) : _price;
77
78
  };
78
- exports.recalculateGasPrice = recalculateGasPrice;
79
+ exports.recalculateGasPrice = recalculateGasPrice;
80
+ const calculateGasFeeParams = async (web3, networkKey) => {
81
+ try {
82
+ const numBlock = 20;
83
+ const history = await web3.api.eth.getFeeHistory(numBlock, 'latest', [0, 25, 50, 75, 100]);
84
+ const baseGasFee = new _bignumber.default(history.baseFeePerGas[history.baseFeePerGas.length - 1]); // Last element is latest
85
+
86
+ const blocksBusy = history.reward.reduce((previous, rewards, currentIndex) => {
87
+ const [priority] = rewards;
88
+ const base = history.baseFeePerGas[currentIndex];
89
+ const priorityBN = new _bignumber.default(priority);
90
+ const baseBN = new _bignumber.default(base);
91
+ const blockIsBusy = priorityBN.dividedBy(baseBN).gte(0.3) ? 1 : 0; // True if priority >= 0.5 * base
92
+
93
+ return previous + blockIsBusy;
94
+ }, 0);
95
+ const busyNetwork = blocksBusy >= numBlock / 2; // True if half of block is busy
96
+
97
+ const maxPriorityFeePerGas = history.reward.reduce((previous, rewards, currentIndex) => {
98
+ const [first, second] = rewards;
99
+ const base = history.baseFeePerGas[currentIndex];
100
+ const firstBN = new _bignumber.default(first);
101
+ const secondBN = new _bignumber.default(second);
102
+ const baseBN = new _bignumber.default(base);
103
+
104
+ // Special for bsc, base and first always 0
105
+ if (baseBN.eq(_number.BN_ZERO) && firstBN.eq(_number.BN_ZERO)) {
106
+ const current = secondBN;
107
+ return current.gte(previous) ? current : previous; // get min priority
108
+ }
109
+
110
+ if (busyNetwork) {
111
+ const current = secondBN.dividedBy(2).gte(firstBN) ? firstBN : secondBN; // second too larger than first (> 2 times), use first else use second
112
+
113
+ return current.gte(previous) ? current : previous; // get max priority
114
+ } else {
115
+ const current = firstBN;
116
+ return current.lte(previous) ? current : previous; // get min priority
117
+ }
118
+ }, _number.BN_ZERO);
119
+ const maxFeePerGas = baseGasFee.plus(maxPriorityFeePerGas).multipliedBy(busyNetwork ? 2 : 1.5).decimalPlaces(0); // Max gas =(base + priority) * 1.5(if not busy or 2 when busy);
120
+
121
+ return {
122
+ maxFeePerGas,
123
+ maxPriorityFeePerGas,
124
+ baseGasFee,
125
+ busyNetwork
126
+ };
127
+ } catch (e) {
128
+ const _price = await web3.api.eth.getGasPrice();
129
+ const gasPrice = recalculateGasPrice(_price, networkKey);
130
+ return {
131
+ gasPrice,
132
+ busyNetwork: false
133
+ };
134
+ }
135
+ };
136
+ exports.calculateGasFeeParams = calculateGasFeeParams;
@@ -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.toBNString = exports.formatNumber = exports.balanceFormatter = exports.PREDEFINED_FORMATTER = exports.BN_ZERO = exports.BN_TEN = void 0;
7
+ exports.toBNString = exports.formatNumber = exports.balanceFormatter = exports.PREDEFINED_FORMATTER = exports.BN_ZERO = exports.BN_WEI = exports.BN_TEN = exports.BN_ONE = void 0;
8
8
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
9
9
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
10
10
  // SPDX-License-Identifier: Apache-2.0
@@ -13,6 +13,10 @@ const BN_ZERO = new _bignumber.default(0);
13
13
  exports.BN_ZERO = BN_ZERO;
14
14
  const BN_TEN = new _bignumber.default(10);
15
15
  exports.BN_TEN = BN_TEN;
16
+ const BN_ONE = new _bignumber.default(1);
17
+ exports.BN_ONE = BN_ONE;
18
+ const BN_WEI = BN_TEN.pow(9);
19
+ exports.BN_WEI = BN_WEI;
16
20
  // Clear zero from end, use with decimal only
17
21
  const clearZero = result => {
18
22
  let index = result.length - 1;
@@ -11,9 +11,10 @@ export declare const BIT_COUNTRY_LAND_ESTATE_METADATA_API = "https://pioneer-api
11
11
  export declare const BIT_COUNTRY_THUMBNAIL_RESOLVER = "https://res.cloudinary.com/ddftctzph/image/upload/c_scale,q_100,w_250/production-ipfs/asset/";
12
12
  export declare const CF_IPFS_GATEWAY = "https://cf-ipfs.com/ipfs/";
13
13
  export declare const PINATA_IPFS_GATEWAY = "https://gateway.pinata.cloud/ipfs/";
14
- export declare const UNIQUE_SCAN_ENDPOINT = "https://explorer-api.unique.network/v1/graphql";
15
- export declare const QUARTZ_SCAN_ENDPOINT = "https://hasura-quartz.unique.network/v1/graphql";
16
14
  export declare const VARA_SCAN_ENDPOINT = "https://nft-explorer.vara-network.io/graphql";
15
+ export declare const UNIQUE_SCAN_ENDPOINT = "https://api-unique.uniquescan.io/v1/graphql";
16
+ export declare const QUARTZ_SCAN_ENDPOINT = "https://api-quartz.uniquescan.io/v1/graphql";
17
+ export declare const OPAL_SCAN_ENDPOINT = "https://api-opal.uniquescan.io/v1/graphql";
17
18
  export declare const UNIQUE_IPFS_GATEWAY = "https://ipfs.unique.network/ipfs/";
18
19
  export declare const NFT_STORAGE_GATEWAY = "https://nftstorage.link/ipfs/";
19
20
  export declare const IPFS_W3S_LINK = "https://w3s.link/ipfs/";
@@ -21,10 +21,15 @@ export const CF_IPFS_GATEWAY = 'https://cf-ipfs.com/ipfs/';
21
21
 
22
22
  // XOrigin
23
23
  export const PINATA_IPFS_GATEWAY = 'https://gateway.pinata.cloud/ipfs/';
24
- export const UNIQUE_SCAN_ENDPOINT = 'https://explorer-api.unique.network/v1/graphql';
25
- export const QUARTZ_SCAN_ENDPOINT = 'https://hasura-quartz.unique.network/v1/graphql';
26
- export const VARA_SCAN_ENDPOINT = 'https://nft-explorer.vara-network.io/graphql';
27
24
 
25
+ // deprecated
26
+ // export const UNIQUE_SCAN_ENDPOINT = 'https://explorer-api.unique.network/v1/graphql';
27
+ // export const QUARTZ_SCAN_ENDPOINT = 'https://hasura-quartz.unique.network/v1/graphql';
28
+
29
+ export const VARA_SCAN_ENDPOINT = 'https://nft-explorer.vara-network.io/graphql';
30
+ export const UNIQUE_SCAN_ENDPOINT = 'https://api-unique.uniquescan.io/v1/graphql';
31
+ export const QUARTZ_SCAN_ENDPOINT = 'https://api-quartz.uniquescan.io/v1/graphql';
32
+ export const OPAL_SCAN_ENDPOINT = 'https://api-opal.uniquescan.io/v1/graphql';
28
33
  // GATEWAY
29
34
 
30
35
  export const UNIQUE_IPFS_GATEWAY = 'https://ipfs.unique.network/ipfs/';
@@ -8,7 +8,8 @@ import { KaruraNftApi } from '@subwallet/extension-base/koni/api/nft/karura_nft'
8
8
  import OrdinalNftApi from '@subwallet/extension-base/koni/api/nft/ordinal_nft';
9
9
  import { RmrkNftApi } from '@subwallet/extension-base/koni/api/nft/rmrk_nft';
10
10
  import StatemineNftApi from '@subwallet/extension-base/koni/api/nft/statemine_nft';
11
- import UniqueNftApi from '@subwallet/extension-base/koni/api/nft/unique_nft';
11
+ import { UniqueNftApi } from '@subwallet/extension-base/koni/api/nft/unique_network_nft';
12
+ // import UniqueNftApi from '@subwallet/extension-base/koni/api/nft/unique_nft';
12
13
  import { VaraNftApi } from '@subwallet/extension-base/koni/api/nft/vara_nft';
13
14
  import { WasmNftApi } from '@subwallet/extension-base/koni/api/nft/wasm_nft';
14
15
  import { _NFT_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
@@ -28,7 +29,7 @@ function createSubstrateNftApi(chain, substrateApi, addresses) {
28
29
  } else if (_NFT_CHAIN_GROUP.statemint.includes(chain)) {
29
30
  return new StatemintNftApi(substrateApi, substrateAddresses, chain);
30
31
  } else if (_NFT_CHAIN_GROUP.unique_network.includes(chain)) {
31
- return new UniqueNftApi(substrateApi, substrateAddresses, chain);
32
+ return new UniqueNftApi(chain, substrateAddresses);
32
33
  } else if (_NFT_CHAIN_GROUP.bitcountry.includes(chain)) {
33
34
  return new BitCountryNftApi(substrateApi, substrateAddresses, chain);
34
35
  } else if (_NFT_CHAIN_GROUP.vara.includes(chain)) {
@@ -3,7 +3,6 @@ export declare function isRecipientSelf(currentAddress: string, recipientAddress
3
3
  export declare function acalaGetExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null;
4
4
  export declare function rmrkGetExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null;
5
5
  export declare function uniqueGetExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null;
6
- export declare function quartzGetExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null;
7
6
  export declare function statemineGetExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null;
8
7
  export declare function statemintGetExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null;
9
8
  export declare function getNftTransferExtrinsic(networkKey: string, substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null;
@@ -30,18 +30,6 @@ export function rmrkGetExtrinsic(substrateApi, senderAddress, recipientAddress,
30
30
  }
31
31
  }
32
32
  export function uniqueGetExtrinsic(substrateApi, senderAddress, recipientAddress, params) {
33
- try {
34
- const itemId = params.itemId;
35
- const collectionId = params.collectionId;
36
- return substrateApi.api.tx.nft.transfer({
37
- Substrate: recipientAddress
38
- }, collectionId, itemId, 1);
39
- } catch (e) {
40
- console.error(e);
41
- return null;
42
- }
43
- }
44
- export function quartzGetExtrinsic(substrateApi, senderAddress, recipientAddress, params) {
45
33
  try {
46
34
  const itemId = params.itemId;
47
35
  const collectionId = params.collectionId;
@@ -81,12 +69,13 @@ export function getNftTransferExtrinsic(networkKey, substrateApi, senderAddress,
81
69
  return acalaGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
82
70
  case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.kusama:
83
71
  return rmrkGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
84
- case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.uniqueNft:
85
- return uniqueGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
86
- case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.quartz:
87
- return quartzGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
88
- case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.opal:
89
- return quartzGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
72
+ // temporary prevent send nfts on Unique network-based chains
73
+ // case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.uniqueNft:
74
+ // return uniqueGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
75
+ // case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.quartz:
76
+ // return uniqueGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
77
+ // case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.opal:
78
+ // return uniqueGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
90
79
  case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.statemine:
91
80
  return statemineGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
92
81
  case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.statemint:
@@ -0,0 +1,9 @@
1
+ import { BaseNftApi, HandleNftParams } from '@subwallet/extension-base/koni/api/nft/nft';
2
+ export declare class UniqueNftApi extends BaseNftApi {
3
+ constructor(chain: string, addresses: string[]);
4
+ private handleProperties;
5
+ private static parseNftRequest;
6
+ private getNftByAccount;
7
+ handleNfts(params: HandleNftParams): Promise<void>;
8
+ fetchNfts(params: HandleNftParams): Promise<number>;
9
+ }
@@ -0,0 +1,146 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { OPAL_SCAN_ENDPOINT, QUARTZ_SCAN_ENDPOINT, UNIQUE_SCAN_ENDPOINT } from '@subwallet/extension-base/koni/api/nft/config';
5
+ import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
6
+ import fetch from 'cross-fetch';
7
+ import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
8
+ export class UniqueNftApi extends BaseNftApi {
9
+ constructor(chain, addresses) {
10
+ super(chain, undefined, addresses);
11
+ }
12
+ handleProperties(nft) {
13
+ const propertiesMap = {};
14
+ const attRecord = nft.attributes;
15
+ if (attRecord) {
16
+ for (const item in attRecord) {
17
+ if (attRecord[item].name._.toLowerCase() === 'traits') {
18
+ const traits = [];
19
+ const traitValues = attRecord[item].value;
20
+ for (const trait in traitValues) {
21
+ traits.push(traitValues[trait]._);
22
+ }
23
+ propertiesMap.traits = {
24
+ value: traits
25
+ };
26
+ } else {
27
+ propertiesMap[attRecord[item].name._] = {
28
+ value: attRecord[item].value._
29
+ };
30
+ }
31
+ }
32
+ }
33
+ return propertiesMap;
34
+ }
35
+ static parseNftRequest(uniqueAddress) {
36
+ return {
37
+ query: `
38
+ query {
39
+ tokens(
40
+ limit: 99999
41
+ offset: 0
42
+ where: { owner: { _eq: "${uniqueAddress}" }, burned: { _eq: "false" }})
43
+ {
44
+ data {
45
+ collection_id
46
+ collection_name
47
+ collection_description
48
+ collection_cover
49
+ token_id
50
+ token_name
51
+ image
52
+ attributes
53
+ }
54
+ }
55
+ }
56
+ `
57
+ };
58
+ }
59
+ async getNftByAccount(address) {
60
+ var _result$data, _result$data$tokens;
61
+ let endpoint = '';
62
+ let uniqueAddress = '';
63
+
64
+ // Use exactly endpoint for each network
65
+ if (['unique_network'].includes(this.chain)) {
66
+ endpoint = UNIQUE_SCAN_ENDPOINT;
67
+ uniqueAddress = encodeAddress(decodeAddress(address), 7391);
68
+ // Unique network prefix: 7391
69
+ } else if (['quartz'].includes(this.chain)) {
70
+ endpoint = QUARTZ_SCAN_ENDPOINT;
71
+ uniqueAddress = encodeAddress(decodeAddress(address), 255);
72
+ // Quartz prefix: 255
73
+ } else if (['opal'].includes(this.chain)) {
74
+ endpoint = OPAL_SCAN_ENDPOINT;
75
+ uniqueAddress = address;
76
+ // Opal address: Normal address
77
+ }
78
+
79
+ const resp = await fetch(endpoint, {
80
+ method: 'post',
81
+ headers: {
82
+ 'Content-Type': 'application/json'
83
+ },
84
+ body: JSON.stringify(UniqueNftApi.parseNftRequest(uniqueAddress))
85
+ });
86
+ const result = await resp.json();
87
+
88
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
89
+ return result === null || result === void 0 ? void 0 : (_result$data = result.data) === null || _result$data === void 0 ? void 0 : (_result$data$tokens = _result$data.tokens) === null || _result$data$tokens === void 0 ? void 0 : _result$data$tokens.data;
90
+ }
91
+ async handleNfts(params) {
92
+ try {
93
+ await Promise.all(this.addresses.map(async address => {
94
+ const nfts = await this.getNftByAccount(address);
95
+ if (nfts) {
96
+ const collectionMap = {};
97
+ for (const nft of nfts) {
98
+ var _nft$image;
99
+ // Handle case rendering image on Quartz Network (Temporary solution)
100
+ if (this.chain === 'quartz' && nft.collection_id.toString() === '141') {
101
+ continue;
102
+ }
103
+
104
+ // Handle properties
105
+ const propertiesMap = this.handleProperties(nft);
106
+
107
+ // Update Nft information
108
+ const parsedNft = {
109
+ id: nft.token_id.toString(),
110
+ chain: this.chain,
111
+ owner: address,
112
+ name: nft.token_name,
113
+ image: this.parseUrl((_nft$image = nft.image) === null || _nft$image === void 0 ? void 0 : _nft$image.fullUrl),
114
+ description: nft.collection_description,
115
+ collectionId: nft.collection_id.toString(),
116
+ properties: propertiesMap
117
+ };
118
+ params.updateItem(this.chain, parsedNft, address);
119
+
120
+ // Update Collection information
121
+ if (!collectionMap[nft.collection_id.toString()]) {
122
+ const parsedCollection = {
123
+ collectionId: nft.collection_id.toString(),
124
+ chain: this.chain,
125
+ collectionName: nft.collection_name,
126
+ image: this.parseUrl(nft.collection_cover)
127
+ };
128
+ collectionMap[nft.collection_id.toString()] = parsedCollection;
129
+ params.updateCollection(this.chain, parsedCollection);
130
+ }
131
+ }
132
+ }
133
+ }));
134
+ } catch (e) {
135
+ console.error(`Failed to fetch ${this.chain} nft`, e);
136
+ }
137
+ }
138
+ async fetchNfts(params) {
139
+ try {
140
+ await this.handleNfts(params);
141
+ } catch (e) {
142
+ return 0;
143
+ }
144
+ return 1;
145
+ }
146
+ }
@@ -3,7 +3,9 @@ import { _ChainInfo } from '@subwallet/chain-list/types';
3
3
  import { NominationInfo, NominatorMetadata, StakingType, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
4
4
  import { _SubstrateInflationParams } from '@subwallet/extension-base/services/chain-service/constants';
5
5
  import { EarningStatus, YieldPoolInfo, YieldPositionInfo } from '@subwallet/extension-base/types';
6
+ import BigNumber from 'bignumber.js';
6
7
  import { ApiPromise } from '@polkadot/api';
8
+ import { Codec } from '@polkadot/types/types';
7
9
  import { BN } from '@polkadot/util';
8
10
  export interface PalletDappsStakingDappInfo {
9
11
  address: string;
@@ -97,6 +99,7 @@ export declare function calcInflationUniformEraPayout(totalIssuance: BN, yearlyI
97
99
  export declare function calcInflationRewardCurve(minInflation: number, stakedFraction: number, idealStake: number, idealInterest: number, falloff: number): number;
98
100
  export declare function calculateInflation(totalEraStake: BN, totalIssuance: BN, numAuctions: number, networkKey: string): number;
99
101
  export declare function calculateChainStakedReturn(inflation: number, totalEraStake: BN, totalIssuance: BN, networkKey: string): number;
102
+ export declare function calculateChainStakedReturnV2(chainInfo: _ChainInfo, totalIssuance: string, erasPerDay: number, lastTotalStaked: string, validatorEraReward: BigNumber, isCompound?: boolean): number;
100
103
  export declare function calculateAlephZeroValidatorReturn(chainStakedReturn: number, commission: number): number;
101
104
  export declare function calculateTernoaValidatorReturn(rewardPerValidator: number, validatorStake: number, commission: number): number;
102
105
  export declare function calculateValidatorStakedReturn(chainStakedReturn: number, totalValidatorStake: BN, avgStake: BN, commission: number): number;
@@ -154,6 +157,8 @@ export declare function isActionFromValidator(stakingType: StakingType, chain: s
154
157
  export declare function getWithdrawalInfo(nominatorMetadata: NominatorMetadata): UnstakingInfo | undefined;
155
158
  export declare function getEarningStatusByNominations(bnTotalActiveStake: BN, nominationList: NominationInfo[]): EarningStatus;
156
159
  export declare function getValidatorLabel(chain: string): "dApp" | "Validator" | "Collator";
160
+ export declare function getAvgValidatorEraReward(supportedDays: number, eraRewardHistory: Codec[]): BigNumber;
161
+ export declare function getSupportedDaysByHistoryDepth(erasPerDay: number, maxSupportedEras: number): 15 | 30;
157
162
  export declare const getMinStakeErrorMessage: (chainInfo: _ChainInfo, bnMinStake: BN) => string;
158
163
  export declare const getMaxValidatorErrorMessage: (chainInfo: _ChainInfo, max: number) => string;
159
164
  export declare const getExistUnstakeErrorMessage: (chain: string, type?: StakingType, isStakeMore?: boolean) => string;
@@ -9,6 +9,7 @@ import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning
9
9
  import { EarningStatus, UnstakingStatus, YieldPoolType } from '@subwallet/extension-base/types';
10
10
  import { detectTranslate, parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
11
11
  import { balanceFormatter, formatNumber } from '@subwallet/extension-base/utils/number';
12
+ import BigNumber from 'bignumber.js';
12
13
  import { t } from 'i18next';
13
14
  import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
14
15
  export let PalletParachainStakingRequestType;
@@ -71,6 +72,24 @@ export function calculateChainStakedReturn(inflation, totalEraStake, totalIssuan
71
72
 
72
73
  return stakedReturn;
73
74
  }
75
+ export function calculateChainStakedReturnV2(chainInfo, totalIssuance, erasPerDay, lastTotalStaked, validatorEraReward, isCompound) {
76
+ const DAYS_PER_YEAR = 365;
77
+ // @ts-ignore
78
+ const DECIMAL = chainInfo.substrateInfo.decimals;
79
+ const lastTotalStakedUnit = new BigNumber(lastTotalStaked).dividedBy(new BigNumber(10 ** DECIMAL));
80
+ const totalIssuanceUnit = new BigNumber(totalIssuance).dividedBy(new BigNumber(10 ** DECIMAL));
81
+ const supplyStaked = lastTotalStakedUnit.dividedBy(totalIssuanceUnit);
82
+ const dayRewardRate = validatorEraReward.multipliedBy(erasPerDay).dividedBy(totalIssuance).multipliedBy(100);
83
+ let inflationToStakers = new BigNumber(0);
84
+ if (!isCompound) {
85
+ inflationToStakers = dayRewardRate.multipliedBy(DAYS_PER_YEAR);
86
+ } else {
87
+ const multiplier = dayRewardRate.dividedBy(100).plus(1).exponentiatedBy(365);
88
+ inflationToStakers = new BigNumber(100).multipliedBy(multiplier).minus(100);
89
+ }
90
+ const averageRewardRate = inflationToStakers.dividedBy(supplyStaked);
91
+ return averageRewardRate.toNumber();
92
+ }
74
93
  export function calculateAlephZeroValidatorReturn(chainStakedReturn, commission) {
75
94
  return chainStakedReturn * (100 - commission) / 100;
76
95
  }
@@ -310,6 +329,27 @@ export function getValidatorLabel(chain) {
310
329
  }
311
330
  return 'Collator';
312
331
  }
332
+ export function getAvgValidatorEraReward(supportedDays, eraRewardHistory) {
333
+ let sumEraReward = new BigNumber(0);
334
+ let failEra = 0;
335
+ for (const _item of eraRewardHistory) {
336
+ const item = _item.toString();
337
+ if (!item) {
338
+ failEra += 1;
339
+ } else {
340
+ const eraReward = new BigNumber(item);
341
+ sumEraReward = sumEraReward.plus(eraReward);
342
+ }
343
+ }
344
+ return sumEraReward.dividedBy(new BigNumber(supportedDays - failEra));
345
+ }
346
+ export function getSupportedDaysByHistoryDepth(erasPerDay, maxSupportedEras) {
347
+ if (maxSupportedEras / erasPerDay > 30) {
348
+ return 30;
349
+ } else {
350
+ return 15;
351
+ }
352
+ }
313
353
  export const getMinStakeErrorMessage = (chainInfo, bnMinStake) => {
314
354
  const tokenInfo = _getChainNativeTokenBasicInfo(chainInfo);
315
355
  const number = formatNumber(bnMinStake.toString(), tokenInfo.decimals || 0, balanceFormatter);