Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a17833462 | ||
|
|
c6652baa7c |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tx-manager",
|
"name": "tx-manager",
|
||||||
"version": "0.4.0",
|
"version": "0.4.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async-mutex": "^0.2.4",
|
"async-mutex": "^0.2.4",
|
||||||
"ethers": "^5.4.6",
|
"ethers": "^5.4.6",
|
||||||
"gas-price-oracle": "^0.3.5",
|
"gas-price-oracle": "^0.4.0",
|
||||||
"web3-core-promievent": "^1.3.0"
|
"web3-core-promievent": "^1.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -409,28 +409,6 @@ class Transaction {
|
|||||||
return this._wallet.getTransactionCount('latest')
|
return this._wallet.getTransactionCount('latest')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches baseFee from chain and calculate fee params
|
|
||||||
*
|
|
||||||
* @returns {Promise<object>}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
async _estimateFees() {
|
|
||||||
const block = await this._provider.getBlock('latest')
|
|
||||||
|
|
||||||
let maxFeePerGas = null,
|
|
||||||
maxPriorityFeePerGas = null
|
|
||||||
|
|
||||||
if (block && block.baseFeePerGas) {
|
|
||||||
maxPriorityFeePerGas = parseUnits(this.config.PRIORITY_FEE_GWEI.toString(), 'gwei')
|
|
||||||
maxFeePerGas = block.baseFeePerGas
|
|
||||||
.mul(100 + this.config.BASE_FEE_RESERVE_PERCENTAGE)
|
|
||||||
.div(100)
|
|
||||||
.add(maxPriorityFeePerGas)
|
|
||||||
}
|
|
||||||
return { maxFeePerGas, maxPriorityFeePerGas }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Choose network gas params
|
* Choose network gas params
|
||||||
*
|
*
|
||||||
@@ -438,15 +416,19 @@ class Transaction {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _getGasParams() {
|
async _getGasParams() {
|
||||||
const { maxFeePerGas, maxPriorityFeePerGas } = await this._estimateFees()
|
|
||||||
|
|
||||||
const maxGasPrice = parseUnits(this.config.MAX_GAS_PRICE.toString(), 'gwei')
|
const maxGasPrice = parseUnits(this.config.MAX_GAS_PRICE.toString(), 'gwei')
|
||||||
|
const block = await this._provider.getBlock('latest')
|
||||||
|
|
||||||
// Check network support for EIP-1559
|
// Check network support for EIP-1559
|
||||||
if (maxFeePerGas && maxPriorityFeePerGas) {
|
if (block && block.baseFeePerGas) {
|
||||||
|
const maxPriorityFeePerGas = parseUnits(this.config.PRIORITY_FEE_GWEI.toString(), 'gwei')
|
||||||
|
const maxFeePerGas = block.baseFeePerGas
|
||||||
|
.mul(100 + this.config.BASE_FEE_RESERVE_PERCENTAGE)
|
||||||
|
.div(100)
|
||||||
|
.add(maxPriorityFeePerGas)
|
||||||
return {
|
return {
|
||||||
maxFeePerGas: min(maxFeePerGas, maxGasPrice).toHexString(),
|
maxFeePerGas: min(maxFeePerGas, maxGasPrice).toHexString(),
|
||||||
maxPriorityFeePerGas: maxPriorityFeePerGas.toHexString(),
|
maxPriorityFeePerGas: min(maxPriorityFeePerGas, maxGasPrice).toHexString(),
|
||||||
type: 2,
|
type: 2,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1065,10 +1065,10 @@ functional-red-black-tree@^1.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
|
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
|
||||||
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=
|
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=
|
||||||
|
|
||||||
gas-price-oracle@^0.3.5:
|
gas-price-oracle@^0.4.0:
|
||||||
version "0.3.5"
|
version "0.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/gas-price-oracle/-/gas-price-oracle-0.3.5.tgz#b7bff364e37fb7f30a2297cb65be80fceb4b8da3"
|
resolved "https://registry.yarnpkg.com/gas-price-oracle/-/gas-price-oracle-0.4.0.tgz#1b8426bce92ebcff6cc98a0c5638769cb22417b1"
|
||||||
integrity sha512-9NAKzmGgWLjGUc4XsqNJjh0JXthETucijNrkV47FrZIjP8YMzq4jhBvlNeMBt6VVGnr64qjIY2RWb+In7qNsFA==
|
integrity sha512-5ct4VwTqTigD1V3EvUn513e41OIA+/Ubw0FITVfarw7AjVpg4LQSt9anRt+LcDU4+u+eMUEA3VP0VnvMN8nybA==
|
||||||
dependencies:
|
dependencies:
|
||||||
axios "^0.19.2"
|
axios "^0.19.2"
|
||||||
bignumber.js "^9.0.0"
|
bignumber.js "^9.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user