-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can be used to determine what gas price the API is computing
- Loading branch information
1 parent
7a57b12
commit 37eb6bf
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { VercelResponse } from "@vercel/node"; | ||
import { | ||
getLogger, | ||
handleErrorCondition, | ||
latestGasPriceCache, | ||
sendResponse, | ||
} from "./_utils"; | ||
import { TypedVercelRequest } from "./_types"; | ||
|
||
import mainnetChains from "../src/data/chains_1.json"; | ||
|
||
const chains = mainnetChains; | ||
|
||
const handler = async ( | ||
_: TypedVercelRequest<Record<string, never>>, | ||
response: VercelResponse | ||
) => { | ||
const logger = getLogger(); | ||
|
||
try { | ||
const gasPrices = await Promise.all( | ||
chains.map(({ chainId }) => { | ||
return latestGasPriceCache(chainId).get(); | ||
}) | ||
); | ||
const responseJson = Object.fromEntries( | ||
chains.map(({ chainId }, i) => [chainId, gasPrices[i]]) | ||
); | ||
|
||
logger.debug({ | ||
at: "GasPrices", | ||
message: "Response data", | ||
responseJson, | ||
}); | ||
// Respond with a 200 status code and 10 seconds of cache with | ||
// 45 seconds of stale-while-revalidate. | ||
sendResponse(response, responseJson, 200, 10, 45); | ||
} catch (error: unknown) { | ||
return handleErrorCondition("gas-prices", response, logger, error); | ||
} | ||
}; | ||
|
||
export default handler; |