Skip to content

Commit

Permalink
Use correct linea price in gas-prices and pass markups correctly in g…
Browse files Browse the repository at this point in the history
…etCachedFillGasUsage
  • Loading branch information
nicholaspai committed Jan 10, 2025
1 parent 5c78f58 commit 380ea4e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
3 changes: 3 additions & 0 deletions api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1995,11 +1995,14 @@ export function getCachedFillGasUsage(
);
// We don't care about the gas token price or the token gas price, only the raw gas units. In the API
// we'll compute the gas price separately.
const markups = getGasMarkup(deposit.destinationChainId);
const gasCosts = await relayerFeeCalculatorQueries.getGasCosts(
buildDepositForSimulation(deposit),
overrides?.relayerAddress,
{
gasPrice,
baseFeeMultiplier: markups.baseFeeMarkup,
priorityFeeMultiplier: markups.priorityFeeMarkup,
opStackL1GasCostMultiplier: sdk.utils.chainIsOPStack(
deposit.destinationChainId
)
Expand Down
39 changes: 28 additions & 11 deletions api/gas-prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,32 @@ const handler = async (
const relayerFeeCalculatorQueries = getRelayerFeeCalculatorQueries(
Number(chainId)
);
const opStackL1GasCostMultiplier = getGasMarkup(
Number(chainId)
).opStackL1DataFeeMarkup;
const { nativeGasCost, tokenGasCost, opStackL1GasCost } =
const { baseFeeMarkup, priorityFeeMarkup, opStackL1DataFeeMarkup } =
getGasMarkup(Number(chainId));
const { nativeGasCost, tokenGasCost, opStackL1GasCost, gasPrice } =
await relayerFeeCalculatorQueries.getGasCosts(
deposit,
relayerFeeCalculatorQueries.simulatedRelayerAddress,
{
// Pass in the already-computed gasPrice into this query so that the tokenGasCost includes
// the scaled gas price,
// e.g. tokenGasCost = nativeGasCost * (baseFee * baseFeeMultiplier + priorityFee).
// Except for Linea, where the gas price is dependent on the unsignedTx produced from the deposit,
// so let the SDK compute its gas price here.
gasPrice:
Number(chainId) === CHAIN_IDs.LINEA
? undefined
: gasPrices[i].maxFeePerGas,
opStackL1GasCostMultiplier,
opStackL1GasCostMultiplier: opStackL1DataFeeMarkup,
baseFeeMultiplier: baseFeeMarkup,
priorityFeeMultiplier: priorityFeeMarkup,
}
);
return {
nativeGasCost,
tokenGasCost,
opStackL1GasCost,
gasPrice,
};
}
)
Expand All @@ -103,12 +107,23 @@ const handler = async (
Object.keys(chainIdsWithToken).map((chainId, i) => [
chainId,
{
gasPrice: gasPrices[i].maxFeePerGas.toString(),
gasPrice:
Number(chainId) === CHAIN_IDs.LINEA
? gasCosts[i].gasPrice.toString()
: gasPrices[i].maxFeePerGas.toString(),
gasPriceComponents: {
maxFeePerGas: gasPrices[i].maxFeePerGas
.sub(gasPrices[i].maxPriorityFeePerGas)
.toString(),
priorityFeePerGas: gasPrices[i].maxPriorityFeePerGas.toString(),
// Linea hardcodes base fee at 7 wei so we can always back it out fromthe gasPrice returned by the
// getGasCosts method.
maxFeePerGas:
Number(chainId) === CHAIN_IDs.LINEA
? gasCosts[i].gasPrice.sub(7).toString()
: gasPrices[i].maxFeePerGas
.sub(gasPrices[i].maxPriorityFeePerGas)
.toString(),
priorityFeePerGas:
Number(chainId) === CHAIN_IDs.LINEA
? "7"
: gasPrices[i].maxPriorityFeePerGas.toString(),
baseFeeMultiplier: ethers.utils.formatEther(
getGasMarkup(chainId).baseFeeMarkup
),
Expand All @@ -118,7 +133,9 @@ const handler = async (
opStackL1GasCostMultiplier: sdk.utils.chainIsOPStack(
Number(chainId)
)
? ethers.utils.formatEther(getGasMarkup(chainId).baseFeeMarkup)
? ethers.utils.formatEther(
getGasMarkup(chainId).opStackL1DataFeeMarkup
)
: undefined,
},
nativeGasCost: gasCosts[i].nativeGasCost.toString(),
Expand Down

0 comments on commit 380ea4e

Please sign in to comment.