Skip to content

Commit

Permalink
Merge branch 'gas-costs' into gas-markup-fee
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Jan 3, 2025
2 parents 769296d + 6a524ac commit 0113ac5
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions api/gas-prices.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { VercelResponse } from "@vercel/node";
import {
getCachedFillGasUsage,
getLogger,
handleErrorCondition,
latestGasPriceCache,
sendResponse,
} from "./_utils";
import { TypedVercelRequest } from "./_types";
import { ethers } from "ethers";
import * as sdk from "@across-protocol/sdk";

import mainnetChains from "../src/data/chains_1.json";
import { DEFAULT_SIMULATED_RECIPIENT_ADDRESS } from "./_constants";

const chains = mainnetChains;

Expand All @@ -18,13 +22,30 @@ const handler = async (
const logger = getLogger();

try {
const gasPrices = await Promise.all(
const [gasPrices, gasCosts] = await Promise.all([
chains.map(({ chainId }) => {
return latestGasPriceCache(chainId).get();
})
);
}),
chains.map(({ chainId }) => {
const depositArgs = {
amount: ethers.BigNumber.from(100),
inputToken: sdk.constants.ZERO_ADDRESS,
outputToken: sdk.constants.ZERO_ADDRESS,
recipientAddress: DEFAULT_SIMULATED_RECIPIENT_ADDRESS,
originChainId: 0, // Shouldn't matter for simulation
destinationChainId: chainId,
};
return getCachedFillGasUsage(depositArgs);
}),
]);
const responseJson = Object.fromEntries(
chains.map(({ chainId }, i) => [chainId, gasPrices[i].toString()])
chains.map(({ chainId }, i) => [
chainId,
{
gasPrice: gasPrices[i].toString(),
gasCost: gasCosts[i].toString(),
},
])
);

logger.debug({
Expand Down

0 comments on commit 0113ac5

Please sign in to comment.