Skip to content

Commit

Permalink
improve(API): Derive tokenGasCost locally in /limits
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nicholaspai committed Jan 9, 2025
1 parent 948b6f2 commit 11a3a1a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
10 changes: 9 additions & 1 deletion api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,7 @@ export function getCachedFillGasUsage(
}
);
return {
opStackL1GasCost: gasCosts.opStackL1GasCost,
nativeGasCost: gasCosts.nativeGasCost,
tokenGasCost: gasCosts.tokenGasCost,
};
Expand All @@ -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,
};
}
);
Expand Down
9 changes: 8 additions & 1 deletion api/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -195,7 +202,7 @@ const handler = async (
relayer,
gasPrice,
gasCosts?.nativeGasCost,
gasCosts?.tokenGasCost
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.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",
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.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"
Expand Down

0 comments on commit 11a3a1a

Please sign in to comment.