Skip to content

Commit a581d00

Browse files
authored
chore: make getCrossChainSwapOrders fail silently to keep getOrders stable (#885)
1 parent c9b1d0a commit a581d00

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gobob/bob-sdk",
3-
"version": "4.4.8",
3+
"version": "4.4.9",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"scripts": {

sdk/src/gateway/layerzero.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,12 +931,25 @@ export class LayerZeroGatewayClient extends GatewayApiClient {
931931
return createOrderGasEstimate * fee;
932932
}
933933

934+
/**
935+
* Fetches cross-chain swap orders initiated by a given wallet.
936+
*
937+
* @param _userAddress - Wallet address the message originated from.
938+
* @returns Array of normalized cross-chain orders.
939+
*/
934940
async getCrossChainSwapOrders(_userAddress: Address): Promise<CrossChainOrder[]> {
935941
const url = new URL(`https://scan.layerzero-api.com/v1/messages/wallet/${_userAddress}`);
936942

937943
const response = await super.safeFetch(url.toString(), undefined, 'Failed to fetch LayerZero send orders');
938944

939945
if (!response.ok) {
946+
if (response.status === 404) {
947+
// Note: The API returns an error instead of an empty JSON if the address is not found
948+
console.warn('LayerZero send orders not found. Status:', response.status, response.statusText);
949+
return [];
950+
}
951+
952+
// For all other errors: throw
940953
const errorData = await response.json().catch(() => null);
941954
throw new Error(errorData?.message || 'Failed to fetch LayerZero send orders');
942955
}

sdk/test/layerzero.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { Hex } from 'viem';
4343
import { privateKeyToAccount } from 'viem/accounts';
4444
import { getCrossChainStatus } from '../src/gateway/utils/layerzero';
4545
import { supportedChainsMapping } from '../src/gateway/utils/common';
46+
import { EsploraClient, GatewaySDK } from '../src';
4647

4748
describe('LayerZero Tests', () => {
4849
it.skip('should get chains', async () => {
@@ -143,6 +144,28 @@ describe('LayerZero Tests', () => {
143144
console.log(txHash);
144145
}, 120000);
145146

147+
it.skip(
148+
'fetches LayerZero orders and cross-chain swap orders correctly',
149+
async () => {
150+
const client = new LayerZeroGatewayClient();
151+
152+
// Case 1: Address with no cross-chain swap orders and no with gateway orders
153+
const noCrossChainSwapAddress = '0x0555E30da8f98308EdB960aa94C0Db47230d2B9c';
154+
let crossChainSwapOrders = await client.getCrossChainSwapOrders(noCrossChainSwapAddress);
155+
expect(crossChainSwapOrders.length).toBeGreaterThanOrEqual(0); // if expected
156+
let allOrders = await client.getOrders(noCrossChainSwapAddress);
157+
expect(allOrders).toHaveLength(0);
158+
159+
// Case 2: Address that has done cross-chain swaps and gateway orders
160+
const swapAddress = '0x9BD3befca3660D38F5125C48BB21bEf3e8789787';
161+
crossChainSwapOrders = await client.getCrossChainSwapOrders(swapAddress);
162+
expect(crossChainSwapOrders.length).toBeGreaterThanOrEqual(1);
163+
allOrders = await client.getOrders(swapAddress);
164+
expect(allOrders.length).toBeGreaterThanOrEqual(1);
165+
},
166+
{ timeout: 30000 }
167+
);
168+
146169
it.skip('should get an offramp quote and execute it', async () => {
147170
const client = new LayerZeroGatewayClient();
148171
const layerZeroClient = new LayerZeroClient();

0 commit comments

Comments
 (0)