Skip to content

Commit

Permalink
remove isAvailable method from Route interface
Browse files Browse the repository at this point in the history
  • Loading branch information
artursapek committed Sep 4, 2024
1 parent 007f61b commit b613473
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 47 deletions.
4 changes: 0 additions & 4 deletions connect/src/routes/cctp/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ export class AutomaticCCTPRoute<N extends Network>
};
}

async isAvailable(): Promise<boolean> {
return true;
}

async validate(request: RouteTransferRequest<N>, params: Tp): Promise<Vr> {
try {
const options = params.options ?? this.getDefaultOptions();
Expand Down
5 changes: 0 additions & 5 deletions connect/src/routes/portico/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ export class AutomaticPorticoRoute<N extends Network>
return chain.supportsPorticoBridge();
}

async isAvailable(): Promise<boolean> {
// TODO:
return true;
}

getDefaultOptions(): OP {
return {};
}
Expand Down
27 changes: 2 additions & 25 deletions connect/src/routes/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<N extends Network> {
wh: Wormhole<N>;
Expand Down Expand Up @@ -58,7 +56,7 @@ export class RouteResolver<N extends Network> {

async findRoutes(request: RouteTransferRequest<N>): Promise<Route<N>[]> {
// 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 =
Expand Down Expand Up @@ -99,28 +97,7 @@ export class RouteResolver<N extends Network> {
}
}),
).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<N, Options, ValidatedTransferParams<Options>, 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!));
}
}
4 changes: 1 addition & 3 deletions connect/src/routes/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,10 @@ export abstract class AutomaticRoute<
R extends Receipt = Receipt,
> extends Route<N, OP, VP, R> {
static IS_AUTOMATIC = true;
// TODO: search for usagees and update arg
public abstract isAvailable(request: RouteTransferRequest<N>): Promise<boolean>;
}

export function isAutomatic<N extends Network>(route: Route<N>): route is AutomaticRoute<N> {
return (route as AutomaticRoute<N>).isAvailable !== undefined && (route.constructor as RouteConstructor).IS_AUTOMATIC;
return (route.constructor as RouteConstructor).IS_AUTOMATIC;
}

/**
Expand Down
10 changes: 0 additions & 10 deletions connect/src/routes/tokenBridge/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,6 @@ export class AutomaticTokenBridgeRoute<N extends Network>
return { nativeGas: 0.0 };
}

async isAvailable(request: RouteTransferRequest<N>): Promise<boolean> {
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<N>, params: Tp): Promise<Vr> {
try {
const options = params.options ?? this.getDefaultOptions();
Expand Down

0 comments on commit b613473

Please sign in to comment.