Skip to content

Commit 19da621

Browse files
committed
address review comments
1 parent d179714 commit 19da621

6 files changed

Lines changed: 54 additions & 140 deletions

File tree

cli/src/__tests__/xrpl-onboarding.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ describe("buildOnboardingPayload", () => {
7676
const out = buildOnboardingPayload({
7777
admin: ADMIN,
7878
app: "NTT",
79-
initialTicket: 100,
80-
ticketCount: 150,
79+
initialTicket: 100n,
80+
ticketCount: 150n,
8181
initData,
8282
});
8383

@@ -104,8 +104,8 @@ describe("buildOnboardingPayload", () => {
104104
const out = buildOnboardingPayload({
105105
admin: ADMIN,
106106
app: "NTT",
107-
initialTicket: 1,
108-
ticketCount: 2,
107+
initialTicket: 1n,
108+
ticketCount: 2n,
109109
initData,
110110
});
111111
// 72 (fixed) + 43 (init_data) = 115 bytes => 230 hex chars

cli/src/commands/xrpl/init.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ export function createXrplInitCommand(
6262
})
6363
.option("initial-ticket", {
6464
describe: "First ticket ID in the pre-allocated range",
65-
type: "number",
65+
type: "string",
6666
demandOption: true,
6767
})
6868
.option("ticket-count", {
6969
describe: "Number of tickets available",
70-
type: "number",
70+
type: "string",
7171
demandOption: true,
7272
})
7373
.option("token", {
@@ -135,8 +135,8 @@ export function createXrplInitCommand(
135135
const payload = buildOnboardingPayload({
136136
admin: argv.admin,
137137
app: APP_TYPE,
138-
initialTicket: argv["initial-ticket"],
139-
ticketCount: argv["ticket-count"],
138+
initialTicket: BigInt(argv["initial-ticket"]),
139+
ticketCount: BigInt(argv["ticket-count"]),
140140
initData,
141141
});
142142
const memoData = buildPublishMemoData(payload);

cli/src/commands/xrpl/relay.ts

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type {
22
Network,
33
WormholeConfigOverrides,
44
} from "@wormhole-foundation/sdk-connect";
5-
import { RequestPrefix } from "@wormhole-foundation/sdk-connect";
5+
import { RequestPrefix, UniversalAddress } from "@wormhole-foundation/sdk-connect";
66
import { fetchQuote, fetchStatus } from "@wormhole-foundation/sdk-connect";
7-
import { toChain, toUniversal, type Chain } from "@wormhole-foundation/sdk";
7+
import { toChain, toUniversal, type Chain, executor, CONFIG } from "@wormhole-foundation/sdk";
88
import { ethers } from "ethers";
99
import { decodeAccountID } from "xrpl";
1010
import { colors } from "../../colors.js";
@@ -17,12 +17,6 @@ import {
1717
walletFromSeed,
1818
withXrplClient,
1919
} from "../../xrpl/helpers";
20-
import { getDefaultExecutorApiForNetwork } from "../../xrpl/executor";
21-
import {
22-
CHAIN_ID_XRPL,
23-
getDefaultGuardianApiForNetwork,
24-
pollSignedVaa,
25-
} from "../../xrpl/guardian";
2620
import {
2721
buildGasInstructionHex,
2822
serializeRequest,
@@ -39,6 +33,9 @@ import {
3933
type TokenId,
4034
} from "../../xrpl/tokenId";
4135
import { withCommon } from "./common";
36+
import { getVaaBytesWithRetry } from "@wormhole-foundation/sdk-connect/whscan-api";
37+
38+
const CHAIN_ID_XRPL = 66;
4239

4340
/**
4441
* Resolve a destination address to a 32-byte universal hex. Accepts the
@@ -309,15 +306,15 @@ export async function runRelay(
309306

310307
// ── 2. Poll the guardian API for the signed VAA ──
311308
console.log(colors.blue("\n⏳ Waiting for guardian VAA..."));
312-
await pollSignedVaa({
309+
await getVaaBytesWithRetry(
313310
guardianApi,
314-
chain: CHAIN_ID_XRPL,
315-
emitterHex,
316-
sequence,
317-
pollIntervalMs: pollInterval,
318-
pollTimeoutMs: pollTimeout,
319-
onAttempt: (n, url) => console.log(colors.dim(` attempt ${n}: ${url}`)),
320-
});
311+
{
312+
chain: toChain(CHAIN_ID_XRPL),
313+
emitter: new UniversalAddress(emitterHex),
314+
sequence: sequence
315+
},
316+
pollTimeout
317+
);
321318
console.log(colors.green(" VAA available."));
322319

323320
// ── 3. Fetch a quote ──
@@ -433,3 +430,33 @@ export async function runRelay(
433430
)
434431
);
435432
}
433+
434+
/**
435+
* Default Executor API base URL for a network. Throws if there is no default
436+
* for that network (e.g. not deployed yet) — pass `--executor-api` explicitly
437+
* in that case.
438+
*/
439+
export function getDefaultExecutorApiForNetwork(network: Network): string {
440+
const api = executor.executorAPI.get(network);
441+
if (!api) {
442+
throw new Error(
443+
`No default Executor API for ${network}; pass --executor-api`
444+
);
445+
}
446+
return api;
447+
}
448+
449+
/**
450+
* Default Guardian / Wormholescan API base URL for a network. Throws if there
451+
* is no default for that network (e.g. not deployed yet) — pass `--guardian-api`
452+
* explicitly in that case.
453+
*/
454+
export function getDefaultGuardianApiForNetwork(network: Network): string {
455+
const api = CONFIG[network].api;
456+
if (!api) {
457+
throw new Error(
458+
`No default Guardian API for ${network}; pass --guardian-api`
459+
);
460+
}
461+
return api;
462+
}

cli/src/xrpl/executor.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

cli/src/xrpl/guardian.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

cli/src/xrpl/onboarding.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ const U64_MAX = (1n << 64n) - 1n;
5959
* Encode a non-negative integer that fits in a u64 as a big-endian 8-byte
6060
* (16 hex char) value. Accepts a number, bigint, or decimal string.
6161
*/
62-
function u64Hex(n: string | number | bigint): string {
63-
if (typeof n === "number" && !Number.isInteger(n)) {
64-
throw new Error(`value ${n} must be an integer`);
65-
}
62+
function u64Hex(n: string | bigint): string {
6663
let v: bigint;
6764
try {
6865
v = BigInt(n);
@@ -148,8 +145,8 @@ export function buildInitData(decimals: number, token: TokenInit): string {
148145
export function buildOnboardingPayload(params: {
149146
admin: string;
150147
app: string;
151-
initialTicket: number;
152-
ticketCount: number;
148+
initialTicket: bigint;
149+
ticketCount: bigint;
153150
initData: string;
154151
}): string {
155152
const adminHex = accountIdHex(params.admin);

0 commit comments

Comments
 (0)