1
1
import { type Request , type Response } from "express" ;
2
2
import { enabledChains , type ChainConfig } from "../chains" ;
3
- import { isHex , padHex , toBytes } from "viem" ;
3
+ import { createPublicClient , http , isHex , padHex , toBytes } from "viem" ;
4
4
import type { Quote } from "@wormhole-foundation/sdk-definitions" ;
5
5
import {
6
6
PAYEE_PUBLIC_KEY ,
@@ -12,12 +12,26 @@ import {
12
12
getTotalGasLimitAndMsgValue ,
13
13
signQuote ,
14
14
} from "../utils" ;
15
+ import { anvil } from "viem/chains" ;
15
16
16
17
function getChainConfig ( chainId : string ) : ChainConfig | undefined {
17
18
const numericId = parseInt ( chainId ) ;
18
19
return enabledChains [ numericId ] ;
19
20
}
20
21
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
+
21
35
export const quoteHandler = async ( req : Request , res : Response ) => {
22
36
const enabledChainIds = Object . keys ( enabledChains ) ;
23
37
@@ -61,9 +75,10 @@ export const quoteHandler = async (req: Request, res: Response) => {
61
75
}
62
76
63
77
const expiryTime = new Date ( ) ;
64
-
65
78
expiryTime . setHours ( expiryTime . getHours ( ) + 1 ) ;
66
79
80
+ const dstGasPrice = await getGasPrice ( dstChain ) ;
81
+
67
82
const quote : Quote = {
68
83
quote : {
69
84
prefix : "EQ01" ,
@@ -78,7 +93,7 @@ export const quoteHandler = async (req: Request, res: Response) => {
78
93
dstChain : parseInt ( dstChainId ) ,
79
94
expiryTime,
80
95
baseFee : 1n ,
81
- dstGasPrice : 100n ,
96
+ dstGasPrice : dstGasPrice ,
82
97
srcPrice : 10000000000n ,
83
98
dstPrice : 10000000000n ,
84
99
} ,
0 commit comments