Skip to content

Commit

Permalink
Overrestimate gas (#1876)
Browse files Browse the repository at this point in the history
* Overrestimate gas

* udpate changelog

* systematic gas estimation for tx
  • Loading branch information
maxencerb authored Apr 2, 2024
1 parent 132dc35 commit bd122df
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Next version

- Add 20% to gas limit from the gas estimation

# 2.0.5-48

- Add mumbai addresses.
Expand Down
6 changes: 4 additions & 2 deletions src/util/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,10 @@ class Trade {
) {
// If not given an explicit gasLimit then we estimate it. Ethers does this automatically, but if we are given a lower bound,
// (for instance from our own estimateGas function) then we need to invoke estimation manually and compare.
if (!overrides.gasLimit && gasLowerBound) {
overrides.gasLimit = await estimateTx(...args);
if (!overrides.gasLimit && !gasLowerBound) {
overrides.gasLimit = (await estimateTx(...args)).mul(120).div(100);
} else if (!overrides.gasLimit && gasLowerBound) {
overrides.gasLimit = (await estimateTx(...args)).mul(120).div(100);
if (overrides.gasLimit.lt(gasLowerBound)) {
overrides.gasLimit = gasLowerBound;
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/market.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,9 +1265,9 @@ describe("Market integration tests suite", () => {
} else {
// Use ethers estimation, if these values are too unstable, then refactor.
if (forceRouting) {
expectedLimit = 271629;
expectedLimit = 325954;
} else {
expectedLimit = 43475;
expectedLimit = 52170;
}
}
}
Expand Down

0 comments on commit bd122df

Please sign in to comment.