Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/iris/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ export async function fetchFastTransferFeeBps(
const url = `${irisBaseUrl(useSandbox)}burn/USDC/fees/${sourceDomain}/${destDomain}`;
const res = await fetch(url);
if (!res.ok) {
throw new Error(`Iris fees request failed: ${res.status} ${res.statusText}`);
throw new IrisRequestError(
`Iris fees request failed: ${res.status} ${res.statusText}`,
res.status,
);
}
const body = (await res.json()) as IrisFeesResponse;
const fastEntry = body.find((entry) => entry.finalityThreshold <= 1000);
return fastEntry?.minimumFee ?? 0;
if (!fastEntry) {
throw new IrisRequestError(
`Iris fees response has no fast-transfer tier for domain pair ${sourceDomain} -> ${destDomain}`,
);
}
return fastEntry.minimumFee;
}

/**
Expand Down
15 changes: 10 additions & 5 deletions tests/poll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,30 @@ describe("fetchFastTransferFeeBps", () => {
expect(feeBps).toBe(2);
});

it("returns 0 when no entry at or under the fast finality threshold exists", async () => {
it("rejects when no entry at or under the fast finality threshold exists", async () => {
global.fetch = vi.fn().mockResolvedValue({
ok: true,
json: async () => [{ finalityThreshold: 2000, minimumFee: 5 }],
}) as unknown as typeof fetch;

const feeBps = await fetchFastTransferFeeBps(26, 27, true);
const err = await fetchFastTransferFeeBps(26, 27, true).catch((e) => e);

expect(feeBps).toBe(0);
expect(err).toBeInstanceOf(IrisRequestError);
expect(err.message).toContain("26 -> 27");
});

it("throws when the request fails", async () => {
it("throws IrisRequestError with the HTTP status when the request fails", async () => {
global.fetch = vi.fn().mockResolvedValue({
ok: false,
status: 500,
statusText: "Internal Server Error",
}) as unknown as typeof fetch;

await expect(fetchFastTransferFeeBps(26, 27, true)).rejects.toThrow("Iris fees request failed");
const err = await fetchFastTransferFeeBps(26, 27, true).catch((e) => e);

expect(err).toBeInstanceOf(IrisRequestError);
expect(err.message).toContain("Iris fees request failed");
expect(err.status).toBe(500);
});
});

Expand Down