From b61347302ae5eca01fec737256a934fef72b4240 Mon Sep 17 00:00:00 2001 From: Artur Sapek Date: Wed, 4 Sep 2024 17:28:04 -0400 Subject: [PATCH] remove isAvailable method from Route interface --- connect/src/routes/cctp/automatic.ts | 4 --- connect/src/routes/portico/automatic.ts | 5 ---- connect/src/routes/resolver.ts | 27 ++------------------- connect/src/routes/route.ts | 4 +-- connect/src/routes/tokenBridge/automatic.ts | 10 -------- 5 files changed, 3 insertions(+), 47 deletions(-) diff --git a/connect/src/routes/cctp/automatic.ts b/connect/src/routes/cctp/automatic.ts index 2dff9da65..f65d35a10 100644 --- a/connect/src/routes/cctp/automatic.ts +++ b/connect/src/routes/cctp/automatic.ts @@ -109,10 +109,6 @@ export class AutomaticCCTPRoute }; } - async isAvailable(): Promise { - return true; - } - async validate(request: RouteTransferRequest, params: Tp): Promise { try { const options = params.options ?? this.getDefaultOptions(); diff --git a/connect/src/routes/portico/automatic.ts b/connect/src/routes/portico/automatic.ts index 5ec53439e..464d3cf57 100644 --- a/connect/src/routes/portico/automatic.ts +++ b/connect/src/routes/portico/automatic.ts @@ -162,11 +162,6 @@ export class AutomaticPorticoRoute return chain.supportsPorticoBridge(); } - async isAvailable(): Promise { - // TODO: - return true; - } - getDefaultOptions(): OP { return {}; } diff --git a/connect/src/routes/resolver.ts b/connect/src/routes/resolver.ts index 9e66a248e..357b81189 100644 --- a/connect/src/routes/resolver.ts +++ b/connect/src/routes/resolver.ts @@ -8,9 +8,7 @@ import { import type { Wormhole } from "../wormhole.js"; import type { RouteTransferRequest } from "./request.js"; import type { Route, RouteConstructor } from "./route.js"; -import { isAutomatic } from "./route.js"; import { uniqueTokens } from "./token.js"; -import type { Options, Receipt, ValidatedTransferParams } from "./types.js"; export class RouteResolver { wh: Wormhole; @@ -58,7 +56,7 @@ export class RouteResolver { async findRoutes(request: RouteTransferRequest): Promise[]> { // First we find all routes which support the request inputs (network, chains, and tokens) - const supportedRoutes = await Promise.all( + return await Promise.all( this.routeConstructors.map(async (rc) => { try { const protocolSupported = @@ -99,28 +97,7 @@ export class RouteResolver { } }), ).then((routesSupported) => - this.routeConstructors.filter((_, index) => routesSupported[index]), + this.routeConstructors.filter((_, index) => routesSupported[index]).map((rc) => new rc(this.wh)) ); - - // Next, we make sure all supported routes are available. For relayed routes, this will ping - // the relayer to make sure it's online. - return await Promise.all( - supportedRoutes.map( - async ( - rc, - ): Promise<[Route, Receipt>, boolean]> => { - const route = new rc(this.wh); - try { - const available = isAutomatic(route) ? await route.isAvailable(request) : true; - return [route, available]; - } catch (e) { - console.error(`failed to check if route is available for ${rc.meta.name}: `, e); - return [route, false]; - } - }, - ), - ) - .then((availableRoutes) => availableRoutes.filter(([_, available]) => available)) - .then((availableRoutes) => availableRoutes.map(([route, _]) => route!)); } } diff --git a/connect/src/routes/route.ts b/connect/src/routes/route.ts index 04528f075..068ea768d 100644 --- a/connect/src/routes/route.ts +++ b/connect/src/routes/route.ts @@ -113,12 +113,10 @@ export abstract class AutomaticRoute< R extends Receipt = Receipt, > extends Route { static IS_AUTOMATIC = true; - // TODO: search for usagees and update arg - public abstract isAvailable(request: RouteTransferRequest): Promise; } export function isAutomatic(route: Route): route is AutomaticRoute { - return (route as AutomaticRoute).isAvailable !== undefined && (route.constructor as RouteConstructor).IS_AUTOMATIC; + return (route.constructor as RouteConstructor).IS_AUTOMATIC; } /** diff --git a/connect/src/routes/tokenBridge/automatic.ts b/connect/src/routes/tokenBridge/automatic.ts index d19ae699d..c8d2f2e1b 100644 --- a/connect/src/routes/tokenBridge/automatic.ts +++ b/connect/src/routes/tokenBridge/automatic.ts @@ -118,16 +118,6 @@ export class AutomaticTokenBridgeRoute return { nativeGas: 0.0 }; } - async isAvailable(request: RouteTransferRequest): Promise { - const atb = await request.fromChain.getAutomaticTokenBridge(); - - if (isTokenId(request.source.id)) { - return await atb.isRegisteredToken(request.source.id.address); - } - - return true; - } - async validate(request: RouteTransferRequest, params: Tp): Promise { try { const options = params.options ?? this.getDefaultOptions();