Skip to content

Commit

Permalink
Fix price adjustment in profitability formula (#642)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 authored Mar 6, 2024
1 parent 3985f62 commit 8c046a7
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public class TransactionProfitabilityCalculator {

private final LineaProfitabilityConfiguration profitabilityConf;
private final double preComputedValue;
private final double priceAdjustment;

public TransactionProfitabilityCalculator(
final LineaProfitabilityConfiguration profitabilityConf) {
this.profitabilityConf = profitabilityConf;
this.preComputedValue =
profitabilityConf.gasPriceRatio() * profitabilityConf.verificationGasCost();
this.priceAdjustment = profitabilityConf.gasPriceAdjustment().getAsBigInteger().doubleValue();
}

public Wei profitablePriorityFeePerGas(
Expand All @@ -44,15 +46,14 @@ public Wei profitablePriorityFeePerGas(
final double compressedTxSize = getCompressedTxSize(transaction);

final var profitAt =
preComputedValue
* minMargin
* compressedTxSize
* minGasPrice.getAsBigInteger().doubleValue()
/ (gas * profitabilityConf.verificationCapacity());

final var adjustedProfit =
Wei.ofNumber(BigDecimal.valueOf(profitAt).toBigInteger())
.add(profitabilityConf.gasPriceAdjustment());
(preComputedValue
* compressedTxSize
* minGasPrice.getAsBigInteger().doubleValue()
/ (gas * profitabilityConf.verificationCapacity())
+ priceAdjustment)
* minMargin;

final var adjustedProfit = Wei.ofNumber(BigDecimal.valueOf(profitAt).toBigInteger());

log.atDebug()
.setMessage(
Expand Down

0 comments on commit 8c046a7

Please sign in to comment.