@subwallet/extension-base 1.1.35-beta.2 → 1.1.35-beta.3

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 (71) 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/staking/bonding/utils.js +44 -0
  5. package/cjs/koni/api/tokens/evm/transfer.js +35 -19
  6. package/cjs/koni/api/yield/helper/utils.js +6 -3
  7. package/cjs/koni/background/handlers/Extension.js +20 -12
  8. package/cjs/koni/background/handlers/State.js +15 -5
  9. package/cjs/services/chain-service/index.js +0 -3
  10. package/cjs/services/earning-service/handlers/liquid-staking/base.js +2 -1
  11. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +2 -1
  12. package/cjs/services/earning-service/handlers/liquid-staking/index.js +7 -0
  13. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
  14. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +10 -2
  15. package/cjs/services/earning-service/handlers/nomination-pool/index.js +10 -2
  16. package/cjs/services/earning-service/handlers/special.js +7 -3
  17. package/cjs/services/earning-service/service.js +9 -2
  18. package/cjs/services/notification-service/NotificationService.js +7 -4
  19. package/cjs/services/request-service/handler/EvmRequestHandler.js +46 -29
  20. package/cjs/services/transaction-service/index.js +43 -14
  21. package/cjs/signers/web3/QrSigner.js +2 -0
  22. package/cjs/types/yield/actions/join/step.js +1 -0
  23. package/cjs/utils/eth/mergeTransactionAndSignature.js +25 -10
  24. package/cjs/utils/eth.js +51 -2
  25. package/cjs/utils/number.js +5 -1
  26. package/cjs/utils/yield/index.js +3 -0
  27. package/koni/api/staking/bonding/utils.d.ts +5 -0
  28. package/koni/api/staking/bonding/utils.js +40 -0
  29. package/koni/api/tokens/evm/transfer.js +36 -21
  30. package/koni/api/yield/helper/utils.d.ts +1 -1
  31. package/koni/api/yield/helper/utils.js +5 -3
  32. package/koni/background/handlers/Extension.js +21 -13
  33. package/koni/background/handlers/State.js +16 -6
  34. package/package.json +11 -7
  35. package/services/chain-service/index.js +0 -3
  36. package/services/earning-service/handlers/liquid-staking/base.d.ts +1 -1
  37. package/services/earning-service/handlers/liquid-staking/base.js +2 -1
  38. package/services/earning-service/handlers/liquid-staking/bifrost-manta.d.ts +37 -0
  39. package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +132 -0
  40. package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +3 -3
  41. package/services/earning-service/handlers/liquid-staking/bifrost.js +2 -1
  42. package/services/earning-service/handlers/liquid-staking/index.d.ts +1 -0
  43. package/services/earning-service/handlers/liquid-staking/index.js +1 -0
  44. package/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
  45. package/services/earning-service/handlers/native-staking/relay-chain.js +11 -3
  46. package/services/earning-service/handlers/nomination-pool/index.js +11 -3
  47. package/services/earning-service/handlers/special.js +7 -3
  48. package/services/earning-service/service.d.ts +2 -1
  49. package/services/earning-service/service.js +10 -3
  50. package/services/notification-service/NotificationService.js +7 -4
  51. package/services/request-service/handler/EvmRequestHandler.d.ts +2 -2
  52. package/services/request-service/handler/EvmRequestHandler.js +46 -29
  53. package/services/transaction-service/index.js +44 -15
  54. package/services/transaction-service/types.d.ts +2 -2
  55. package/signers/types.d.ts +2 -0
  56. package/signers/web3/QrSigner.js +2 -0
  57. package/types/yield/actions/join/step.d.ts +1 -0
  58. package/types/yield/actions/join/step.js +1 -0
  59. package/utils/eth/mergeTransactionAndSignature.js +25 -10
  60. package/utils/eth.d.ts +14 -0
  61. package/utils/eth.js +48 -0
  62. package/utils/number.d.ts +2 -0
  63. package/utils/number.js +2 -0
  64. package/cjs/koni/api/dotsama/balance.js +0 -464
  65. package/cjs/services/migration-service/scripts/MigrateEthProvider.js +0 -17
  66. package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +0 -17
  67. package/cjs/services/migration-service/scripts/MigrateProvider.js +0 -29
  68. package/cjs/services/storage-service/index.js +0 -241
  69. package/cjs/types.js +0 -1
  70. package/cjs/utils/address.js +0 -34
  71. package/cjs/utils/keyring.js +0 -57
@@ -5,8 +5,9 @@ import { ExternalRequestPromiseStatus } from '@subwallet/extension-base/backgrou
5
5
  import { getERC20Contract } from '@subwallet/extension-base/koni/api/tokens/evm/web3';
6
6
  import { _BALANCE_PARSING_CHAIN_GROUP, EVM_REFORMAT_DECIMALS } from '@subwallet/extension-base/services/chain-service/constants';
7
7
  import { _ERC721_ABI } from '@subwallet/extension-base/services/chain-service/helper';
8
- import { recalculateGasPrice } from '@subwallet/extension-base/utils/eth';
9
- import { BN, hexToBn } from '@polkadot/util';
8
+ import { calculateGasFeeParams } from '@subwallet/extension-base/utils/eth';
9
+ import BigN from 'bignumber.js';
10
+ import { hexToBn } from '@polkadot/util';
10
11
  export const handleTransferBalanceResult = ({
11
12
  callback,
12
13
  changeValue,
@@ -34,20 +35,29 @@ export const handleTransferBalanceResult = ({
34
35
  callback(response);
35
36
  };
36
37
  export async function getEVMTransactionObject(chainInfo, from, to, value, transferAll, evmApiMap) {
38
+ var _priority$maxFeePerGa, _priority$maxPriority;
37
39
  const networkKey = chainInfo.slug;
38
40
  const web3Api = evmApiMap[networkKey];
39
- const _price = await web3Api.api.eth.getGasPrice();
40
- const gasPrice = recalculateGasPrice(_price, chainInfo.slug);
41
+ const priority = await calculateGasFeeParams(web3Api, networkKey);
41
42
  const transactionObject = {
42
- gasPrice: gasPrice,
43
43
  to: to,
44
44
  value: value,
45
- from: from
45
+ from: from,
46
+ gasPrice: priority.gasPrice,
47
+ maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
48
+ maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
46
49
  };
47
50
  const gasLimit = await web3Api.api.eth.estimateGas(transactionObject);
48
51
  transactionObject.gas = gasLimit;
49
- const estimateFee = new BN(gasLimit).mul(new BN(gasPrice));
50
- transactionObject.value = transferAll ? new BN(value).sub(estimateFee).toString() : value;
52
+ let estimateFee;
53
+ if (priority.baseGasFee) {
54
+ const priorityFee = priority.baseGasFee.plus(priority.maxPriorityFeePerGas);
55
+ const maxFee = priority.maxFeePerGas.gte(priorityFee) ? priority.maxFeePerGas : priorityFee;
56
+ estimateFee = maxFee.multipliedBy(gasLimit);
57
+ } else {
58
+ estimateFee = new BigN(priority.gasPrice).multipliedBy(gasLimit);
59
+ }
60
+ transactionObject.value = transferAll ? new BigN(value).minus(estimateFee).toString() : value;
51
61
  if (EVM_REFORMAT_DECIMALS.acala.includes(networkKey)) {
52
62
  const numberReplace = 18 - 12;
53
63
  transactionObject.value = transactionObject.value.substring(0, transactionObject.value.length - 6) + new Array(numberReplace).fill('0').join('');
@@ -55,53 +65,58 @@ export async function getEVMTransactionObject(chainInfo, from, to, value, transf
55
65
  return [transactionObject, transactionObject.value.toString()];
56
66
  }
57
67
  export async function getERC20TransactionObject(assetAddress, chainInfo, from, to, value, transferAll, evmApiMap) {
68
+ var _priority$maxFeePerGa2, _priority$maxPriority2;
58
69
  const networkKey = chainInfo.slug;
59
70
  const evmApi = evmApiMap[networkKey];
60
71
  const erc20Contract = getERC20Contract(networkKey, assetAddress, evmApiMap);
61
- let freeAmount = new BN(0);
72
+ let freeAmount = new BigN(0);
62
73
  let transferValue = value;
63
74
  if (transferAll) {
64
75
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
65
76
  const bal = await erc20Contract.methods.balanceOf(from).call();
66
- freeAmount = new BN(bal || '0');
67
- transferValue = freeAmount.toString() || '0';
77
+ freeAmount = new BigN(bal || '0');
78
+ transferValue = freeAmount.toFixed(0) || '0';
68
79
  }
69
80
  function generateTransferData(to, transferValue) {
70
81
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
71
82
  return erc20Contract.methods.transfer(to, transferValue).encodeABI();
72
83
  }
73
84
  const transferData = generateTransferData(to, transferValue);
74
- const [gasLimit, _price] = await Promise.all([
85
+ const [gasLimit, priority] = await Promise.all([
75
86
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
76
87
  erc20Contract.methods.transfer(to, transferValue).estimateGas({
77
88
  from
78
- }), evmApi.api.eth.getGasPrice()]);
79
- const gasPrice = recalculateGasPrice(_price, chainInfo.slug);
89
+ }), calculateGasFeeParams(evmApi, networkKey)]);
80
90
  const transactionObject = {
81
- gasPrice: gasPrice,
82
91
  gas: gasLimit,
83
92
  from,
93
+ value: '0',
84
94
  to: assetAddress,
85
- data: transferData
95
+ data: transferData,
96
+ gasPrice: priority.gasPrice,
97
+ maxFeePerGas: (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
98
+ maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString()
86
99
  };
87
100
  if (transferAll) {
88
- transferValue = new BN(freeAmount).toString();
101
+ transferValue = freeAmount.toFixed(0);
89
102
  transactionObject.data = generateTransferData(to, transferValue);
90
103
  }
91
104
  return [transactionObject, transferValue];
92
105
  }
93
106
  export async function getERC721Transaction(web3Api, chain, contractAddress, senderAddress, recipientAddress, tokenId) {
107
+ var _priority$maxFeePerGa3, _priority$maxPriority3;
94
108
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
95
109
  const contract = new web3Api.api.eth.Contract(_ERC721_ABI, contractAddress);
96
- const [gasLimit, _price] = await Promise.all([
110
+ const [gasLimit, priority] = await Promise.all([
97
111
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
98
112
  contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).estimateGas({
99
113
  from: senderAddress
100
- }), web3Api.api.eth.getGasPrice()]);
101
- const gasPrice = recalculateGasPrice(_price, chain);
114
+ }), calculateGasFeeParams(web3Api, chain)]);
102
115
  return {
103
116
  from: senderAddress,
104
- gasPrice,
117
+ gasPrice: priority.gasPrice,
118
+ maxFeePerGas: (_priority$maxFeePerGa3 = priority.maxFeePerGas) === null || _priority$maxFeePerGa3 === void 0 ? void 0 : _priority$maxFeePerGa3.toString(),
119
+ maxPriorityFeePerGas: (_priority$maxPriority3 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority3 === void 0 ? void 0 : _priority$maxPriority3.toString(),
105
120
  gas: gasLimit,
106
121
  to: contractAddress,
107
122
  value: '0x00',
@@ -7,4 +7,4 @@ export declare const DEFAULT_YIELD_FIRST_STEP: YieldStepDetail;
7
7
  export declare const YIELD_EXTRINSIC_TYPES: ExtrinsicType[];
8
8
  export declare const YIELD_POOL_STAT_REFRESH_INTERVAL = 90000;
9
9
  export declare const YIELD_POOL_MIN_AMOUNT_PERCENT: Record<string, number>;
10
- export declare function convertDerivativeToOriginToken(amount: string, poolInfo: SpecialYieldPoolInfo, derivativeTokenInfo: _ChainAsset, originTokenInfo: _ChainAsset): number;
10
+ export declare function convertDerivativeToOriginToken(amount: string, poolInfo: SpecialYieldPoolInfo, derivativeTokenInfo: _ChainAsset, originTokenInfo: _ChainAsset): string;
@@ -4,6 +4,8 @@
4
4
  import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
5
  import { _getAssetDecimals } from '@subwallet/extension-base/services/chain-service/utils';
6
6
  import { YieldStepType } from '@subwallet/extension-base/types';
7
+ import { BN_TEN } from '@subwallet/extension-base/utils';
8
+ import BigN from 'bignumber.js';
7
9
  export const syntheticSelectedValidators = ['15MLn9YQaHZ4GMkhK3qXqR5iGGSdULyJ995ctjeBgFRseyi6', '1REAJ1k691g5Eqqg9gL7vvZCBG7FCCZ8zgQkZWd4va5ESih', '1yGJ3h7TQuJWLYSsUVPZbM8aR8UsQXCqMvrFx5Fn1ktiAmq', '16GDRhRYxk42paoK6TfHAqWej8PdDDUwdDazjv4bAn4KGNeb', '13Ybj8CPEArUee78DxUAP9yX3ABmFNVQME1ZH4w8HVncHGzc', '14yx4vPAACZRhoDQm1dyvXD3QdRQyCRRCe5tj1zPomhhS29a', '14Vh8S1DzzycngbAB9vqEgPFR9JpSvmF1ezihTUES1EaHAV', '153YD8ZHD9dRh82U419bSCB5SzWhbdAFzjj4NtA5pMazR2yC', '1LUckyocmz9YzeQZHVpBvYYRGXb3rnSm2tvfz79h3G3JDgP', '14oRE62MB1SWR6h5RTx3GY5HK2oZipi1Gp3zdiLwVYLfEyRZ', '1cFsLn7o74nmjbRyDtMAnMpQMc5ZLsjgCSz9Np2mcejUK83', '15ZvLonEseaWZNy8LDkXXj3Y8bmAjxCjwvpy4pXWSL4nGSBs', '1NebF2xZHb4TJJpiqZZ3reeTo8dZov6LZ49qZqcHHbsmHfo', '1HmAqbBRrWvsqbLkvpiVDkdA2PcctUE5JUe3qokEh1FN455', '15tfUt4iQNjMyhZiJGBf4EpETE2KqtW1nfJwbBT1MvWjvcK9', '12RXTLiaYh59PokjZVhQvKzcfBEB5CvDnjKKUmDUotzcTH3S'];
8
10
  export function calculateAlternativeFee(feeInfo) {
9
11
  return feeInfo.partialFee;
@@ -26,7 +28,7 @@ export function convertDerivativeToOriginToken(amount, poolInfo, derivativeToken
26
28
  const derivativeDecimals = _getAssetDecimals(derivativeTokenInfo);
27
29
  const originDecimals = _getAssetDecimals(originTokenInfo);
28
30
  const exchangeRate = ((_poolInfo$statistic = poolInfo.statistic) === null || _poolInfo$statistic === void 0 ? void 0 : (_poolInfo$statistic$a = _poolInfo$statistic.assetEarning) === null || _poolInfo$statistic$a === void 0 ? void 0 : _poolInfo$statistic$a[0].exchangeRate) || 1;
29
- const formattedAmount = parseInt(amount) / 10 ** derivativeDecimals; // TODO: decimals
30
- const minAmount = formattedAmount * exchangeRate;
31
- return Math.floor(minAmount * 10 ** originDecimals);
31
+ const formattedAmount = new BigN(amount).dividedBy(BN_TEN.pow(derivativeDecimals)); // TODO: decimals
32
+ const minAmount = formattedAmount.multipliedBy(exchangeRate);
33
+ return minAmount.multipliedBy(BN_TEN.pow(originDecimals)).toFixed(0);
32
34
  }
@@ -1,7 +1,8 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import Common from '@ethereumjs/common';
4
+ import { Common } from '@ethereumjs/common';
5
+ import { LegacyTransaction } from '@ethereumjs/tx';
5
6
  import { _AssetType } from '@subwallet/chain-list/types';
6
7
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
7
8
  import { isJsonPayload, SEED_DEFAULT_LENGTH, SEED_LENGTHS } from '@subwallet/extension-base/background/handlers/Extension';
@@ -31,14 +32,13 @@ import { WALLET_CONNECT_EIP155_NAMESPACE } from '@subwallet/extension-base/servi
31
32
  import { isProposalExpired, isSupportWalletConnectChain, isSupportWalletConnectNamespace } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
32
33
  import { YieldPoolType } from '@subwallet/extension-base/types';
33
34
  import { convertSubjectInfoToAddresses, isSameAddress, reformatAddress, uniqueStringArray } from '@subwallet/extension-base/utils';
34
- import { createTransactionFromRLP, recalculateGasPrice, signatureToHex } from '@subwallet/extension-base/utils/eth';
35
+ import { calculateGasFeeParams, createTransactionFromRLP, signatureToHex } from '@subwallet/extension-base/utils/eth';
35
36
  import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
36
37
  import { balanceFormatter, formatNumber } from '@subwallet/extension-base/utils/number';
37
38
  import { createPair } from '@subwallet/keyring';
38
39
  import { keyring } from '@subwallet/ui-keyring';
39
40
  import { getSdkError } from '@walletconnect/utils';
40
41
  import BigN from 'bignumber.js';
41
- import { Transaction } from 'ethereumjs-tx';
42
42
  import { t } from 'i18next';
43
43
  import { TypeRegistry } from '@polkadot/types';
44
44
  import { assert, BN, BN_ZERO, hexStripPrefix, hexToU8a, isAscii, isHex, u8aToHex, u8aToString } from '@polkadot/util';
@@ -1880,10 +1880,15 @@ export default class KoniExtension {
1880
1880
  // null address
1881
1881
  from: address
1882
1882
  };
1883
- const _price = await web3.api.eth.getGasPrice();
1884
- const gasPrice = recalculateGasPrice(_price, networkKey);
1885
1883
  const gasLimit = await web3.api.eth.estimateGas(transaction);
1886
- estimatedFee = (gasLimit * parseInt(gasPrice)).toString();
1884
+ const priority = await calculateGasFeeParams(web3, networkKey);
1885
+ if (priority.baseGasFee) {
1886
+ const priorityFee = priority.baseGasFee.plus(priority.maxPriorityFeePerGas);
1887
+ const maxFee = priority.maxFeePerGas.gte(priorityFee) ? priority.maxFeePerGas : priorityFee;
1888
+ estimatedFee = maxFee.multipliedBy(gasLimit).toFixed(0);
1889
+ } else {
1890
+ estimatedFee = new BigN(priority.gasPrice).multipliedBy(gasLimit).toFixed(0);
1891
+ }
1887
1892
  } else {
1888
1893
  var _paymentInfo$partialF2;
1889
1894
  const [mockTx] = await createTransferExtrinsic({
@@ -2407,6 +2412,7 @@ export default class KoniExtension {
2407
2412
  }
2408
2413
  signed = await pair.evmSigner.signMessage(data, 'personal_sign');
2409
2414
  } else {
2415
+ var _signedTranaction$r, _signedTranaction$s, _signedTranaction$v;
2410
2416
  const tx = createTransactionFromRLP(message);
2411
2417
  if (!tx) {
2412
2418
  throw new Error(t('Failed to decode data. Please use a valid QR code'));
@@ -2419,21 +2425,23 @@ export default class KoniExtension {
2419
2425
  nonce: new BigN(tx.nonce).toNumber(),
2420
2426
  gas: new BigN(tx.gas).toNumber()
2421
2427
  };
2422
- const common = Common.forCustomChain('mainnet', {
2428
+ const common = Common.custom({
2423
2429
  name: network.name,
2424
2430
  networkId: _getEvmChainId(network),
2425
2431
  chainId: _getEvmChainId(network)
2426
- }, 'petersburg');
2432
+ }, {
2433
+ hardfork: 'petersburg'
2434
+ });
2427
2435
 
2428
2436
  // @ts-ignore
2429
- const transaction = new Transaction(txObject, {
2437
+ const transaction = new LegacyTransaction(txObject, {
2430
2438
  common
2431
2439
  });
2432
- pair.evmSigner.signTransaction(transaction);
2440
+ const signedTranaction = LegacyTransaction.fromSerializedTx(hexToU8a(pair.evmSigner.signTransaction(transaction)));
2433
2441
  signed = signatureToHex({
2434
- r: u8aToHex(transaction.r),
2435
- s: u8aToHex(transaction.s),
2436
- v: u8aToHex(transaction.v)
2442
+ r: ((_signedTranaction$r = signedTranaction.r) === null || _signedTranaction$r === void 0 ? void 0 : _signedTranaction$r.toString(16)) || '',
2443
+ s: ((_signedTranaction$s = signedTranaction.s) === null || _signedTranaction$s === void 0 ? void 0 : _signedTranaction$s.toString(16)) || '',
2444
+ v: ((_signedTranaction$v = signedTranaction.v) === null || _signedTranaction$v === void 0 ? void 0 : _signedTranaction$v.toString(16)) || ''
2437
2445
  });
2438
2446
  }
2439
2447
  return {
@@ -31,11 +31,12 @@ import TransactionService from '@subwallet/extension-base/services/transaction-s
31
31
  import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
32
32
  import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
33
33
  import { addLazy, isAccountAll, stripUrl, TARGET_ENV } from '@subwallet/extension-base/utils';
34
- import { recalculateGasPrice } from '@subwallet/extension-base/utils/eth';
34
+ import { calculateGasFeeParams } from '@subwallet/extension-base/utils/eth';
35
35
  import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
36
36
  import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
37
37
  import { decodePair } from '@subwallet/keyring/pair/decode';
38
38
  import { keyring } from '@subwallet/ui-keyring';
39
+ import BigN from 'bignumber.js';
39
40
  import SimpleKeyring from 'eth-simple-keyring';
40
41
  import { t } from 'i18next';
41
42
  import { Subject } from 'rxjs';
@@ -1239,10 +1240,17 @@ export default class KoniState {
1239
1240
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1240
1241
  throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
1241
1242
  }
1242
- const _price = await web3.eth.getGasPrice();
1243
- const gasPrice = recalculateGasPrice(_price, networkKey);
1244
- transaction.gasPrice = gasPrice;
1245
- const estimateGas = new BN(gasPrice.toString()).mul(new BN(transaction.gas)).toString();
1243
+ const priority = await calculateGasFeeParams(evmApi, networkKey);
1244
+ let estimateGas;
1245
+ if (priority.baseGasFee) {
1246
+ transaction.maxPriorityFeePerGas = priority.maxPriorityFeePerGas.toString();
1247
+ transaction.maxFeePerGas = priority.maxFeePerGas.toString();
1248
+ const priorityFee = priority.baseGasFee.plus(priority.maxPriorityFeePerGas);
1249
+ const maxFee = priority.maxFeePerGas.lte(priorityFee) ? priority.maxFeePerGas : priorityFee;
1250
+ estimateGas = maxFee.multipliedBy(transaction.gas).toFixed(0);
1251
+ } else {
1252
+ estimateGas = new BigN(priority.gasPrice).multipliedBy(transaction.gas).toFixed(0);
1253
+ }
1246
1254
 
1247
1255
  // Address is validated in before step
1248
1256
  const fromAddress = allowedAccounts.find(account => account.toLowerCase() === transaction.from.toLowerCase());
@@ -1260,7 +1268,7 @@ export default class KoniState {
1260
1268
 
1261
1269
  // Validate balance
1262
1270
  const balance = new BN((await web3.eth.getBalance(fromAddress)) || 0);
1263
- if (balance.lt(new BN(gasPrice.toString()).mul(new BN(transaction.gas)).add(new BN(autoFormatNumber(transactionParams.value) || '0')))) {
1271
+ if (balance.lt(new BN(estimateGas).add(new BN(autoFormatNumber(transactionParams.value) || '0')))) {
1264
1272
  throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Insufficient balance'));
1265
1273
  }
1266
1274
  transaction.nonce = await web3.eth.getTransactionCount(fromAddress);
@@ -1571,6 +1579,8 @@ export default class KoniState {
1571
1579
  await this.keyringService.resetWallet(resetAll);
1572
1580
  this.requestService.resetWallet();
1573
1581
  this.transactionService.resetWallet();
1582
+ await this.handleResetBalance(ALL_ACCOUNT_KEY, true);
1583
+ await this.earningService.resetWallet();
1574
1584
  await this.dbService.resetWallet(resetAll);
1575
1585
  this.accountRefStore.set('refList', []);
1576
1586
  if (resetAll) {
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.1.35-beta.2",
20
+ "version": "1.1.35-beta.3",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -755,6 +755,11 @@
755
755
  "require": "./cjs/services/earning-service/handlers/liquid-staking/bifrost.js",
756
756
  "default": "./services/earning-service/handlers/liquid-staking/bifrost.js"
757
757
  },
758
+ "./services/earning-service/handlers/liquid-staking/bifrost-manta": {
759
+ "types": "./services/earning-service/handlers/liquid-staking/bifrost-manta.d.ts",
760
+ "require": "./cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js",
761
+ "default": "./services/earning-service/handlers/liquid-staking/bifrost-manta.js"
762
+ },
758
763
  "./services/earning-service/handlers/liquid-staking/parallel": {
759
764
  "types": "./services/earning-service/handlers/liquid-staking/parallel.d.ts",
760
765
  "require": "./cjs/services/earning-service/handlers/liquid-staking/parallel.js",
@@ -1702,8 +1707,8 @@
1702
1707
  "@apollo/client": "^3.7.14",
1703
1708
  "@azns/resolver-core": "^1.4.0",
1704
1709
  "@equilab/api": "~1.14.25",
1705
- "@ethereumjs/common": "^2.6.5",
1706
- "@ethereumjs/tx": "^4.0.2",
1710
+ "@ethereumjs/common": "^4.1.0",
1711
+ "@ethereumjs/tx": "^5.1.0",
1707
1712
  "@ethersproject/abi": "^5.7.0",
1708
1713
  "@json-rpc-tools/utils": "^1.7.6",
1709
1714
  "@metamask/safe-event-emitter": "^2.0.0",
@@ -1726,13 +1731,13 @@
1726
1731
  "@reduxjs/toolkit": "^1.9.1",
1727
1732
  "@sora-substrate/type-definitions": "^1.17.7",
1728
1733
  "@substrate/connect": "^0.7.26",
1729
- "@subwallet/chain-list": "0.2.39",
1734
+ "@subwallet/chain-list": "0.2.40-beta.2",
1730
1735
  "@subwallet/extension-base": "^1.1.35-0",
1731
1736
  "@subwallet/extension-chains": "^1.1.35-0",
1732
1737
  "@subwallet/extension-dapp": "^1.1.35-0",
1733
1738
  "@subwallet/extension-inject": "^1.1.35-0",
1734
- "@subwallet/keyring": "^0.1.1",
1735
- "@subwallet/ui-keyring": "^0.1.1",
1739
+ "@subwallet/keyring": "^0.1.3",
1740
+ "@subwallet/ui-keyring": "^0.1.3",
1736
1741
  "@walletconnect/sign-client": "^2.8.4",
1737
1742
  "@walletconnect/types": "^2.8.4",
1738
1743
  "@walletconnect/utils": "^2.8.4",
@@ -1747,7 +1752,6 @@
1747
1752
  "dexie": "^3.2.2",
1748
1753
  "dexie-export-import": "^4.0.7",
1749
1754
  "eth-simple-keyring": "^4.2.0",
1750
- "ethereumjs-tx": "^2.1.2",
1751
1755
  "ethereumjs-util": "^7.1.5",
1752
1756
  "ethers": "^6.4.2",
1753
1757
  "eventemitter3": "^5.0.0",
@@ -433,9 +433,6 @@ export class ChainService {
433
433
  checkLatestData() {
434
434
  clearInterval(this.refreshLatestChainDataTimeOut);
435
435
  this.handleLatestData();
436
- this.handleLatestData();
437
- this.handleLatestData();
438
- this.handleLatestData();
439
436
  this.refreshLatestChainDataTimeOut = setInterval(this.handleLatestData.bind(this), LATEST_CHAIN_DATA_FETCHING_INTERVAL);
440
437
  }
441
438
  stopCheckLatestChainData() {
@@ -6,6 +6,6 @@ export default abstract class BaseLiquidStakingPoolHandler extends BaseSpecialSt
6
6
  /** Rate convert token when redeem */
7
7
  readonly minAmountPercent: number;
8
8
  static get defaultMinAmountPercent(): number;
9
- createParamToRedeem(amount: string, address: string): Promise<number>;
9
+ createParamToRedeem(amount: string, address: string): Promise<string>;
10
10
  validateYieldLeave(amount: string, address: string, fastLeave: boolean, selectedTarget?: string): Promise<TransactionError[]>;
11
11
  }
@@ -6,6 +6,7 @@ import { BasicTxErrorType, StakingTxErrorType } from '@subwallet/extension-base/
6
6
  import { convertDerivativeToOriginToken } from '@subwallet/extension-base/koni/api/yield/helper/utils';
7
7
  import { YieldPoolType } from '@subwallet/extension-base/types';
8
8
  import { formatNumber } from '@subwallet/extension-base/utils';
9
+ import BigN from 'bignumber.js';
9
10
  import { t } from 'i18next';
10
11
  import { BN, BN_ZERO } from '@polkadot/util';
11
12
  import BaseSpecialStakingPoolHandler from "../special.js";
@@ -31,7 +32,7 @@ export default class BaseLiquidStakingPoolHandler extends BaseSpecialStakingPool
31
32
  return Promise.reject(new TransactionError(BasicTxErrorType.INVALID_PARAMS));
32
33
  }
33
34
  const formattedMinAmount = convertDerivativeToOriginToken(amount, poolInfo, derivativeTokenInfo, originTokenInfo);
34
- return Math.floor(this.minAmountPercent * formattedMinAmount);
35
+ return new BigN(formattedMinAmount).multipliedBy(this.minAmountPercent).toFixed(0);
35
36
  }
36
37
  async validateYieldLeave(amount, address, fastLeave, selectedTarget) {
37
38
  const poolInfo = await this.getPoolInfo();
@@ -0,0 +1,37 @@
1
+ import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
+ import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
3
+ import { BaseYieldStepDetail, HandleYieldStepData, LiquidYieldPoolInfo, OptimalYieldPath, SubmitYieldJoinData, TransactionData } from '@subwallet/extension-base/types';
4
+ import BifrostLiquidStakingPoolHandler from './bifrost';
5
+ export interface BifrostLiquidStakingMeta {
6
+ apy: string;
7
+ apyBase: string;
8
+ apyReward: string;
9
+ tvl: number;
10
+ tvm: number;
11
+ holders: number;
12
+ }
13
+ export interface BifrostVtokenExchangeRateResp {
14
+ ratio: BifrostVtokenExchangeRate[];
15
+ }
16
+ export interface BifrostVtokenExchangeRate {
17
+ ratio: string;
18
+ key: string;
19
+ timestamp: string;
20
+ total_issuance: number;
21
+ token_pool: number;
22
+ }
23
+ export default class BifrostMantaLiquidStakingPoolHandler extends BifrostLiquidStakingPoolHandler {
24
+ protected readonly altInputAsset: string;
25
+ protected readonly derivativeAssets: string[];
26
+ protected readonly inputAsset: string;
27
+ protected readonly rewardAssets: string[];
28
+ protected readonly feeAssets: string[];
29
+ readonly minAmountPercent: number;
30
+ constructor(state: KoniState, chain: string);
31
+ protected getDescription(): string;
32
+ getPoolStat(): Promise<LiquidYieldPoolInfo>;
33
+ get submitJoinStepInfo(): BaseYieldStepDetail;
34
+ handleSubmitStep(data: SubmitYieldJoinData, path: OptimalYieldPath): Promise<HandleYieldStepData>;
35
+ handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
36
+ handleYieldUnstake(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
37
+ }
@@ -0,0 +1,132 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
+ import { _getAssetDecimals, _getTokenOnChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
6
+ import { YieldStepType } from '@subwallet/extension-base/types';
7
+ import fetch from 'cross-fetch';
8
+ import BifrostLiquidStakingPoolHandler from "./bifrost.js";
9
+ const STATS_URL = 'https://api.bifrost.app/api/site';
10
+ const RATIO_URL = 'https://api.bifrost.app/api/omni/MANTA';
11
+ export default class BifrostMantaLiquidStakingPoolHandler extends BifrostLiquidStakingPoolHandler {
12
+ altInputAsset = 'manta_network-NATIVE-MANTA';
13
+ derivativeAssets = ['bifrost_dot-LOCAL-vMANTA'];
14
+ inputAsset = 'bifrost_dot-LOCAL-MANTA';
15
+ rewardAssets = ['bifrost_dot-LOCAL-MANTA'];
16
+ feeAssets = ['bifrost_dot-NATIVE-BNC', 'bifrost_dot-LOCAL-MANTA'];
17
+ minAmountPercent = 0.985;
18
+ constructor(state, chain) {
19
+ super(state, chain);
20
+ const chainInfo = this.chainInfo;
21
+ this.slug = `MANTA___liquid_staking___${chain}`;
22
+ this.name = `${chainInfo.name} Liquid Staking Manta`;
23
+ this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
24
+ }
25
+ getDescription() {
26
+ return 'Stake MANTA to earn yield on vMANTA';
27
+ }
28
+
29
+ /* Subscribe pool info */
30
+
31
+ async getPoolStat() {
32
+ const substrateApi = await this.substrateApi.isReady;
33
+ const stakingMetaPromise = new Promise(function (resolve) {
34
+ fetch(STATS_URL, {
35
+ method: 'GET'
36
+ }).then(res => {
37
+ resolve(res.json());
38
+ }).catch(console.error);
39
+ });
40
+ const exchangeRatePromise = new Promise(function (resolve) {
41
+ fetch(RATIO_URL, {
42
+ method: 'GET'
43
+ }).then(resp => {
44
+ resolve(resp.json());
45
+ }).catch(console.error);
46
+ });
47
+ const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
48
+ const inputTokenInfo = this.state.getAssetBySlug(this.inputAsset);
49
+ const [_stakingMeta, _exchangeRate, _minimumRedeem, _minimumMint] = await Promise.all([stakingMetaPromise, exchangeRatePromise, substrateApi.api.query.vtokenMinting.minimumRedeem(_getTokenOnChainInfo(derivativeTokenInfo)), substrateApi.api.query.vtokenMinting.minimumMint(_getTokenOnChainInfo(inputTokenInfo))]);
50
+ const minimumRedeem = _minimumRedeem.toString();
51
+ const minimumMint = _minimumMint.toString();
52
+ const stakingMeta = _stakingMeta;
53
+ const exchangeRate = _exchangeRate;
54
+ const vMANTAStats = stakingMeta.vMANTA;
55
+ const assetInfo = this.state.getAssetBySlug(this.inputAsset);
56
+ const assetDecimals = 10 ** _getAssetDecimals(assetInfo);
57
+ const rate = parseFloat(exchangeRate.ratio[exchangeRate.ratio.length - 1].ratio); // TODO
58
+
59
+ this.updateExchangeRate(rate);
60
+ return {
61
+ ...this.baseInfo,
62
+ type: this.type,
63
+ metadata: {
64
+ ...this.metadataInfo,
65
+ description: this.getDescription()
66
+ },
67
+ statistic: {
68
+ assetEarning: [{
69
+ slug: this.rewardAssets[0],
70
+ apy: parseFloat(vMANTAStats.apyBase),
71
+ exchangeRate: rate
72
+ }],
73
+ farmerCount: vMANTAStats.holders,
74
+ unstakingPeriod: 24 * 7,
75
+ maxCandidatePerFarmer: 1,
76
+ maxWithdrawalRequestPerFarmer: 1,
77
+ earningThreshold: {
78
+ join: minimumMint,
79
+ defaultUnstake: minimumRedeem,
80
+ fastUnstake: '0'
81
+ },
82
+ totalApy: parseFloat(vMANTAStats.apyBase),
83
+ tvl: (vMANTAStats.tvm * assetDecimals).toString()
84
+ }
85
+ };
86
+ }
87
+
88
+ /* Subscribe pool info */
89
+
90
+ /* Join pool action */
91
+
92
+ get submitJoinStepInfo() {
93
+ return {
94
+ name: 'Mint vMANTA',
95
+ type: YieldStepType.MINT_VMANTA
96
+ };
97
+ }
98
+ async handleSubmitStep(data, path) {
99
+ const substrateApi = await this.substrateApi.isReady;
100
+ const inputTokenSlug = this.inputAsset;
101
+ const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
102
+ const extrinsic = substrateApi.api.tx.vtokenMinting.mint(_getTokenOnChainInfo(inputTokenInfo), data.amount, undefined, undefined);
103
+ return {
104
+ txChain: this.chain,
105
+ extrinsicType: ExtrinsicType.MINT_VMANTA,
106
+ extrinsic,
107
+ txData: data,
108
+ transferNativeAmount: '0',
109
+ chainType: ChainType.SUBSTRATE
110
+ };
111
+ }
112
+
113
+ /* Join pool action */
114
+
115
+ /* Leave pool action */
116
+
117
+ async handleYieldRedeem(amount, address, selectedTarget) {
118
+ const substrateApi = await this.substrateApi.isReady;
119
+ const weightedMinAmount = await this.createParamToRedeem(amount, address);
120
+ const extrinsic = substrateApi.api.tx.stablePool.swap(5, 1, 0, amount, weightedMinAmount);
121
+ return [ExtrinsicType.REDEEM_VMANTA, extrinsic];
122
+ }
123
+ async handleYieldUnstake(amount, address, selectedTarget) {
124
+ const chainApi = await this.substrateApi.isReady;
125
+ const derivativeTokenSlug = this.derivativeAssets[0];
126
+ const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
127
+ const extrinsic = chainApi.api.tx.vtokenMinting.redeem(_getTokenOnChainInfo(derivativeTokenInfo), amount);
128
+ return [ExtrinsicType.UNSTAKE_VMANTA, extrinsic];
129
+ }
130
+
131
+ /* Leave pool action */
132
+ }
@@ -24,14 +24,14 @@ export interface BifrostVtokenExchangeRate {
24
24
  }
25
25
  export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPoolHandler {
26
26
  slug: string;
27
- protected readonly name: string;
28
- protected readonly shortName: string;
27
+ protected name: string;
28
+ protected shortName: string;
29
29
  protected readonly altInputAsset: string;
30
30
  protected readonly derivativeAssets: string[];
31
31
  protected readonly inputAsset: string;
32
32
  protected readonly rewardAssets: string[];
33
33
  protected readonly feeAssets: string[];
34
- readonly minAmountPercent = 0.99;
34
+ readonly minAmountPercent: number;
35
35
  protected readonly availableMethod: YieldPoolMethodInfo;
36
36
  protected readonly rateDecimals = 0;
37
37
  constructor(state: KoniState, chain: string);
@@ -34,7 +34,7 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
34
34
  super(state, chain);
35
35
  const chainInfo = this.chainInfo;
36
36
  this.slug = `DOT___liquid_staking___${chain}`;
37
- this.name = `${chainInfo.name} Liquid Staking`;
37
+ this.name = `${chainInfo.name} Liquid Staking DOT`;
38
38
  this.shortName = chainInfo.name.replaceAll(' Relay Chain', '');
39
39
  }
40
40
  getDescription() {
@@ -93,6 +93,7 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
93
93
  unstakingPeriod: 24 * 28,
94
94
  maxCandidatePerFarmer: 1,
95
95
  maxWithdrawalRequestPerFarmer: 1,
96
+ farmerCount: vDOTStats.holders,
96
97
  earningThreshold: {
97
98
  join: minimumMint,
98
99
  defaultUnstake: minimumRedeem,
@@ -1,4 +1,5 @@
1
1
  export { default as AcalaLiquidStakingPoolHandler } from './acala';
2
2
  export { default as BifrostLiquidStakingPoolHandler } from './bifrost';
3
+ export { default as BifrostMantaLiquidStakingPoolHandler } from './bifrost-manta';
3
4
  export { default as ParallelLiquidStakingPoolHandler } from './parallel';
4
5
  export { default as StellaSwapLiquidStakingPoolHandler } from './stella-swap';
@@ -3,5 +3,6 @@
3
3
 
4
4
  export { default as AcalaLiquidStakingPoolHandler } from "./acala.js";
5
5
  export { default as BifrostLiquidStakingPoolHandler } from "./bifrost.js";
6
+ export { default as BifrostMantaLiquidStakingPoolHandler } from "./bifrost-manta.js";
6
7
  export { default as ParallelLiquidStakingPoolHandler } from "./parallel.js";
7
8
  export { default as StellaSwapLiquidStakingPoolHandler } from "./stella-swap.js";
@@ -38,9 +38,9 @@ export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakin
38
38
  constructor(state, chain) {
39
39
  super(state, chain);
40
40
  this.slug = 'xcDOT___liquid_staking___stellaswap';
41
- this.name = 'Stellaswap Liquid Staking';
41
+ this.name = 'StellaSwap Liquid Staking';
42
42
  this._logo = 'stellaswap';
43
- this.shortName = 'Stellaswap';
43
+ this.shortName = 'StellaSwap';
44
44
  }
45
45
  getDescription() {
46
46
  return 'Earn rewards by staking xcDOT for stDOT';