Skip to content

Commit

Permalink
Add gas estimation to kandel populate tx (#1881)
Browse files Browse the repository at this point in the history
* Add gas estimation to kandel populate tx

* Add block gas limit as upper range
  • Loading branch information
maxencerb committed Apr 16, 2024
1 parent d34b0db commit f25ee0e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 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

- Change gas estimation for kandel populate transaction.

# 2.0.5-49

- Add 20% to gas limit from the gas estimation
Expand Down
23 changes: 23 additions & 0 deletions src/kandel/geometricKandel/geometricKandelInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,29 @@ class GeometricKandelInstance extends CoreKandelInstance {
params.distribution.askGives,
);

if (!overridesWithFunds.gasLimit) {
const [gasEstimation, block] = await Promise.all([
this.geometricKandel.estimateGas.populateFromOffset(
firstDistribution.from,
firstDistribution.to,
params.distribution.baseQuoteTickIndex0,
newBaseQuoteTickOffset,
params.distribution.firstAskIndex,
rawBidGives,
rawAskGives,
rawParameters,
rawDepositBaseAmount,
rawDepositQuoteAmount,
overridesWithFunds,
),
this.geometricKandel.provider.getBlock("latest"),
]);
overridesWithFunds.gasLimit = gasEstimation.mul(120).div(100);
if (overridesWithFunds.gasLimit.gt(block.gasLimit)) {
overridesWithFunds.gasLimit = block.gasLimit;
}
}

const txs = [
await this.geometricKandel.populateFromOffset(
firstDistribution.from,
Expand Down

0 comments on commit f25ee0e

Please sign in to comment.