fix: configure EIP-1559 feature
This commit is contained in:
parent
6adf89472e
commit
eaaa54b7f9
@ -465,7 +465,7 @@ class Transaction {
|
|||||||
const block = await this._provider.getBlock('latest')
|
const block = await this._provider.getBlock('latest')
|
||||||
|
|
||||||
// Check network support for EIP-1559
|
// 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 maxPriorityFeePerGas = await this._estimatePriorityFee(block.number)
|
||||||
|
|
||||||
const maxFeePerGas = block.baseFeePerGas
|
const maxFeePerGas = block.baseFeePerGas
|
||||||
|
@ -15,6 +15,7 @@ const defaultConfig = {
|
|||||||
ESTIMATE_GAS: true,
|
ESTIMATE_GAS: true,
|
||||||
THROW_ON_REVERT: true,
|
THROW_ON_REVERT: true,
|
||||||
BLOCK_GAS_LIMIT: null,
|
BLOCK_GAS_LIMIT: null,
|
||||||
|
ENABLE_EIP1559: true,
|
||||||
PRIORITY_FEE_GWEI: 3,
|
PRIORITY_FEE_GWEI: 3,
|
||||||
BASE_FEE_RESERVE_PERCENTAGE: 50,
|
BASE_FEE_RESERVE_PERCENTAGE: 50,
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,13 @@
|
|||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
require('chai').should()
|
require('chai').should()
|
||||||
|
const { providers } = require('ethers')
|
||||||
const { parseUnits } = require('ethers').utils
|
const { parseUnits } = require('ethers').utils
|
||||||
const TxManager = require('../src/TxManager')
|
const TxManager = require('../src/TxManager')
|
||||||
// const Transaction = require('../src/Transaction')
|
// const Transaction = require('../src/Transaction')
|
||||||
const { RPC_URL, PRIVATE_KEY } = process.env
|
const { RPC_URL, PRIVATE_KEY } = process.env
|
||||||
|
|
||||||
describe('TxManager', () => {
|
describe('TxManager', () => {
|
||||||
const manager = new TxManager({
|
let manager
|
||||||
privateKey: PRIVATE_KEY,
|
|
||||||
rpcUrl: RPC_URL,
|
|
||||||
config: {
|
|
||||||
CONFIRMATIONS: 1,
|
|
||||||
GAS_BUMP_INTERVAL: 1000 * 20,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const tx1 = {
|
const tx1 = {
|
||||||
value: 1,
|
value: 1,
|
||||||
@ -45,6 +39,26 @@ describe('TxManager', () => {
|
|||||||
type: 2,
|
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', () => {
|
describe('#transaction', () => {
|
||||||
it('should work legacy tx', async () => {
|
it('should work legacy tx', async () => {
|
||||||
const tx = manager.createTx(tx1)
|
const tx = manager.createTx(tx1)
|
||||||
@ -138,6 +152,20 @@ describe('TxManager', () => {
|
|||||||
console.log('receipt', receipt)
|
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 () => {
|
it('should send multiple txs', async () => {
|
||||||
const genTx = value => ({
|
const genTx = value => ({
|
||||||
value,
|
value,
|
||||||
|
Loading…
Reference in New Issue
Block a user