Skip to content

Commit 4dd0795

Browse files
authored
removed automatic route isAvailable method (#720)
* removed comment * removed isAvailable method * removed imports
1 parent d847b4d commit 4dd0795

File tree

6 files changed

+15
-50
lines changed

6 files changed

+15
-50
lines changed

connect/__tests__/mocks/routes/automatic.ts

-4
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ export class AutomaticMockRoute<N extends Network>
6464
return true;
6565
}
6666

67-
async isAvailable(): Promise<boolean> {
68-
return true;
69-
}
70-
7167
async validate(
7268
request: RouteTransferRequest<N>,
7369
params: TransferParams<Op>,

connect/src/routes/cctp/automatic.ts

-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ export class AutomaticCCTPRoute<N extends Network>
110110
};
111111
}
112112

113-
async isAvailable(): Promise<boolean> {
114-
return true;
115-
}
116-
117113
async validate(request: RouteTransferRequest<N>, params: Tp): Promise<Vr> {
118114
try {
119115
const options = params.options ?? this.getDefaultOptions();

connect/src/routes/portico/automatic.ts

-4
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ export class AutomaticPorticoRoute<N extends Network>
144144
return chain.supportsPorticoBridge();
145145
}
146146

147-
async isAvailable(): Promise<boolean> {
148-
return true;
149-
}
150-
151147
getDefaultOptions(): OP {
152148
return {};
153149
}

connect/src/routes/resolver.ts

+1-22
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import {
88
import type { Wormhole } from "../wormhole.js";
99
import type { RouteTransferRequest } from "./request.js";
1010
import type { Route, RouteConstructor } from "./route.js";
11-
import { isAutomatic } from "./route.js";
1211
import { uniqueTokens } from "./token.js";
13-
import type { Options, Receipt, ValidatedTransferParams } from "./types.js";
1412

1513
export class RouteResolver<N extends Network> {
1614
wh: Wormhole<N>;
@@ -102,25 +100,6 @@ export class RouteResolver<N extends Network> {
102100
this.routeConstructors.filter((_, index) => routesSupported[index]),
103101
);
104102

105-
// Next, we make sure all supported routes are available. For relayed routes, this will ping
106-
// the relayer to make sure it's online.
107-
return await Promise.all(
108-
supportedRoutes.map(
109-
async (
110-
rc,
111-
): Promise<[Route<N, Options, ValidatedTransferParams<Options>, Receipt>, boolean]> => {
112-
const route = new rc(this.wh);
113-
try {
114-
const available = isAutomatic(route) ? await route.isAvailable(request) : true;
115-
return [route, available];
116-
} catch (e) {
117-
console.error(`failed to check if route is available for ${rc.meta.name}: `, e);
118-
return [route, false];
119-
}
120-
},
121-
),
122-
)
123-
.then((availableRoutes) => availableRoutes.filter(([_, available]) => available))
124-
.then((availableRoutes) => availableRoutes.map(([route, _]) => route!));
103+
return supportedRoutes.map((rc) => new rc(this.wh));
125104
}
126105
}

connect/src/routes/route.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,10 @@ export abstract class AutomaticRoute<
113113
R extends Receipt = Receipt,
114114
> extends Route<N, OP, VP, R> {
115115
static IS_AUTOMATIC = true;
116-
// TODO: search for usagees and update arg
117-
public abstract isAvailable(request: RouteTransferRequest<N>): Promise<boolean>;
118116
}
119117

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

124122
/**

connect/src/routes/tokenBridge/automatic.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ import { TransferState } from "../../types.js";
1414
import { Wormhole } from "../../wormhole.js";
1515
import type { StaticRouteMethods } from "../route.js";
1616
import { AutomaticRoute } from "../route.js";
17-
import {
18-
MinAmountError,
19-
} from '../types.js';
17+
import { MinAmountError } from "../types.js";
2018
import type {
2119
Quote,
2220
QuoteResult,
@@ -121,16 +119,6 @@ export class AutomaticTokenBridgeRoute<N extends Network>
121119
return { nativeGas: 0.0 };
122120
}
123121

124-
async isAvailable(request: RouteTransferRequest<N>): Promise<boolean> {
125-
const atb = await request.fromChain.getAutomaticTokenBridge();
126-
127-
if (isTokenId(request.source.id)) {
128-
return await atb.isRegisteredToken(request.source.id.address);
129-
}
130-
131-
return true;
132-
}
133-
134122
async validate(request: RouteTransferRequest<N>, params: Tp): Promise<Vr> {
135123
try {
136124
const options = params.options ?? this.getDefaultOptions();
@@ -219,6 +207,18 @@ export class AutomaticTokenBridgeRoute<N extends Network>
219207
}
220208

221209
async quote(request: RouteTransferRequest<N>, params: Vp): Promise<QR> {
210+
const atb = await request.fromChain.getAutomaticTokenBridge();
211+
212+
if (isTokenId(request.source.id)) {
213+
const isRegistered = await atb.isRegisteredToken(request.source.id.address);
214+
if (!isRegistered) {
215+
return {
216+
success: false,
217+
error: new Error("Source token is not registered"),
218+
};
219+
}
220+
}
221+
222222
try {
223223
let quote = await TokenTransfer.quoteTransfer(this.wh, request.fromChain, request.toChain, {
224224
automatic: true,

0 commit comments

Comments
 (0)