Skip to content

Commit

Permalink
removed isAvailable method
Browse files Browse the repository at this point in the history
  • Loading branch information
kev1n-peters committed Nov 8, 2024
1 parent f1887c9 commit 0d32790
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 47 deletions.
4 changes: 0 additions & 4 deletions connect/__tests__/mocks/routes/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ export class AutomaticMockRoute<N extends Network>
return true;
}

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

async validate(
request: RouteTransferRequest<N>,
params: TransferParams<Op>,
Expand Down
4 changes: 0 additions & 4 deletions connect/src/routes/cctp/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,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
4 changes: 0 additions & 4 deletions connect/src/routes/portico/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ export class AutomaticPorticoRoute<N extends Network>
return chain.supportsPorticoBridge();
}

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

getDefaultOptions(): OP {
return {};
}
Expand Down
21 changes: 1 addition & 20 deletions connect/src/routes/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,6 @@ export class RouteResolver<N extends Network> {
this.routeConstructors.filter((_, index) => routesSupported[index]),
);

// 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!));
return supportedRoutes.map((rc) => new rc(this.wh));
}
}
3 changes: 1 addition & 2 deletions connect/src/routes/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ export abstract class AutomaticRoute<
R extends Receipt = Receipt,
> extends Route<N, OP, VP, R> {
static IS_AUTOMATIC = true;
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
26 changes: 13 additions & 13 deletions connect/src/routes/tokenBridge/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import { TransferState } from "../../types.js";
import { Wormhole } from "../../wormhole.js";
import type { StaticRouteMethods } from "../route.js";
import { AutomaticRoute } from "../route.js";
import {
MinAmountError,
} from '../types.js';
import { MinAmountError } from "../types.js";
import type {
Quote,
QuoteResult,
Expand Down Expand Up @@ -121,16 +119,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 Expand Up @@ -219,6 +207,18 @@ export class AutomaticTokenBridgeRoute<N extends Network>
}

async quote(request: RouteTransferRequest<N>, params: Vp): Promise<QR> {
const atb = await request.fromChain.getAutomaticTokenBridge();

if (isTokenId(request.source.id)) {
const isRegistered = await atb.isRegisteredToken(request.source.id.address);
if (!isRegistered) {
return {
success: false,
error: new Error("Source token is not registered"),
};
}
}

try {
let quote = await TokenTransfer.quoteTransfer(this.wh, request.fromChain, request.toChain, {
automatic: true,
Expand Down

0 comments on commit 0d32790

Please sign in to comment.