Skip to content

Commit 68e0ac8

Browse files
committed
fix: allow buffer, use correct oft, check viem clients
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
1 parent d184931 commit 68e0ac8

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

sdk/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gobob/bob-sdk",
3-
"version": "4.2.3",
3+
"version": "4.2.4",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"scripts": {
@@ -52,4 +52,4 @@
5252
"viem": "^2.33.2",
5353
"global": "^4.4.0"
5454
}
55-
}
55+
}

sdk/src/gateway/layerzero.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

sdk/src/gateway/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ export interface GatewayQuoteParams {
9595

9696
/** @description Cross chain message - strategy data */
9797
message?: Hex;
98+
99+
/** @description LayerZero fee buffer percentage in Basis Points (BPS) units to add on top of the estimated L0 fee. This accounts for potential L0 fee changes between quote time and order execution. Default is 500 BPS (5%). */
100+
l0FeeBuffer?: number | bigint;
98101
}
99102

100103
/**

sdk/test/layerzero.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('LayerZero Tests', () => {
6565
assert.equal(await client.getOftAddressForChain('sei'), '0x0555e30da8f98308edb960aa94c0db47230d2b9c');
6666
}, 120000);
6767

68-
it('should get an onramp quote and execute it', async () => {
68+
it.skip('should get an onramp quote and execute it', async () => {
6969
const client = new LayerZeroGatewayClient(bob.id);
7070

7171
const quote = await client.getQuote({
@@ -104,7 +104,7 @@ describe('LayerZero Tests', () => {
104104
console.log(txHash);
105105
}, 120000);
106106

107-
it('should get an offramp quote and execute it', async () => {
107+
it.skip('should get an offramp quote and execute it', async () => {
108108
const client = new LayerZeroGatewayClient(bob.id);
109109
const layerZeroClient = new LayerZeroClient();
110110

0 commit comments

Comments
 (0)