@@ -137,6 +137,12 @@ export class LayerZeroGatewayClient extends GatewayApiClient {
137137 throw new Error ( `Unsupported destination chain: ${ toChain } ` ) ;
138138 }
139139
140+ // always use the wBTC token on BOB
141+ const wbtcOftAddress = await this . l0Client . getOftAddressForChain ( 'bob' ) ;
142+ if ( ! wbtcOftAddress ) {
143+ throw new Error ( `WBTC OFT not found for chain: ${ fromChain } ` ) ;
144+ }
145+
140146 // TODO: Will need to generalize this if we want to support other option sets. Its manual ABI encoding so a little complex.
141147 const extraOptions = encodePacked (
142148 [ 'uint16' , 'uint8' , 'uint16' , 'uint8' , 'uint128' ] ,
@@ -166,16 +172,17 @@ export class LayerZeroGatewayClient extends GatewayApiClient {
166172
167173 // Getting the layer zero fee gas so we know how much we need to swap from the order
168174 const layerZeroFee = await publicClient . readContract ( {
169- address : params . toToken as Hex ,
175+ address : wbtcOftAddress as Hex ,
170176 abi : layerZeroOftAbi ,
171177 functionName : 'quoteSend' ,
172178 args : [ sendParam , false ] ,
173179 } ) ;
174180
175- const buffer = BigInt ( 500 ) ; // 5% buffer
181+ // allow consumer to override the buffer
182+ const buffer = params . l0FeeBuffer ? BigInt ( params . l0FeeBuffer ) : BigInt ( 500 ) ; // 5% buffer
176183
177184 // Add buffer to the layer zero fee to account for changes from now until the order is executed
178- const layerZeroFeeWithBuffer = ( layerZeroFee . nativeFee * ( 10000n + buffer ) ) / 10000n ; // 5% buffer
185+ const layerZeroFeeWithBuffer = ( layerZeroFee . nativeFee * ( 10000n + buffer ) ) / 10000n ;
179186
180187 // Getting the amount of tokens we need to swap from the order by using the uniswap quoter
181188 const quote = await publicClient . readContract ( {
@@ -184,7 +191,7 @@ export class LayerZeroGatewayClient extends GatewayApiClient {
184191 functionName : 'quoteExactOutputSingle' ,
185192 args : [
186193 {
187- tokenIn : params . toToken as Hex ,
194+ tokenIn : wbtcOftAddress as Hex ,
188195 tokenOut : '0x4200000000000000000000000000000000000006' as Hex ,
189196 amountOut : layerZeroFeeWithBuffer , // Desired output amount
190197 fee : 3000 ,
@@ -256,10 +263,10 @@ export class LayerZeroGatewayClient extends GatewayApiClient {
256263 const receiverAddress = toHexScriptPubKey ( params . toUserAddress , bitcoin . networks . bitcoin ) ;
257264
258265 const dstEid = await layerZeroClient . getEidForChain ( 'bob' ) ;
259-
260266 if ( ! dstEid ) {
261267 throw new Error ( `Destination EID not found for chain: ${ fromChain } ` ) ;
262268 }
269+
263270 const wbtcOftAddress = await layerZeroClient . getOftAddressForChain ( fromChain ) ;
264271 if ( ! wbtcOftAddress ) {
265272 throw new Error ( `WBTC OFT not found for chain: ${ fromChain } ` ) ;
@@ -307,6 +314,11 @@ export class LayerZeroGatewayClient extends GatewayApiClient {
307314 ) ,
308315 } ;
309316
317+ // we're quoting on the origin chain, so public client must be configured correctly
318+ if ( publicClient . chain ?. name . toLowerCase ( ) !== fromChain ) {
319+ throw new Error ( `Public client must be origin chain` ) ;
320+ }
321+
310322 const sendFees = await publicClient . readContract ( {
311323 abi : layerZeroOftAbi ,
312324 address : wbtcOftAddress as Hex ,
0 commit comments