fix: configure EIP-1559 feature

This commit is contained in:
Danil Kovtonyuk 2022-05-11 23:24:39 +10:00
parent fe1ae90f79
commit 34ac05d87f
No known key found for this signature in database
GPG Key ID: E72A919BF08C3746
3 changed files with 38 additions and 9 deletions

View File

@ -465,7 +465,7 @@ class Transaction {
const block = await this._provider.getBlock('latest')
// Check network support for EIP-1559
if (block && block.baseFeePerGas) {
if (this.config.ENABLE_EIP1559 && block && block.baseFeePerGas) {
const maxPriorityFeePerGas = await this._estimatePriorityFee(block.number)
const maxFeePerGas = block.baseFeePerGas

View File

@ -15,6 +15,7 @@ const defaultConfig = {
ESTIMATE_GAS: true,
THROW_ON_REVERT: true,
BLOCK_GAS_LIMIT: null,
ENABLE_EIP1559: true,
PRIORITY_FEE_GWEI: 3,
BASE_FEE_RESERVE_PERCENTAGE: 50,
}

View File

@ -1,19 +1,13 @@
require('dotenv').config()
require('chai').should()
const { providers } = require('ethers')
const { parseUnits } = require('ethers').utils
const TxManager = require('../src/TxManager')
// const Transaction = require('../src/Transaction')
const { RPC_URL, PRIVATE_KEY } = process.env
describe('TxManager', () => {
const manager = new TxManager({
privateKey: PRIVATE_KEY,
rpcUrl: RPC_URL,
config: {
CONFIRMATIONS: 1,
GAS_BUMP_INTERVAL: 1000 * 20,
},
})
let manager
const tx1 = {
value: 1,
@ -45,6 +39,26 @@ describe('TxManager', () => {
type: 2,
}
before(async () => {
const provider = new providers.JsonRpcProvider(RPC_URL)
const { name, chainId } = await provider.getNetwork()
console.log('\n\n', 'network', { name, chainId }, '\n\n')
manager = new TxManager({
privateKey: PRIVATE_KEY,
rpcUrl: RPC_URL,
config: {
CONFIRMATIONS: 1,
GAS_BUMP_INTERVAL: 1000 * 20,
},
gasPriceOracleConfig: {
chainId: chainId,
defaultRpc: RPC_URL,
},
})
})
describe('#transaction', () => {
it('should work legacy tx', async () => {
const tx = manager.createTx(tx1)
@ -138,6 +152,20 @@ describe('TxManager', () => {
console.log('receipt', receipt)
})
it('should disable eip-1559 transactions', async () => {
manager.config.ENABLE_EIP1559 = false
const tx = manager.createTx(tx3)
const receipt = await tx
.send()
.on('transactionHash', hash => console.log('hash', hash))
.on('mined', receipt => console.log('Mined in block', receipt.blockNumber))
.on('confirmations', confirmations => console.log('confirmations', confirmations))
console.log('receipt', receipt)
manager.config.ENABLE_EIP1559 = true
})
it('should send multiple txs', async () => {
const genTx = value => ({
value,