Skip to content

Commit 561151b

Browse files
committed
quote - retrieve gasPrice for EVM
1 parent c1e2815 commit 561151b

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/api/quote.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type Request, type Response } from "express";
22
import { enabledChains, type ChainConfig } from "../chains";
3-
import { isHex, padHex, toBytes } from "viem";
3+
import { createPublicClient, http, isHex, padHex, toBytes } from "viem";
44
import type { Quote } from "@wormhole-foundation/sdk-definitions";
55
import {
66
PAYEE_PUBLIC_KEY,
@@ -12,12 +12,26 @@ import {
1212
getTotalGasLimitAndMsgValue,
1313
signQuote,
1414
} from "../utils";
15+
import { anvil } from "viem/chains";
1516

1617
function getChainConfig(chainId: string): ChainConfig | undefined {
1718
const numericId = parseInt(chainId);
1819
return enabledChains[numericId];
1920
}
2021

22+
async function getGasPrice(chainConfig: ChainConfig): Promise<bigint> {
23+
try {
24+
const transport = http(chainConfig.rpc);
25+
const client = createPublicClient({
26+
chain: anvil,
27+
transport,
28+
});
29+
return await client.getGasPrice();
30+
} catch (e) {
31+
throw new Error(`unable to determine gas price`);
32+
}
33+
}
34+
2135
export const quoteHandler = async (req: Request, res: Response) => {
2236
const enabledChainIds = Object.keys(enabledChains);
2337

@@ -61,9 +75,10 @@ export const quoteHandler = async (req: Request, res: Response) => {
6175
}
6276

6377
const expiryTime = new Date();
64-
6578
expiryTime.setHours(expiryTime.getHours() + 1);
6679

80+
const dstGasPrice = await getGasPrice(dstChain);
81+
6782
const quote: Quote = {
6883
quote: {
6984
prefix: "EQ01",
@@ -78,7 +93,7 @@ export const quoteHandler = async (req: Request, res: Response) => {
7893
dstChain: parseInt(dstChainId),
7994
expiryTime,
8095
baseFee: 1n,
81-
dstGasPrice: 100n,
96+
dstGasPrice: dstGasPrice,
8297
srcPrice: 10000000000n,
8398
dstPrice: 10000000000n,
8499
},

0 commit comments

Comments
 (0)