Skip to content

Commit

Permalink
improve(GasPriceOracle): Return opStackL1DataFee and floor after scal…
Browse files Browse the repository at this point in the history
…ing priority fee (#822)

Signed-off-by: nicholaspai <[email protected]>
  • Loading branch information
nicholaspai authored Jan 9, 2025
1 parent 40888c4 commit 547fcf1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@across-protocol/sdk",
"author": "UMA Team",
"version": "3.4.7",
"version": "3.4.8",
"license": "AGPL-3.0",
"homepage": "https://docs.across.to/reference/sdk",
"files": [
Expand Down
12 changes: 6 additions & 6 deletions src/gasPriceOracle/adapters/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export async function eip1559Raw(
provider.getBlock("pending"),
(provider as providers.JsonRpcProvider).send("eth_maxPriorityFeePerGas", []),
]);
let maxPriorityFeePerGas = BigNumber.from(_maxPriorityFeePerGas);
const flooredPriorityFeePerGas = parseUnits(process.env[`MIN_PRIORITY_FEE_PER_GAS_${chainId}`] || "0", 9);
if (maxPriorityFeePerGas.lt(flooredPriorityFeePerGas)) {
maxPriorityFeePerGas = BigNumber.from(flooredPriorityFeePerGas);
}
const maxPriorityFeePerGas = BigNumber.from(_maxPriorityFeePerGas);
assert(BigNumber.isBigNumber(baseFeePerGas), `No baseFeePerGas received on ${getNetworkName(chainId)}`);

const scaledPriorityFee = maxPriorityFeePerGas.mul(priorityFeeMultiplier).div(fixedPointAdjustment);
let scaledPriorityFee = maxPriorityFeePerGas.mul(priorityFeeMultiplier).div(fixedPointAdjustment);
const flooredPriorityFeePerGas = parseUnits(process.env[`MIN_PRIORITY_FEE_PER_GAS_${chainId}`] || "0", 9);
if (scaledPriorityFee.lt(flooredPriorityFeePerGas)) {
scaledPriorityFee = BigNumber.from(flooredPriorityFeePerGas);
}
const scaledBaseFee = baseFeePerGas.mul(baseFeeMultiplier).div(fixedPointAdjustment);
return {
maxFeePerGas: scaledPriorityFee.add(scaledBaseFee),
Expand Down
8 changes: 6 additions & 2 deletions src/relayFeeCalculator/chain-queries/baseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class QueryBase implements QueryInterface {
nativeGasCost,
tokenGasCost,
gasPrice: impliedGasPrice,
opStackL1GasCost,
} = await this.estimateGas(tx, relayer, this.provider, {
gasPrice,
gasUnits,
Expand All @@ -109,6 +110,7 @@ export class QueryBase implements QueryInterface {
nativeGasCost,
tokenGasCost,
gasPrice: impliedGasPrice,
opStackL1GasCost,
};
}

Expand Down Expand Up @@ -160,16 +162,17 @@ export class QueryBase implements QueryInterface {
let tokenGasCost: BigNumber;

// OP stack is a special case; gas cost is computed by the SDK, without having to query price.
let opStackL1GasCost: BigNumber | undefined;
if (chainIsOPStack(chainId)) {
assert(isOptimismL2Provider(provider), `Unexpected provider for chain ID ${chainId}.`);
const populatedTransaction = await voidSigner.populateTransaction({
...unsignedTx,
gasLimit: nativeGasCost, // prevents additional gas estimation call
});
const l1GasCost = await (provider as L2Provider<providers.Provider>).estimateL1GasCost(populatedTransaction);
const scaledL1GasCost = l1GasCost.mul(opStackL1GasCostMultiplier).div(fixedPointAdjustment);
opStackL1GasCost = l1GasCost.mul(opStackL1GasCostMultiplier).div(fixedPointAdjustment);
const l2GasCost = nativeGasCost.mul(gasPrice);
tokenGasCost = scaledL1GasCost.add(l2GasCost);
tokenGasCost = opStackL1GasCost.add(l2GasCost);
} else {
tokenGasCost = nativeGasCost.mul(gasPrice);
}
Expand All @@ -178,6 +181,7 @@ export class QueryBase implements QueryInterface {
nativeGasCost, // Units: gas
tokenGasCost, // Units: wei (nativeGasCost * wei/gas)
gasPrice: BigNumber.from(gasPrice.toString()), // Units: wei/gas, does not include l1GasCost for OP stack chains
opStackL1GasCost,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export type TransactionCostEstimate = {
nativeGasCost: BigNumber; // Units: gas
tokenGasCost: BigNumber; // Units: wei (nativeGasCost * wei/gas)
gasPrice: BigNumber; // Units: wei/gas
opStackL1GasCost?: BigNumber; // Units: wei (L1 gas cost * wei/gas)
};

export function randomAddress() {
Expand Down
2 changes: 1 addition & 1 deletion test/GasPriceOracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe("Gas Price Oracle", function () {

// Base fee should be multiplied by multiplier. Returned max fee includes priority fee
// so back it out before scaling.
const expectedMarkedUpPriorityFee = minPriorityFee.mul(priorityFeeMultiplier).div(fixedPointAdjustment);
const expectedMarkedUpPriorityFee = minPriorityFee;
const expectedMarkedUpMaxFeePerGas = stdLastBaseFeePerGas
.mul(baseFeeMultiplier)
.div(fixedPointAdjustment)
Expand Down

0 comments on commit 547fcf1

Please sign in to comment.