Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed automatic route isAvailable method #720

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 1 addition & 22 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 @@ -102,25 +100,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));
}
}
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
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
Loading