Skip to content

Commit 6ee77c1

Browse files
kev1n-petersclaude
andcommitted
feat(sdk-route): group executor overrides under executor namespace on Config
Add executor.getCapabilities to NttExecutorRoute.Config and MultiTokenNttExecutorRoute.Config. Replace local type definitions with imports from sdk-definitions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 18d84c7 commit 6ee77c1

File tree

4 files changed

+41
-72
lines changed

4 files changed

+41
-72
lines changed

sdk/route/src/executor/executor.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
import "@wormhole-foundation/sdk-definitions-ntt";
4040
import { NttRoute } from "../types.js";
4141
import {
42+
type CapabilitiesResponse,
4243
calculateReferrerFee,
4344
collectTransactions,
4445
fetchCapabilities,
@@ -61,6 +62,10 @@ export namespace NttExecutorRoute {
6162
referrerFee?: ReferrerFeeConfig;
6263
// Takes priority over referrerFee if defined
6364
getReferrerFee?: ReferrerFeeCallback;
65+
executor?: {
66+
/** Override the default capabilities fetcher (e.g. to cache or use a custom endpoint). */
67+
getCapabilities?: (network: Network) => Promise<CapabilitiesResponse>;
68+
};
6469
};
6570

6671
export type ReferrerFeeConfig = {
@@ -379,7 +384,9 @@ export class NttExecutorRoute<N extends Network>
379384
throw new Error("Amount after fee <= 0");
380385
}
381386

382-
const capabilities = await fetchCapabilities(fromChain.network);
387+
const capabilities = this.staticConfig.executor?.getCapabilities
388+
? await this.staticConfig.executor.getCapabilities(fromChain.network)
389+
: await fetchCapabilities(fromChain.network);
383390
const srcCapabilities = capabilities[toChainId(fromChain.chain)];
384391
if (!srcCapabilities) {
385392
throw new Error("Unsupported source chain");

sdk/route/src/executor/multiToken.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ import {
3636
NttWithExecutor,
3737
} from "@wormhole-foundation/sdk-definitions-ntt";
3838
import {
39+
type CapabilitiesResponse,
40+
type Capabilities,
3941
calculateReferrerFee,
40-
Capabilities,
4142
collectTransactions,
4243
fetchCapabilities,
4344
fetchSignedQuote,
@@ -51,6 +52,10 @@ export namespace MultiTokenNttExecutorRoute {
5152
contracts: MultiTokenNtt.Contracts[];
5253
referrerFee?: ReferrerFeeConfig;
5354
axelarGasMultiplier?: number | "auto";
55+
executor?: {
56+
/** Override the default capabilities fetcher (e.g. to cache or use a custom endpoint). */
57+
getCapabilities?: (network: Network) => Promise<CapabilitiesResponse>;
58+
};
5459
};
5560

5661
export type ReferrerFeeConfig = NttExecutorRoute.ReferrerFeeConfig;
@@ -349,7 +354,9 @@ export class MultiTokenNttExecutorRoute<N extends Network>
349354
sourceCapabilities: Capabilities;
350355
destinationCapabilities: Capabilities;
351356
}> {
352-
const capabilities = await fetchCapabilities(fromChain.network);
357+
const capabilities = this.staticConfig.executor?.getCapabilities
358+
? await this.staticConfig.executor.getCapabilities(fromChain.network)
359+
: await fetchCapabilities(fromChain.network);
353360
const sourceCapabilities = capabilities[toChainId(fromChain.chain)];
354361
if (!sourceCapabilities) {
355362
throw new Error("Unsupported source chain");

sdk/route/src/executor/utils.ts

Lines changed: 20 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,32 @@ import {
55
amount as sdkAmount,
66
} from "@wormhole-foundation/sdk-base";
77
import type { UnsignedTransaction } from "@wormhole-foundation/sdk-definitions";
8-
import { SignedQuote } from "@wormhole-foundation/sdk-definitions";
8+
import {
9+
type CapabilitiesResponse,
10+
type Capabilities,
11+
type QuoteResponse,
12+
type RelayData,
13+
type RequestForExecution,
14+
type StatusResponse,
15+
type TxInfo,
16+
RelayStatus,
17+
RequestPrefix,
18+
} from "@wormhole-foundation/sdk-definitions";
919
import axios from "axios";
1020
import { apiBaseUrl } from "./consts.js";
1121
import { NttRoute } from "../types.js";
1222

13-
export enum RelayStatus {
14-
Pending = "pending",
15-
Failed = "failed",
16-
Unsupported = "unsupported",
17-
Submitted = "submitted",
18-
Underpaid = "underpaid",
19-
Aborted = "aborted",
20-
}
21-
22-
export type RequestForExecution = {
23-
quoterAddress: `0x${string}`;
24-
amtPaid: string;
25-
dstChain: number;
26-
dstAddr: `0x${string}`;
27-
refundAddr: `0x${string}`;
28-
signedQuoteBytes: `0x${string}`;
29-
requestBytes: `0x${string}`;
30-
relayInstructionsBytes: `0x${string}`;
31-
timestamp: Date;
32-
};
33-
34-
export type TxInfo = {
35-
txHash: string;
36-
chainId: number;
37-
blockNumber: string;
38-
blockTime: Date | null;
39-
cost: string;
23+
export { RelayStatus, RequestPrefix };
24+
export type {
25+
CapabilitiesResponse,
26+
Capabilities,
27+
QuoteResponse,
28+
RelayData,
29+
RequestForExecution,
30+
StatusResponse,
31+
TxInfo,
4032
};
4133

42-
export type RelayData = {
43-
id: `0x${string}`;
44-
txHash: string;
45-
chainId: number;
46-
status: string;
47-
estimatedCost: string;
48-
requestForExecution: RequestForExecution;
49-
instruction?: Request;
50-
txs?: TxInfo[];
51-
indexed_at: Date;
52-
};
53-
54-
export enum RequestPrefix {
55-
ERM1 = "ERM1", // MM
56-
ERV1 = "ERV1", // VAA_V1
57-
ERN1 = "ERN1", // NTT_V1
58-
ERC1 = "ERC1", // CCTP_V1
59-
ERC2 = "ERC2", // CCTP_V2
60-
}
61-
62-
export type Capabilities = {
63-
requestPrefixes: Array<keyof typeof RequestPrefix>;
64-
gasDropOffLimit: string;
65-
maxGasLimit: string;
66-
maxMsgValue: string; // the maximum msgValue, inclusive of the gasDropOffLimit
67-
};
68-
69-
export interface CapabilitiesResponse {
70-
[chainId: string]: Capabilities;
71-
}
72-
7334
export async function fetchCapabilities(
7435
network: Network
7536
): Promise<CapabilitiesResponse> {
@@ -83,11 +44,6 @@ export async function fetchCapabilities(
8344
}
8445
}
8546

86-
export interface QuoteResponse {
87-
signedQuote: `0x${string}`;
88-
estimatedCost?: string;
89-
}
90-
9147
export async function fetchSignedQuote(
9248
network: Network,
9349
srcChain: Chain,
@@ -108,11 +64,6 @@ export async function fetchSignedQuote(
10864
}
10965
}
11066

111-
export interface StatusResponse extends RelayData {
112-
signedQuote: SignedQuote;
113-
estimatedCost: string;
114-
}
115-
11667
// Fetch Status
11768
export async function fetchStatus(
11869
network: Network,

sdk/route/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ export * from "./automatic.js";
44
export * from "./multiTokenManual.js";
55
export * from "./executor/executor.js";
66
export * from "./executor/multiToken.js";
7+
export {
8+
fetchCapabilities,
9+
type CapabilitiesResponse,
10+
} from "./executor/utils.js";

0 commit comments

Comments
 (0)