Skip to content

Commit

Permalink
Try beta package
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Jan 6, 2025
1 parent 35ae6cf commit 0237cda
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
33 changes: 26 additions & 7 deletions api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,8 @@ export const getRelayerFeeDetails = async (
tokenPrice: number,
relayerAddress: string,
gasPrice: sdk.utils.BigNumberish,
gasUnits?: sdk.utils.BigNumberish
gasUnits?: sdk.utils.BigNumberish,
tokenGasCost?: sdk.utils.BigNumberish
): Promise<sdk.relayFeeCalculator.RelayerFeeDetails> => {
const {
inputToken,
Expand Down Expand Up @@ -740,7 +741,8 @@ export const getRelayerFeeDetails = async (
relayerAddress,
tokenPrice,
gasPrice,
gasUnits
gasUnits,
tokenGasCost
);
};

Expand Down Expand Up @@ -1970,15 +1972,32 @@ 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 { nativeGasCost } = await relayerFeeCalculatorQueries.getGasCosts(
const gasCosts = await relayerFeeCalculatorQueries.getGasCosts(
buildDepositForSimulation(deposit),
overrides?.relayerAddress
overrides?.relayerAddress,
{
// Scale the op stack L1 gas cost component by the base fee multiplier.
// Consider adding a new environment variable OP_STACK_L1_GAS_COST_MARKUPif we want finer-grained control.
opStackL1GasCostMultiplier: getGasMarkup(deposit.destinationChainId)
.baseFeeMarkup,
}
);
return nativeGasCost;
return {
nativeGasCost: gasCosts.nativeGasCost,
tokenGasCost: gasCosts.tokenGasCost,
};
};

return getCachedValue(cacheKey, ttl, fetchFn, (bnFromCache) =>
BigNumber.from(bnFromCache)
return getCachedValue(
cacheKey,
ttl,
fetchFn,
(gasCosts: { nativeGasCost: BigNumber; tokenGasCost: BigNumber }) => {
return {
nativeGasCost: BigNumber.from(gasCosts.nativeGasCost),
tokenGasCost: BigNumber.from(gasCosts.tokenGasCost),
};
}
);
}

Expand Down
10 changes: 10 additions & 0 deletions api/gas-prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const handler = async (
const relayerFeeCalculatorQueries = getRelayerFeeCalculatorQueries(
Number(chainId)
);
const opStackL1GasCostMultiplier = getGasMarkup(
Number(chainId)
).baseFeeMarkup;
const { nativeGasCost, tokenGasCost } =
await relayerFeeCalculatorQueries.getGasCosts(
deposit,
Expand All @@ -79,6 +82,7 @@ const handler = async (
// the scaled gas price,
// e.g. tokenGasCost = nativeGasCost * (baseFee * baseFeeMultiplier + priorityFee).
gasPrice: gasPrices[i].maxFeePerGas,
opStackL1GasCostMultiplier,
}
);
// OPStack chains factor in the L1 gas cost of including the L2 transaction in an L1 rollup batch
Expand All @@ -102,6 +106,9 @@ const handler = async (
opStackL1GasCost = await (
provider as L2Provider<providers.Provider>
).estimateL1GasCost(unsignedTx);
opStackL1GasCost = opStackL1GasCostMultiplier
.mul(opStackL1GasCost)
.div(sdk.utils.fixedPointAdjustment);
}
return {
nativeGasCost,
Expand Down Expand Up @@ -129,6 +136,9 @@ const handler = async (
priorityFeeMultiplier: ethers.utils.formatEther(
getGasMarkup(chainId).priorityFeeMarkup
),
opStackL1GasCostMultiplier: ethers.utils.formatEther(
getGasMarkup(chainId).baseFeeMarkup
),
},
nativeGasCost: gasCosts[i].nativeGasCost.toString(),
tokenGasCost: gasCosts[i].tokenGasCost.toString(),
Expand Down
5 changes: 3 additions & 2 deletions api/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const handler = async (
message,
};

const [tokenPriceNative, _tokenPriceUsd, latestBlock, gasUnits, gasPrice] =
const [tokenPriceNative, _tokenPriceUsd, latestBlock, gasCosts, gasPrice] =
await Promise.all([
getCachedTokenPrice(
l1Token.address,
Expand Down Expand Up @@ -194,7 +194,8 @@ const handler = async (
tokenPriceNative,
relayer,
gasPrice,
gasUnits
gasCosts?.nativeGasCost,
gasCosts?.tokenGasCost
),
callViaMulticall3(provider, multiCalls, {
blockTag: latestBlock.number,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@across-protocol/constants": "^3.1.24",
"@across-protocol/contracts": "^3.0.19",
"@across-protocol/contracts-v3.0.6": "npm:@across-protocol/[email protected]",
"@across-protocol/sdk": "^3.4.4",
"@across-protocol/sdk": "^3.4.5-beta.1",
"@amplitude/analytics-browser": "^2.3.5",
"@balancer-labs/sdk": "1.1.6-beta.16",
"@emotion/react": "^11.13.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@
yargs "^17.7.2"
zksync-web3 "^0.14.3"

"@across-protocol/sdk@^3.4.4":
version "3.4.4"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-3.4.4.tgz#4744e87f6a5154d6696870e8f0f5e32b619d9554"
integrity sha512-g2PEvE6U0i7UjZah5g+x01pTbeex3mpJnRV6aC8RJGCBu69B9fRKpyOwx44DPURI1HqRE3i+4wPa8y9LxYx34A==
"@across-protocol/sdk@^3.4.5-beta.1":
version "3.4.5-beta.1"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-3.4.5-beta.1.tgz#53c6a92f42aa4d6d638091a736b5dc53db02c10e"
integrity sha512-LHXZuQCJoGxDYtJRt4AAONS/zA0M4BOI5lK4krWLC1G8pmFfz3ml2ynr9vALTuZ4d2LjNqwJTUH6CEgxu2rHVA==
dependencies:
"@across-protocol/across-token" "^1.0.0"
"@across-protocol/constants" "^3.1.25"
Expand Down

0 comments on commit 0237cda

Please sign in to comment.