diff --git a/packages/sdk/src/actions/getLimits.ts b/packages/sdk/src/actions/getLimits.ts index 0216bcc..99b1386 100644 --- a/packages/sdk/src/actions/getLimits.ts +++ b/packages/sdk/src/actions/getLimits.ts @@ -1,12 +1,17 @@ -import { Address } from "viem"; +import { Address, Hex } from "viem"; import { fetchAcrossApi, LoggerT } from "../utils"; import { MAINNET_API_URL } from "../constants"; +import { Amount } from "../types"; type LimitsQueryParams = { destinationChainId: number; inputToken: Address; outputToken: Address; originChainId: number; + amount?: Amount; + message?: Hex; + recipient?: Address; + relayer?: Address; }; export type GetLimitsParams = LimitsQueryParams & { diff --git a/packages/sdk/src/actions/getSuggestedFees.ts b/packages/sdk/src/actions/getSuggestedFees.ts index 2f70451..dc42dcb 100644 --- a/packages/sdk/src/actions/getSuggestedFees.ts +++ b/packages/sdk/src/actions/getSuggestedFees.ts @@ -3,8 +3,16 @@ import { LoggerT, fetchAcrossApi } from "../utils"; import { Amount, Route } from "../types"; import { MAINNET_API_URL } from "../constants"; -type SuggestedFeesQueryParams = Partial> & - Pick & { +type SuggestedFeesQueryParams = Partial< + Omit +> & + Pick< + Route, + | "originChainId" + | "destinationChainId" + | "inputTokenSymbol" + | "outputTokenSymbol" + > & { amount: Amount; recipient?: Address; message?: string; diff --git a/packages/sdk/src/client.ts b/packages/sdk/src/client.ts index c29a105..864cd1e 100644 --- a/packages/sdk/src/client.ts +++ b/packages/sdk/src/client.ts @@ -277,7 +277,7 @@ export class AcrossClient { ) { const { simulationId, simulationUrl } = await this.simulateTxOnTenderly( { - networkId: params.originChainId.toString(), + networkId: params.destinationChainId.toString(), to: e.transaction.to, data: e.transaction.data, from: e.transaction.from, @@ -296,7 +296,12 @@ export class AcrossClient { async getLimits(params: Omit) { try { - return getLimits({ ...params, apiUrl: this.apiUrl, logger: this.logger }); + const limits = await getLimits({ + ...params, + apiUrl: this.apiUrl, + logger: this.logger, + }); + return limits; } catch (e) { if ( this.tenderlySimOnError && @@ -305,7 +310,7 @@ export class AcrossClient { ) { const { simulationId, simulationUrl } = await this.simulateTxOnTenderly( { - networkId: params.originChainId.toString(), + networkId: params.destinationChainId.toString(), to: e.transaction.to, data: e.transaction.data, from: e.transaction.from, diff --git a/packages/sdk/src/errors/index.ts b/packages/sdk/src/errors/index.ts index dac9e21..391a468 100644 --- a/packages/sdk/src/errors/index.ts +++ b/packages/sdk/src/errors/index.ts @@ -42,8 +42,8 @@ export class AcrossApiError extends HttpError { ) { super( { - name: "AcrossApiError", ...params, + name: params.name ?? "AcrossApiError", }, opts, ); diff --git a/packages/sdk/src/utils/fetch.ts b/packages/sdk/src/utils/fetch.ts index d49b44c..ef77cbb 100644 --- a/packages/sdk/src/utils/fetch.ts +++ b/packages/sdk/src/utils/fetch.ts @@ -42,11 +42,7 @@ export function isOk(res: Response) { function makeFetcher( name: string, - apiErrorHandler?: ( - response: Response, - data: any, - url: string, - ) => Promise, + apiErrorHandler?: (response: Response, data: any, url: string) => void, ) { return async ( apiUrl: string, @@ -92,43 +88,40 @@ function makeFetcher( }; } -export const fetchAcrossApi = makeFetcher( - "Across API", - async (res, data, url) => { - // Check for Across API errors - if ( - typeof data === "object" && - data !== null && - "type" in data && - data.type === "AcrossApiError" - ) { - const acrossApiError = data as unknown as { - message: string; - code: AcrossErrorCodeType; - transaction: { - from: Address; - to: Address; - data: Hex; - }; +export const fetchAcrossApi = makeFetcher("Across API", (res, data, url) => { + // Check for Across API errors + if ( + typeof data === "object" && + data !== null && + "type" in data && + data.type === "AcrossApiError" + ) { + const acrossApiError = data as unknown as { + message: string; + code: AcrossErrorCodeType; + transaction: { + from: Address; + to: Address; + data: Hex; }; + }; - if (acrossApiError.code === "SIMULATION_ERROR") { - throw new AcrossApiSimulationError({ - message: acrossApiError.message, - url, - transaction: acrossApiError.transaction, - }); - } - - throw new AcrossApiError({ - status: res.status, + if (acrossApiError.code === "SIMULATION_ERROR") { + throw new AcrossApiSimulationError({ message: acrossApiError.message, url, - code: acrossApiError.code, + transaction: acrossApiError.transaction, }); } - }, -); + + throw new AcrossApiError({ + status: res.status, + message: acrossApiError.message, + url, + code: acrossApiError.code, + }); + } +}); export const fetchIndexerApi = makeFetcher( "Indexer API",