diff --git a/package.json b/package.json index 7428d47e..f212ad64 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/src/gasPriceOracle/adapters/ethereum.ts b/src/gasPriceOracle/adapters/ethereum.ts index 3c8fbca1..a75e8b0f 100644 --- a/src/gasPriceOracle/adapters/ethereum.ts +++ b/src/gasPriceOracle/adapters/ethereum.ts @@ -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), diff --git a/src/relayFeeCalculator/chain-queries/baseQuery.ts b/src/relayFeeCalculator/chain-queries/baseQuery.ts index 942eb0ec..f7870a5b 100644 --- a/src/relayFeeCalculator/chain-queries/baseQuery.ts +++ b/src/relayFeeCalculator/chain-queries/baseQuery.ts @@ -96,6 +96,7 @@ export class QueryBase implements QueryInterface { nativeGasCost, tokenGasCost, gasPrice: impliedGasPrice, + opStackL1GasCost, } = await this.estimateGas(tx, relayer, this.provider, { gasPrice, gasUnits, @@ -109,6 +110,7 @@ export class QueryBase implements QueryInterface { nativeGasCost, tokenGasCost, gasPrice: impliedGasPrice, + opStackL1GasCost, }; } @@ -160,6 +162,7 @@ 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({ @@ -167,9 +170,9 @@ export class QueryBase implements QueryInterface { gasLimit: nativeGasCost, // prevents additional gas estimation call }); const l1GasCost = await (provider as L2Provider).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); } @@ -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, }; } diff --git a/src/utils/common.ts b/src/utils/common.ts index 3b5c0337..7dc34d57 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -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() { diff --git a/test/GasPriceOracle.test.ts b/test/GasPriceOracle.test.ts index e5c06510..df1d06b8 100644 --- a/test/GasPriceOracle.test.ts +++ b/test/GasPriceOracle.test.ts @@ -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)