@subwallet/extension-base 1.1.37-0 → 1.1.38-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/koni/api/tokens/evm/transfer.js +1 -2
- package/cjs/koni/background/handlers/Extension.js +1 -2
- package/cjs/koni/background/handlers/State.js +16 -7
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/transaction-service/index.js +2 -2
- package/cjs/utils/eth.js +58 -19
- package/koni/api/tokens/evm/transfer.js +1 -2
- package/koni/background/handlers/Extension.js +1 -2
- package/koni/background/handlers/State.js +16 -7
- package/package.json +6 -6
- package/packageInfo.js +1 -1
- package/services/transaction-service/index.js +2 -2
- package/utils/eth.d.ts +6 -6
- package/utils/eth.js +58 -19
|
@@ -63,8 +63,7 @@ async function getEVMTransactionObject(chainInfo, from, to, value, transferAll,
|
|
|
63
63
|
transactionObject.gas = gasLimit;
|
|
64
64
|
let estimateFee;
|
|
65
65
|
if (priority.baseGasFee) {
|
|
66
|
-
const
|
|
67
|
-
const maxFee = priority.maxFeePerGas.gte(priorityFee) ? priority.maxFeePerGas : priorityFee;
|
|
66
|
+
const maxFee = priority.maxFeePerGas;
|
|
68
67
|
estimateFee = maxFee.multipliedBy(gasLimit);
|
|
69
68
|
} else {
|
|
70
69
|
estimateFee = new _bignumber.default(priority.gasPrice).multipliedBy(gasLimit);
|
|
@@ -1941,8 +1941,7 @@ class KoniExtension {
|
|
|
1941
1941
|
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
1942
1942
|
const priority = await (0, _eth.calculateGasFeeParams)(web3, networkKey);
|
|
1943
1943
|
if (priority.baseGasFee) {
|
|
1944
|
-
const
|
|
1945
|
-
const maxFee = priority.maxFeePerGas.gte(priorityFee) ? priority.maxFeePerGas : priorityFee;
|
|
1944
|
+
const maxFee = priority.maxFeePerGas;
|
|
1946
1945
|
estimatedFee = maxFee.multipliedBy(gasLimit).toFixed(0);
|
|
1947
1946
|
} else {
|
|
1948
1947
|
estimatedFee = new _bignumber.default(priority.gasPrice).multipliedBy(gasLimit).toFixed(0);
|
|
@@ -1262,16 +1262,25 @@ class KoniState {
|
|
|
1262
1262
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1263
1263
|
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
|
|
1264
1264
|
}
|
|
1265
|
-
const priority = await (0, _eth.calculateGasFeeParams)(evmApi, networkKey);
|
|
1266
1265
|
let estimateGas;
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
const
|
|
1271
|
-
const maxFee = priority.maxFeePerGas.lte(priorityFee) ? priority.maxFeePerGas : priorityFee;
|
|
1266
|
+
|
|
1267
|
+
// TODO: Review, If not override, transaction maybe fail because fee too low
|
|
1268
|
+
if (transactionParams.maxPriorityFeePerGas && transactionParams.maxFeePerGas) {
|
|
1269
|
+
const maxFee = new _bignumber.default(transactionParams.maxFeePerGas);
|
|
1272
1270
|
estimateGas = maxFee.multipliedBy(transaction.gas).toFixed(0);
|
|
1271
|
+
} else if (transactionParams.gasPrice) {
|
|
1272
|
+
estimateGas = new _bignumber.default(transactionParams.gasPrice).multipliedBy(transaction.gas).toFixed(0);
|
|
1273
1273
|
} else {
|
|
1274
|
-
|
|
1274
|
+
const priority = await (0, _eth.calculateGasFeeParams)(evmApi, networkKey);
|
|
1275
|
+
if (priority.baseGasFee) {
|
|
1276
|
+
transaction.maxPriorityFeePerGas = priority.maxPriorityFeePerGas.toString();
|
|
1277
|
+
transaction.maxFeePerGas = priority.maxFeePerGas.toString();
|
|
1278
|
+
const maxFee = priority.maxFeePerGas;
|
|
1279
|
+
estimateGas = maxFee.multipliedBy(transaction.gas).toFixed(0);
|
|
1280
|
+
} else {
|
|
1281
|
+
transaction.gasPrice = priority.gasPrice;
|
|
1282
|
+
estimateGas = new _bignumber.default(priority.gasPrice).multipliedBy(transaction.gas).toFixed(0);
|
|
1283
|
+
}
|
|
1275
1284
|
}
|
|
1276
1285
|
|
|
1277
1286
|
// Address is validated in before step
|
package/cjs/packageInfo.js
CHANGED
|
@@ -126,8 +126,8 @@ class TransactionService {
|
|
|
126
126
|
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
127
127
|
const priority = await (0, _eth.calculateGasFeeParams)(web3, chainInfo.slug);
|
|
128
128
|
if (priority.baseGasFee) {
|
|
129
|
-
const
|
|
130
|
-
|
|
129
|
+
const maxFee = priority.maxFeePerGas; // TODO: Need review
|
|
130
|
+
|
|
131
131
|
estimateFee.value = maxFee.multipliedBy(gasLimit).toFixed(0);
|
|
132
132
|
} else {
|
|
133
133
|
estimateFee.value = new _bignumber.default(priority.gasPrice).multipliedBy(gasLimit).toFixed(0);
|
package/cjs/utils/eth.js
CHANGED
|
@@ -80,44 +80,83 @@ exports.recalculateGasPrice = recalculateGasPrice;
|
|
|
80
80
|
const calculateGasFeeParams = async (web3, networkKey) => {
|
|
81
81
|
try {
|
|
82
82
|
const numBlock = 20;
|
|
83
|
-
const
|
|
83
|
+
const rewardPercent = [];
|
|
84
|
+
for (let i = 0; i <= 100; i = i + 5) {
|
|
85
|
+
rewardPercent.push(i);
|
|
86
|
+
}
|
|
87
|
+
const history = await web3.api.eth.getFeeHistory(numBlock, 'latest', rewardPercent);
|
|
84
88
|
const baseGasFee = new _bignumber.default(history.baseFeePerGas[history.baseFeePerGas.length - 1]); // Last element is latest
|
|
85
89
|
|
|
86
90
|
const blocksBusy = history.reward.reduce((previous, rewards, currentIndex) => {
|
|
87
|
-
const [
|
|
91
|
+
const [firstPriority] = rewards;
|
|
88
92
|
const base = history.baseFeePerGas[currentIndex];
|
|
89
|
-
const priorityBN = new _bignumber.default(
|
|
93
|
+
const priorityBN = new _bignumber.default(firstPriority);
|
|
90
94
|
const baseBN = new _bignumber.default(base);
|
|
91
|
-
|
|
95
|
+
|
|
96
|
+
/*
|
|
97
|
+
* True if priority >= 0.3 * base
|
|
98
|
+
* */
|
|
99
|
+
const blockIsBusy = baseBN.gt(_number.BN_ZERO) ? priorityBN.dividedBy(baseBN).gte(0.3) ? 1 : 0 : 0; // Special for bsc, base fee = 0
|
|
92
100
|
|
|
93
101
|
return previous + blockIsBusy;
|
|
94
102
|
}, 0);
|
|
95
|
-
const busyNetwork = blocksBusy >= numBlock / 2; // True if half of block is busy
|
|
103
|
+
const busyNetwork = blocksBusy >= numBlock / 2; // True, if half of block is busy
|
|
96
104
|
|
|
97
|
-
const maxPriorityFeePerGas = history.reward.reduce((previous, rewards
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const firstBN = new _bignumber.default(first);
|
|
101
|
-
const secondBN = new _bignumber.default(second);
|
|
102
|
-
const baseBN = new _bignumber.default(base);
|
|
105
|
+
const maxPriorityFeePerGas = history.reward.reduce((previous, rewards) => {
|
|
106
|
+
let firstBN = _number.BN_ZERO;
|
|
107
|
+
let firstIndex = 0;
|
|
103
108
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
/* Get first priority which greater than 0 */
|
|
110
|
+
for (let i = 0; i < rewards.length; i++) {
|
|
111
|
+
firstIndex = i;
|
|
112
|
+
const current = rewards[i];
|
|
113
|
+
const currentBN = new _bignumber.default(current);
|
|
114
|
+
if (currentBN.gt(_number.BN_ZERO)) {
|
|
115
|
+
firstBN = currentBN;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
108
118
|
}
|
|
119
|
+
let secondBN = firstBN;
|
|
109
120
|
|
|
121
|
+
/* Get second priority which greater than first priority */
|
|
122
|
+
for (let i = firstIndex; i < rewards.length; i++) {
|
|
123
|
+
const current = rewards[i];
|
|
124
|
+
const currentBN = new _bignumber.default(current);
|
|
125
|
+
if (currentBN.gt(firstBN)) {
|
|
126
|
+
secondBN = currentBN;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
let current;
|
|
110
131
|
if (busyNetwork) {
|
|
111
|
-
|
|
112
|
-
|
|
132
|
+
current = secondBN.dividedBy(2).gte(firstBN) ? firstBN : secondBN; // second too larger than first (> 2 times), use first else use second
|
|
133
|
+
} else {
|
|
134
|
+
current = firstBN;
|
|
135
|
+
}
|
|
136
|
+
if (busyNetwork) {
|
|
137
|
+
/* Get max value */
|
|
113
138
|
return current.gte(previous) ? current : previous; // get max priority
|
|
114
139
|
} else {
|
|
115
|
-
|
|
140
|
+
/* Get min value which greater than 0 */
|
|
141
|
+
if (previous.eq(_number.BN_ZERO)) {
|
|
142
|
+
return current; // get min priority
|
|
143
|
+
} else if (current.eq(_number.BN_ZERO)) {
|
|
144
|
+
return previous;
|
|
145
|
+
}
|
|
116
146
|
return current.lte(previous) ? current : previous; // get min priority
|
|
117
147
|
}
|
|
118
148
|
}, _number.BN_ZERO);
|
|
119
|
-
|
|
149
|
+
if (maxPriorityFeePerGas.eq(_number.BN_ZERO)) {
|
|
150
|
+
const _price = await web3.api.eth.getGasPrice();
|
|
151
|
+
const gasPrice = recalculateGasPrice(_price, networkKey);
|
|
152
|
+
return {
|
|
153
|
+
gasPrice,
|
|
154
|
+
busyNetwork: false
|
|
155
|
+
};
|
|
156
|
+
}
|
|
120
157
|
|
|
158
|
+
/* Max gas = (base + priority) * 1.5 (if not busy or 2 when busy); */
|
|
159
|
+
const maxFeePerGas = baseGasFee.plus(maxPriorityFeePerGas).multipliedBy(busyNetwork ? 2 : 1.5).decimalPlaces(0);
|
|
121
160
|
return {
|
|
122
161
|
maxFeePerGas,
|
|
123
162
|
maxPriorityFeePerGas,
|
|
@@ -51,8 +51,7 @@ export async function getEVMTransactionObject(chainInfo, from, to, value, transf
|
|
|
51
51
|
transactionObject.gas = gasLimit;
|
|
52
52
|
let estimateFee;
|
|
53
53
|
if (priority.baseGasFee) {
|
|
54
|
-
const
|
|
55
|
-
const maxFee = priority.maxFeePerGas.gte(priorityFee) ? priority.maxFeePerGas : priorityFee;
|
|
54
|
+
const maxFee = priority.maxFeePerGas;
|
|
56
55
|
estimateFee = maxFee.multipliedBy(gasLimit);
|
|
57
56
|
} else {
|
|
58
57
|
estimateFee = new BigN(priority.gasPrice).multipliedBy(gasLimit);
|
|
@@ -1883,8 +1883,7 @@ export default class KoniExtension {
|
|
|
1883
1883
|
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
1884
1884
|
const priority = await calculateGasFeeParams(web3, networkKey);
|
|
1885
1885
|
if (priority.baseGasFee) {
|
|
1886
|
-
const
|
|
1887
|
-
const maxFee = priority.maxFeePerGas.gte(priorityFee) ? priority.maxFeePerGas : priorityFee;
|
|
1886
|
+
const maxFee = priority.maxFeePerGas;
|
|
1888
1887
|
estimatedFee = maxFee.multipliedBy(gasLimit).toFixed(0);
|
|
1889
1888
|
} else {
|
|
1890
1889
|
estimatedFee = new BigN(priority.gasPrice).multipliedBy(gasLimit).toFixed(0);
|
|
@@ -1240,16 +1240,25 @@ export default class KoniState {
|
|
|
1240
1240
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1241
1241
|
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, e === null || e === void 0 ? void 0 : e.message);
|
|
1242
1242
|
}
|
|
1243
|
-
const priority = await calculateGasFeeParams(evmApi, networkKey);
|
|
1244
1243
|
let estimateGas;
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
const
|
|
1249
|
-
const maxFee = priority.maxFeePerGas.lte(priorityFee) ? priority.maxFeePerGas : priorityFee;
|
|
1244
|
+
|
|
1245
|
+
// TODO: Review, If not override, transaction maybe fail because fee too low
|
|
1246
|
+
if (transactionParams.maxPriorityFeePerGas && transactionParams.maxFeePerGas) {
|
|
1247
|
+
const maxFee = new BigN(transactionParams.maxFeePerGas);
|
|
1250
1248
|
estimateGas = maxFee.multipliedBy(transaction.gas).toFixed(0);
|
|
1249
|
+
} else if (transactionParams.gasPrice) {
|
|
1250
|
+
estimateGas = new BigN(transactionParams.gasPrice).multipliedBy(transaction.gas).toFixed(0);
|
|
1251
1251
|
} else {
|
|
1252
|
-
|
|
1252
|
+
const priority = await calculateGasFeeParams(evmApi, networkKey);
|
|
1253
|
+
if (priority.baseGasFee) {
|
|
1254
|
+
transaction.maxPriorityFeePerGas = priority.maxPriorityFeePerGas.toString();
|
|
1255
|
+
transaction.maxFeePerGas = priority.maxFeePerGas.toString();
|
|
1256
|
+
const maxFee = priority.maxFeePerGas;
|
|
1257
|
+
estimateGas = maxFee.multipliedBy(transaction.gas).toFixed(0);
|
|
1258
|
+
} else {
|
|
1259
|
+
transaction.gasPrice = priority.gasPrice;
|
|
1260
|
+
estimateGas = new BigN(priority.gasPrice).multipliedBy(transaction.gas).toFixed(0);
|
|
1261
|
+
}
|
|
1253
1262
|
}
|
|
1254
1263
|
|
|
1255
1264
|
// Address is validated in before step
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.1.
|
|
20
|
+
"version": "1.1.38-1",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -1736,11 +1736,11 @@
|
|
|
1736
1736
|
"@reduxjs/toolkit": "^1.9.1",
|
|
1737
1737
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1738
1738
|
"@substrate/connect": "^0.7.26",
|
|
1739
|
-
"@subwallet/chain-list": "0.2.
|
|
1740
|
-
"@subwallet/extension-base": "^1.1.
|
|
1741
|
-
"@subwallet/extension-chains": "^1.1.
|
|
1742
|
-
"@subwallet/extension-dapp": "^1.1.
|
|
1743
|
-
"@subwallet/extension-inject": "^1.1.
|
|
1739
|
+
"@subwallet/chain-list": "0.2.41",
|
|
1740
|
+
"@subwallet/extension-base": "^1.1.38-1",
|
|
1741
|
+
"@subwallet/extension-chains": "^1.1.38-1",
|
|
1742
|
+
"@subwallet/extension-dapp": "^1.1.38-1",
|
|
1743
|
+
"@subwallet/extension-inject": "^1.1.38-1",
|
|
1744
1744
|
"@subwallet/keyring": "^0.1.3",
|
|
1745
1745
|
"@subwallet/ui-keyring": "^0.1.3",
|
|
1746
1746
|
"@walletconnect/sign-client": "^2.8.4",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.1.
|
|
10
|
+
version: '1.1.38-1'
|
|
11
11
|
};
|
|
@@ -119,8 +119,8 @@ export default class TransactionService {
|
|
|
119
119
|
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
120
120
|
const priority = await calculateGasFeeParams(web3, chainInfo.slug);
|
|
121
121
|
if (priority.baseGasFee) {
|
|
122
|
-
const
|
|
123
|
-
|
|
122
|
+
const maxFee = priority.maxFeePerGas; // TODO: Need review
|
|
123
|
+
|
|
124
124
|
estimateFee.value = maxFee.multipliedBy(gasLimit).toFixed(0);
|
|
125
125
|
} else {
|
|
126
126
|
estimateFee.value = new BigN(priority.gasPrice).multipliedBy(gasLimit).toFixed(0);
|
package/utils/eth.d.ts
CHANGED
|
@@ -18,15 +18,15 @@ export declare const createTransactionFromRLP: (rlp: string) => Transaction | nu
|
|
|
18
18
|
export declare const signatureToHex: (sig: SignedTransaction) => string;
|
|
19
19
|
export declare const recalculateGasPrice: (_price: string, chain: string) => string;
|
|
20
20
|
export declare const calculateGasFeeParams: (web3: _EvmApi, networkKey: string) => Promise<{
|
|
21
|
-
maxFeePerGas: BigN;
|
|
22
|
-
maxPriorityFeePerGas: BigN;
|
|
23
|
-
baseGasFee: BigN;
|
|
24
|
-
busyNetwork: boolean;
|
|
25
|
-
gasPrice?: undefined;
|
|
26
|
-
} | {
|
|
27
21
|
gasPrice: string;
|
|
28
22
|
busyNetwork: boolean;
|
|
29
23
|
maxFeePerGas?: undefined;
|
|
30
24
|
maxPriorityFeePerGas?: undefined;
|
|
31
25
|
baseGasFee?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
maxFeePerGas: BigN;
|
|
28
|
+
maxPriorityFeePerGas: BigN;
|
|
29
|
+
baseGasFee: BigN;
|
|
30
|
+
busyNetwork: boolean;
|
|
31
|
+
gasPrice?: undefined;
|
|
32
32
|
}>;
|
package/utils/eth.js
CHANGED
|
@@ -68,44 +68,83 @@ export const recalculateGasPrice = (_price, chain) => {
|
|
|
68
68
|
export const calculateGasFeeParams = async (web3, networkKey) => {
|
|
69
69
|
try {
|
|
70
70
|
const numBlock = 20;
|
|
71
|
-
const
|
|
71
|
+
const rewardPercent = [];
|
|
72
|
+
for (let i = 0; i <= 100; i = i + 5) {
|
|
73
|
+
rewardPercent.push(i);
|
|
74
|
+
}
|
|
75
|
+
const history = await web3.api.eth.getFeeHistory(numBlock, 'latest', rewardPercent);
|
|
72
76
|
const baseGasFee = new BigN(history.baseFeePerGas[history.baseFeePerGas.length - 1]); // Last element is latest
|
|
73
77
|
|
|
74
78
|
const blocksBusy = history.reward.reduce((previous, rewards, currentIndex) => {
|
|
75
|
-
const [
|
|
79
|
+
const [firstPriority] = rewards;
|
|
76
80
|
const base = history.baseFeePerGas[currentIndex];
|
|
77
|
-
const priorityBN = new BigN(
|
|
81
|
+
const priorityBN = new BigN(firstPriority);
|
|
78
82
|
const baseBN = new BigN(base);
|
|
79
|
-
|
|
83
|
+
|
|
84
|
+
/*
|
|
85
|
+
* True if priority >= 0.3 * base
|
|
86
|
+
* */
|
|
87
|
+
const blockIsBusy = baseBN.gt(BN_ZERO) ? priorityBN.dividedBy(baseBN).gte(0.3) ? 1 : 0 : 0; // Special for bsc, base fee = 0
|
|
80
88
|
|
|
81
89
|
return previous + blockIsBusy;
|
|
82
90
|
}, 0);
|
|
83
|
-
const busyNetwork = blocksBusy >= numBlock / 2; // True if half of block is busy
|
|
91
|
+
const busyNetwork = blocksBusy >= numBlock / 2; // True, if half of block is busy
|
|
84
92
|
|
|
85
|
-
const maxPriorityFeePerGas = history.reward.reduce((previous, rewards
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const firstBN = new BigN(first);
|
|
89
|
-
const secondBN = new BigN(second);
|
|
90
|
-
const baseBN = new BigN(base);
|
|
93
|
+
const maxPriorityFeePerGas = history.reward.reduce((previous, rewards) => {
|
|
94
|
+
let firstBN = BN_ZERO;
|
|
95
|
+
let firstIndex = 0;
|
|
91
96
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
/* Get first priority which greater than 0 */
|
|
98
|
+
for (let i = 0; i < rewards.length; i++) {
|
|
99
|
+
firstIndex = i;
|
|
100
|
+
const current = rewards[i];
|
|
101
|
+
const currentBN = new BigN(current);
|
|
102
|
+
if (currentBN.gt(BN_ZERO)) {
|
|
103
|
+
firstBN = currentBN;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
96
106
|
}
|
|
107
|
+
let secondBN = firstBN;
|
|
97
108
|
|
|
109
|
+
/* Get second priority which greater than first priority */
|
|
110
|
+
for (let i = firstIndex; i < rewards.length; i++) {
|
|
111
|
+
const current = rewards[i];
|
|
112
|
+
const currentBN = new BigN(current);
|
|
113
|
+
if (currentBN.gt(firstBN)) {
|
|
114
|
+
secondBN = currentBN;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
let current;
|
|
98
119
|
if (busyNetwork) {
|
|
99
|
-
|
|
100
|
-
|
|
120
|
+
current = secondBN.dividedBy(2).gte(firstBN) ? firstBN : secondBN; // second too larger than first (> 2 times), use first else use second
|
|
121
|
+
} else {
|
|
122
|
+
current = firstBN;
|
|
123
|
+
}
|
|
124
|
+
if (busyNetwork) {
|
|
125
|
+
/* Get max value */
|
|
101
126
|
return current.gte(previous) ? current : previous; // get max priority
|
|
102
127
|
} else {
|
|
103
|
-
|
|
128
|
+
/* Get min value which greater than 0 */
|
|
129
|
+
if (previous.eq(BN_ZERO)) {
|
|
130
|
+
return current; // get min priority
|
|
131
|
+
} else if (current.eq(BN_ZERO)) {
|
|
132
|
+
return previous;
|
|
133
|
+
}
|
|
104
134
|
return current.lte(previous) ? current : previous; // get min priority
|
|
105
135
|
}
|
|
106
136
|
}, BN_ZERO);
|
|
107
|
-
|
|
137
|
+
if (maxPriorityFeePerGas.eq(BN_ZERO)) {
|
|
138
|
+
const _price = await web3.api.eth.getGasPrice();
|
|
139
|
+
const gasPrice = recalculateGasPrice(_price, networkKey);
|
|
140
|
+
return {
|
|
141
|
+
gasPrice,
|
|
142
|
+
busyNetwork: false
|
|
143
|
+
};
|
|
144
|
+
}
|
|
108
145
|
|
|
146
|
+
/* Max gas = (base + priority) * 1.5 (if not busy or 2 when busy); */
|
|
147
|
+
const maxFeePerGas = baseGasFee.plus(maxPriorityFeePerGas).multipliedBy(busyNetwork ? 2 : 1.5).decimalPlaces(0);
|
|
109
148
|
return {
|
|
110
149
|
maxFeePerGas,
|
|
111
150
|
maxPriorityFeePerGas,
|