From 11a3a1a7e4fb137efd0976840470ea194211fad4 Mon Sep 17 00:00:00 2001 From: nicholaspai Date: Thu, 9 Jan 2025 15:29:31 -0500 Subject: [PATCH] improve(API): Derive tokenGasCost locally in /limits Rather than pass the `tokenGasCosts` derived from the SDK.estimateGasCosts call, derive it locally. The current code doesn't use the `gasPrice` fetched from the SDK to compute the `tokenGasCosts` so the token gas costs are inaccurate --- api/_utils.ts | 10 +++++++++- api/limits.ts | 9 ++++++++- package.json | 2 +- yarn.lock | 8 ++++---- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/api/_utils.ts b/api/_utils.ts index 4b94d2296..2cd23d8b7 100644 --- a/api/_utils.ts +++ b/api/_utils.ts @@ -1982,6 +1982,7 @@ export function getCachedFillGasUsage( } ); return { + opStackL1GasCost: gasCosts.opStackL1GasCost, nativeGasCost: gasCosts.nativeGasCost, tokenGasCost: gasCosts.tokenGasCost, }; @@ -1991,10 +1992,17 @@ export function getCachedFillGasUsage( cacheKey, ttl, fetchFn, - (gasCosts: { nativeGasCost: BigNumber; tokenGasCost: BigNumber }) => { + (gasCosts: { + nativeGasCost: BigNumber; + tokenGasCost: BigNumber; + opStackL1GasCost: BigNumber | undefined; + }) => { return { nativeGasCost: BigNumber.from(gasCosts.nativeGasCost), tokenGasCost: BigNumber.from(gasCosts.tokenGasCost), + opStackL1GasCost: gasCosts.opStackL1GasCost + ? BigNumber.from(gasCosts.opStackL1GasCost) + : undefined, }; } ); diff --git a/api/limits.ts b/api/limits.ts index fcfc29a33..803fb4dbe 100644 --- a/api/limits.ts +++ b/api/limits.ts @@ -181,6 +181,13 @@ const handler = async ( latestGasPriceCache(destinationChainId).get(), ]); const tokenPriceUsd = ethers.utils.parseUnits(_tokenPriceUsd.toString()); + let tokenGasCost = gasCosts?.nativeGasCost; + if (tokenGasCost !== undefined) { + tokenGasCost = tokenGasCost.mul(gasPrice); + if (gasCosts?.opStackL1GasCost) { + tokenGasCost = tokenGasCost.add(gasCosts.opStackL1GasCost); + } + } const [ relayerFeeDetails, @@ -195,7 +202,7 @@ const handler = async ( relayer, gasPrice, gasCosts?.nativeGasCost, - gasCosts?.tokenGasCost + tokenGasCost ), callViaMulticall3(provider, multiCalls, { blockTag: latestBlock.number, diff --git a/package.json b/package.json index 6ec93dc78..0a101f267 100644 --- a/package.json +++ b/package.json @@ -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/contracts@3.0.6", - "@across-protocol/sdk": "^3.4.7", + "@across-protocol/sdk": "^3.4.8-beta.1", "@amplitude/analytics-browser": "^2.3.5", "@balancer-labs/sdk": "1.1.6-beta.16", "@emotion/react": "^11.13.0", diff --git a/yarn.lock b/yarn.lock index 9b06bf5bf..275c9cd65 100644 --- a/yarn.lock +++ b/yarn.lock @@ -83,10 +83,10 @@ yargs "^17.7.2" zksync-web3 "^0.14.3" -"@across-protocol/sdk@^3.4.7": - version "3.4.7" - resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-3.4.7.tgz#6ddf9698f918d7b7e0216327d60b54b37fe14f22" - integrity sha512-GeyzDG8EzlN8oddmjXASqND+usZPkWDLpzbdWfAfBfHT3pjIMatntZqZghfCfjy+ICf+rlYrAb8I24H4jlct8Q== +"@across-protocol/sdk@^3.4.8-beta.1": + version "3.4.8-beta.1" + resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-3.4.8-beta.1.tgz#f9366cf7a30bf44a655d25efa03dd9101cdb96ca" + integrity sha512-uVkvdrnQt2Gtdel9H4isDRB+5iTn/fj1zamQzWqvaknSHftdFm2nbiRmNkB7fm2o41XanxTcXRN3rYUNWTGb1Q== dependencies: "@across-protocol/across-token" "^1.0.0" "@across-protocol/constants" "^3.1.25"