Skip to content

Commit

Permalink
feat: gas optimization in gas adjustment calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhwu committed Oct 1, 2024
1 parent b0cd19a commit d8f063a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/reactors/V3DutchOrderReactor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,18 @@ contract V3DutchOrderReactor is BaseReactor {
int256 gasDeltaGwei = block.basefee.sub(order.startingBaseFee);

// Gas increase should increase input
int256 inputDelta = int256(order.baseInput.adjustmentPerGweiBaseFee) * gasDeltaGwei / 1 gwei;
order.baseInput.startAmount = order.baseInput.startAmount.boundedAdd(inputDelta, 0, order.baseInput.maxAmount);

if (order.baseInput.adjustmentPerGweiBaseFee != 0 ) {
int256 inputDelta = int256(order.baseInput.adjustmentPerGweiBaseFee) * gasDeltaGwei / 1 gwei;
order.baseInput.startAmount = order.baseInput.startAmount.boundedAdd(inputDelta, 0, order.baseInput.maxAmount);
}
// Gas increase should decrease output
uint256 outputsLength = order.baseOutputs.length;
for (uint256 i = 0; i < outputsLength; i++) {
V3DutchOutput memory output = order.baseOutputs[i];
int256 outputDelta = int256(output.adjustmentPerGweiBaseFee) * gasDeltaGwei / 1 gwei;
output.startAmount = output.startAmount.boundedSub(outputDelta, output.minAmount, type(uint256).max);
if (output.adjustmentPerGweiBaseFee != 0) {
int256 outputDelta = int256(output.adjustmentPerGweiBaseFee) * gasDeltaGwei / 1 gwei;
output.startAmount = output.startAmount.boundedSub(outputDelta, output.minAmount, type(uint256).max);
}
}
}

Expand Down

0 comments on commit d8f063a

Please sign in to comment.