diff --git a/packages/swap/src/providers/paraswap/index.ts b/packages/swap/src/providers/paraswap/index.ts index a3ee7f010..0dd39ed94 100644 --- a/packages/swap/src/providers/paraswap/index.ts +++ b/packages/swap/src/providers/paraswap/index.ts @@ -198,7 +198,7 @@ class ParaSwap extends ProviderClass { .then((res) => res.json()) .then(async (response: ParaswapResponseType) => { if (response.error) { - console.error(response.error); + console.error("Error in swap response from ParaSwap", response.error); return Promise.resolve(null); } const transactions: EVMTransaction[] = []; @@ -245,7 +245,7 @@ class ParaSwap extends ProviderClass { }; }) .catch((e) => { - console.error(e); + console.error("Error generating swap from ParaSwap", e); return Promise.resolve(null); }); } @@ -283,6 +283,18 @@ class ParaSwap extends ProviderClass { .then((j) => j.json()) .then(async (jsonRes) => { if (!jsonRes) return null; + // Note: sometimes `jsonRes.priceRoute` is undefined and "error" is set instead + if (!jsonRes.priceRoute) { + if (jsonRes.error) { + // Sometimes ParaSwap returns this error: "No routes found with enough liquidity" + throw new Error(`ParaSwap error getting prices: ${jsonRes.error}`); + } else { + // Didn't have the expected "priceRoute" property + throw new Error( + `ParaSwap error getting prices, no "priceRoute" property on response: ${JSON.stringify(jsonRes)}`, + ); + } + } const res: ParaswpQuoteResponse = jsonRes.priceRoute; const transactions: EVMTransaction[] = []; if (options.fromToken.address !== NATIVE_TOKEN_ADDRESS) { @@ -320,7 +332,7 @@ class ParaSwap extends ProviderClass { return response; }) .catch((e) => { - console.error(e); + console.error("Error getting quote from ParaSwap", e); return Promise.resolve(null); }); } diff --git a/packages/swap/src/providers/rango/index.ts b/packages/swap/src/providers/rango/index.ts index aaa4f5651..e4bc0c549 100644 --- a/packages/swap/src/providers/rango/index.ts +++ b/packages/swap/src/providers/rango/index.ts @@ -311,6 +311,13 @@ class Rango extends ProviderClass { async init(tokenList?: TokenType[]): Promise { logger.info(`init: Initialising against ${tokenList?.length} tokens...`); + if (!Rango.isNetworkSupportedByEnkrypt(this.network)) { + logger.info( + `init: Enkrypt does not support network on Rango: ${this.network}`, + ); + return; + } + const [rangoMeta, swaplist] = await Promise.all([ rangoClient.meta({ excludeNonPopulars: true, @@ -429,10 +436,16 @@ class Rango extends ProviderClass { return matchingRangoBlockchain; } + static isNetworkSupportedByEnkrypt( + supportedNetworkName: SupportedNetworkName, + ): boolean { + return supportedNetworkInfoByName.has(supportedNetworkName); + } + /** * Is this network supported by both enkrypt and rango? */ - static isNetworkSupported( + static isNetworkSupportedByEnkryptAndRango( supportedNetworkName: SupportedNetworkName, rangoBlockchains: ReadonlyArray, ): boolean { diff --git a/packages/swap/src/providers/rango/supported.ts b/packages/swap/src/providers/rango/supported.ts index 0b4f5fb10..272300fd6 100644 --- a/packages/swap/src/providers/rango/supported.ts +++ b/packages/swap/src/providers/rango/supported.ts @@ -1,4 +1,4 @@ -import { SupportedNetworkName, } from '../../types' +import { SupportedNetworkName } from "../../types"; export type SupportedNetworkInfo = { /** Standard base10 chain ID, can be obtained from `https://chainlist.org` */ @@ -179,4 +179,3 @@ export const supportedNetworkByRangoBlockchain = new Map< }, ]), ); - diff --git a/packages/swap/tests/changelly.test.ts b/packages/swap/tests/changelly.test.ts index 3f9708c42..b1f9ade80 100644 --- a/packages/swap/tests/changelly.test.ts +++ b/packages/swap/tests/changelly.test.ts @@ -51,9 +51,7 @@ describe("Changelly Provider", () => { (swap?.transactions[0] as EVMTransaction).data.startsWith("0xa9059cbb"), ).to.be.eq(true); const status = await changelly.getStatus( - ( - await swap!.getStatusObject({ transactions: [] }) - ).options, + (await swap!.getStatusObject({ transactions: [] })).options, ); expect(status).to.be.eq("pending"); });