Skip to content

Commit

Permalink
Use sdk for helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Jan 11, 2025
1 parent c1f6e03 commit 5f7ab07
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 43 deletions.
62 changes: 27 additions & 35 deletions api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1970,25 +1970,6 @@ export function isContractCache(chainId: number, address: string) {
);
}

function getUnsignedFillTxnFromDeposit(
deposit: Parameters<typeof buildDepositForSimulation>[0],
_relayerAddress?: string
): Promise<ethers.PopulatedTransaction> {
const relayerAddress =
_relayerAddress ?? sdk.constants.DEFAULT_SIMULATED_RELAYER_ADDRESS;
const relayerFeeCalculatorQueries = getRelayerFeeCalculatorQueries(
deposit.destinationChainId,
{
relayerAddress,
}
);
return sdk.utils.populateV3Relay(
relayerFeeCalculatorQueries.spokePool,
buildDepositForSimulation(deposit),
relayerAddress
);
}

export function getCachedNativeGasCost(
deposit: Parameters<typeof buildDepositForSimulation>[0],
overrides?: Partial<{
Expand All @@ -2014,10 +1995,11 @@ export function getCachedNativeGasCost(
deposit.destinationChainId,
overrides
);
const unsignedFillTxn = await getUnsignedFillTxnFromDeposit(
deposit,
relayerAddress
);
const unsignedFillTxn =
await relayerFeeCalculatorQueries.getUnsignedTxFromDeposit(
buildDepositForSimulation(deposit),
relayerAddress
);
const voidSigner = new ethers.VoidSigner(
relayerAddress,
relayerFeeCalculatorQueries.provider
Expand Down Expand Up @@ -2059,17 +2041,20 @@ export function getCachedOpStackL1DataFee(
deposit.destinationChainId,
overrides
);
const { opStackL1GasCost } = await relayerFeeCalculatorQueries.getGasCosts(
buildDepositForSimulation(deposit),
overrides?.relayerAddress,
{
gasUnits: nativeGasCost, // Passed in here to avoid gas cost recomputation by the SDK
gasPrice: 1, // We pass in a gas price here so that the SDK doesn't recompute the gas price but we don't
// use any results from the SDK dependent on this value so it doesn't matter what it is. The OP
// Stack L1 data fee is unaffected by this gas price.
opStackL1GasCostMultiplier: opStackL1DataFeeMarkup,
}
);
const unsignedTx =
await relayerFeeCalculatorQueries.getUnsignedTxFromDeposit(
buildDepositForSimulation(deposit),
overrides?.relayerAddress
);
const opStackL1GasCost =
await relayerFeeCalculatorQueries.getOpStackL1DataFee(
unsignedTx,
overrides?.relayerAddress,
{
opStackL2GasUnits: nativeGasCost, // Passed in here to avoid gas cost recomputation by the SDK
opStackL1DataFeeMultiplier: opStackL1DataFeeMarkup,
}
);
return opStackL1GasCost;
};

Expand Down Expand Up @@ -2120,8 +2105,15 @@ export async function getMaxFeePerGas(
baseFeeMarkup: baseFeeMultiplier,
priorityFeeMarkup: priorityFeeMultiplier,
} = getGasMarkup(chainId);
const relayerFeeCalculatorQueries = getRelayerFeeCalculatorQueries(
chainId,
overrides
);
const unsignedFillTxn = deposit
? await getUnsignedFillTxnFromDeposit(deposit, overrides?.relayerAddress)
? await relayerFeeCalculatorQueries.getUnsignedTxFromDeposit(
buildDepositForSimulation(deposit),
overrides?.relayerAddress
)
: undefined;
return sdk.gasPriceOracle.getGasPriceEstimate(getProvider(chainId), {
chainId,
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.8",
"@across-protocol/sdk": "^3.4.10-beta.1",
"@amplitude/analytics-browser": "^2.3.5",
"@balancer-labs/sdk": "1.1.6-beta.16",
"@emotion/react": "^11.13.0",
Expand Down
47 changes: 40 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
"@uma/common" "^2.17.0"
hardhat "^2.9.3"

"@across-protocol/constants@^3.1.24", "@across-protocol/constants@^3.1.25":
"@across-protocol/constants@^3.1.24":
version "3.1.25"
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.25.tgz#60d6d9814582ff91faf2b6d9f51d6dccb447b4ce"
integrity sha512-GpZoYn7hETYL2BPMM2GqXAer6+l/xuhder+pvpb00HJcb/sqCjF7vaaeKxjKJ3jKtyeulYmdu0NDkeNm5KbNWA==

"@across-protocol/constants@^3.1.27":
version "3.1.28"
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.28.tgz#0540f5a44b085b0951a853898afe174ea113db3a"
integrity sha512-rnI1pQgkJ6+hPIQNomsi8eQreVfWKfFn9i9Z39U0fAnoXodZklW0eqj5N0cXlEfahp5j2u1RCs7s6fQ9megCdw==

"@across-protocol/constants@^3.1.9":
version "3.1.13"
resolved "https://registry.yarnpkg.com/@across-protocol/constants/-/constants-3.1.13.tgz#b4caf494e9d9fe50290cca91b7883ea408fdb90a"
Expand Down Expand Up @@ -83,14 +88,42 @@
yargs "^17.7.2"
zksync-web3 "^0.14.3"

"@across-protocol/sdk@^3.4.8":
version "3.4.8"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-3.4.8.tgz#070abb97b687cfe22d89349d776f68008af5f6a7"
integrity sha512-m4JnT3Sh+zmTZ/Oi7QrTv3IuNB+myBcbnPnEEssZroyBost/yEPyxXks+EHeU67KrT84t/otGyNb5YpTOvOK0A==
"@across-protocol/contracts@^3.0.20":
version "3.0.20"
resolved "https://registry.yarnpkg.com/@across-protocol/contracts/-/contracts-3.0.20.tgz#5a70782093d21a96b2e955b7ed725bea7af6e804"
integrity sha512-ufyO+MrbY7+0TDm/1cDl9iAeR4P8jt0AM1F9wiCBHVIYtj1wMD4eNm7G5Am3u8p1ruMjRhi6dJEVQcRF2O+LUg==
dependencies:
"@across-protocol/constants" "^3.1.27"
"@coral-xyz/anchor" "^0.30.1"
"@defi-wonderland/smock" "^2.3.4"
"@eth-optimism/contracts" "^0.5.40"
"@ethersproject/abstract-provider" "5.7.0"
"@ethersproject/abstract-signer" "5.7.0"
"@ethersproject/bignumber" "5.7.0"
"@openzeppelin/contracts" "4.9.6"
"@openzeppelin/contracts-upgradeable" "4.9.6"
"@scroll-tech/contracts" "^0.1.0"
"@solana-developers/helpers" "^2.4.0"
"@solana/spl-token" "^0.4.6"
"@solana/web3.js" "^1.31.0"
"@types/yargs" "^17.0.33"
"@uma/common" "^2.37.3"
"@uma/contracts-node" "^0.4.17"
"@uma/core" "^2.61.0"
axios "^1.7.4"
bs58 "^6.0.0"
prettier-plugin-rust "^0.1.9"
yargs "^17.7.2"
zksync-web3 "^0.14.3"

"@across-protocol/sdk@^3.4.10-beta.1":
version "3.4.10-beta.1"
resolved "https://registry.yarnpkg.com/@across-protocol/sdk/-/sdk-3.4.10-beta.1.tgz#81d56458d97dec424e2fe51730f8ae3953c84e6c"
integrity sha512-c4tD6RQBKiok4fAK99Kh69B5+PIcAz0DLaAhfWxInRxW4kBeAKSrOtjETxuYN1wRZ89qRsGx+N+7c/wDpeQDxg==
dependencies:
"@across-protocol/across-token" "^1.0.0"
"@across-protocol/constants" "^3.1.25"
"@across-protocol/contracts" "^3.0.19"
"@across-protocol/constants" "^3.1.27"
"@across-protocol/contracts" "^3.0.20"
"@eth-optimism/sdk" "^3.3.1"
"@ethersproject/bignumber" "^5.7.0"
"@pinata/sdk" "^2.1.0"
Expand Down

0 comments on commit 5f7ab07

Please sign in to comment.