Compare commits
6 Commits
v0.2.7
...
blockGasLi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b38927743 | ||
|
|
ab82b37e0d | ||
|
|
30b32a61d1 | ||
|
|
682f2b03c8 | ||
|
|
414fb28a5e | ||
|
|
780df01b43 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tx-manager",
|
"name": "tx-manager",
|
||||||
"version": "0.2.7",
|
"version": "0.2.9",
|
||||||
"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.0.17",
|
"ethers": "^5.0.17",
|
||||||
"gas-price-oracle": "^0.2.0",
|
"gas-price-oracle": "^0.2.2",
|
||||||
"web3-core-promievent": "^1.3.0"
|
"web3-core-promievent": "^1.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -13,12 +13,14 @@ const nonceErrors = [
|
|||||||
const gasPriceErrors = [
|
const gasPriceErrors = [
|
||||||
'Transaction gas price supplied is too low. There is another transaction with same nonce in the queue. Try increasing the gas price or incrementing the nonce.',
|
'Transaction gas price supplied is too low. There is another transaction with same nonce in the queue. Try increasing the gas price or incrementing the nonce.',
|
||||||
'replacement transaction underpriced',
|
'replacement transaction underpriced',
|
||||||
|
'transaction underpriced',
|
||||||
/Transaction gas price \d+wei is too low. There is another transaction with same nonce in the queue with gas price: \d+wei. Try increasing the gas price or incrementing the nonce./,
|
/Transaction gas price \d+wei is too low. There is another transaction with same nonce in the queue with gas price: \d+wei. Try increasing the gas price or incrementing the nonce./,
|
||||||
]
|
]
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
const sameTxErrors = [
|
const sameTxErrors = [
|
||||||
'Transaction with the same hash was already imported.',
|
'Transaction with the same hash was already imported.',
|
||||||
|
'already known',
|
||||||
]
|
]
|
||||||
|
|
||||||
class Transaction {
|
class Transaction {
|
||||||
@@ -64,6 +66,7 @@ class Transaction {
|
|||||||
if (!tx.gasLimit) {
|
if (!tx.gasLimit) {
|
||||||
tx.gasLimit = await this._wallet.estimateGas(tx)
|
tx.gasLimit = await this._wallet.estimateGas(tx)
|
||||||
tx.gasLimit = Math.floor(tx.gasLimit * this.config.GAS_LIMIT_MULTIPLIER)
|
tx.gasLimit = Math.floor(tx.gasLimit * this.config.GAS_LIMIT_MULTIPLIER)
|
||||||
|
tx.gasLimit = Math.min(tx.gasLimit, this.config.BLOCK_GAS_LIMIT)
|
||||||
}
|
}
|
||||||
tx.nonce = this.tx.nonce // can be different from `this.manager._nonce`
|
tx.nonce = this.tx.nonce // can be different from `this.manager._nonce`
|
||||||
tx.gasPrice = Math.max(this.tx.gasPrice, tx.gasPrice || 0) // start no less than current tx gas price
|
tx.gasPrice = Math.max(this.tx.gasPrice, tx.gasPrice || 0) // start no less than current tx gas price
|
||||||
@@ -113,10 +116,16 @@ class Transaction {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _prepare() {
|
async _prepare() {
|
||||||
|
if (!this.config.BLOCK_GAS_LIMIT) {
|
||||||
|
const lastBlock = await this._provider.getBlock('latest')
|
||||||
|
this.config.BLOCK_GAS_LIMIT = Math.floor(lastBlock.gasLimit.toNumber() * 0.95)
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.tx.gasLimit || this.config.ESTIMATE_GAS) {
|
if (!this.tx.gasLimit || this.config.ESTIMATE_GAS) {
|
||||||
const gas = await this._wallet.estimateGas(this.tx)
|
const gas = await this._wallet.estimateGas(this.tx)
|
||||||
if (!this.tx.gasLimit) {
|
if (!this.tx.gasLimit) {
|
||||||
this.tx.gasLimit = Math.floor(gas * this.config.GAS_LIMIT_MULTIPLIER)
|
const gasLimit = Math.floor(gas * this.config.GAS_LIMIT_MULTIPLIER)
|
||||||
|
this.tx.gasLimit = Math.min(gasLimit, this.config.BLOCK_GAS_LIMIT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!this.tx.gasPrice) {
|
if (!this.tx.gasPrice) {
|
||||||
@@ -268,7 +277,12 @@ class Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_handleSendError(e) {
|
_handleSendError(e) {
|
||||||
if (e.code === 'SERVER_ERROR' && e.error) {
|
if (e.error.error) {
|
||||||
|
// Sometimes ethers wraps known errors, unwrap it in this case
|
||||||
|
e = e.error
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.error && e.code === 'SERVER_ERROR') {
|
||||||
const message = e.error.message
|
const message = e.error.message
|
||||||
|
|
||||||
// nonce is too low, trying to increase and resubmit
|
// nonce is too low, trying to increase and resubmit
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const defaultConfig = {
|
|||||||
CONFIRMATIONS: 8,
|
CONFIRMATIONS: 8,
|
||||||
ESTIMATE_GAS: true,
|
ESTIMATE_GAS: true,
|
||||||
THROW_ON_REVERT: true,
|
THROW_ON_REVERT: true,
|
||||||
|
BLOCK_GAS_LIMIT: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
class TxManager {
|
class TxManager {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ describe('TxManager', () => {
|
|||||||
privateKey: PRIVATE_KEY,
|
privateKey: PRIVATE_KEY,
|
||||||
rpcUrl: RPC_URL,
|
rpcUrl: RPC_URL,
|
||||||
config: {
|
config: {
|
||||||
CONFIRMATIONS: 3,
|
CONFIRMATIONS: 1,
|
||||||
GAS_BUMP_INTERVAL: 1000 * 15,
|
GAS_BUMP_INTERVAL: 1000 * 15,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1141,10 +1141,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.2.0:
|
gas-price-oracle@^0.2.2:
|
||||||
version "0.2.0"
|
version "0.2.2"
|
||||||
resolved "https://registry.yarnpkg.com/gas-price-oracle/-/gas-price-oracle-0.2.0.tgz#981926c96089497115113162b03151aacfe44a5a"
|
resolved "https://registry.yarnpkg.com/gas-price-oracle/-/gas-price-oracle-0.2.2.tgz#32c57a9aa6bc69152be96812880232efebfecbc6"
|
||||||
integrity sha512-2+mMyunV/pMJrmKl/IeEtX860NaE/bQ7H4D8PO2dc0OQd8ZAj/e4WJ+C9F/uOeG3dwm8SEFjofOvcYRHeGxo/Q==
|
integrity sha512-I4+rLbc7C1vgYXV+cYY0MKeqdZVna2hXpNfD2fcIvf/wIgvtIYmG9gsmhiaYGSgOE2RSPUs2xf/W4K2nJOoNuQ==
|
||||||
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