Skip to content
Open
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
26 changes: 12 additions & 14 deletions cli/src/__tests__/xrpl-onboarding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,25 @@ describe("buildInitData", () => {
expect(buildInitData(8, { type: "xrp" })).toBe("08");
});

test("iou: decimals + 0x01 + currency + issuer, right-padded to 43 bytes total", () => {
test("iou: decimals + 0x01 + currency + issuer = 42 bytes total (no padding)", () => {
const out = buildInitData(9, {
type: "iou",
currency: FOO_CURRENCY,
issuer: ADMIN,
});
const issuerHex = Buffer.from(decodeAccountID(ADMIN)).toString("hex");
// 1 (decimals) + 42 (token_id padded) = 43 bytes => 86 hex chars
expect(out.length).toBe(86);
expect(
out.startsWith("09" + "01" + FOO_CURRENCY.toLowerCase() + issuerHex)
).toBe(true);
// trailing byte is zero padding (41 bytes of data -> padded to 42)
expect(out.endsWith("00")).toBe(true);
// 1 (decimals) + 41 (token_id) = 42 bytes => 84 hex chars
expect(out.length).toBe(84);
// IOU token_id fills all 41 bytes (1 + 20 + 20) with no trailing padding.
expect(out).toBe("09" + "01" + FOO_CURRENCY.toLowerCase() + issuerHex);
});

test("mpt: decimals + 0x02 + mpt_id, right-padded to 43 bytes total", () => {
test("mpt: decimals + 0x02 + mpt_id, right-padded to 42 bytes total", () => {
const out = buildInitData(9, { type: "mpt", mptId: MPT_ID });
expect(out.length).toBe(86);
// 1 (decimals) + 41 (token_id: 0x02 + 24-byte id, padded from 25 to 41) = 42 bytes => 84 hex chars
expect(out.length).toBe(84);
expect(out.startsWith("09" + "02" + MPT_ID)).toBe(true);
// 1 + 2 + 48 = 51 hex of data, padded to 84 -> ends in zeros
// 1 + 24 = 25 bytes of data in the 41-byte token_id -> 16 trailing zero bytes
expect(out.endsWith("0000")).toBe(true);
});

Expand Down Expand Up @@ -95,7 +93,7 @@ describe("buildOnboardingPayload", () => {
expect(out.length).toBe(146);
});

test("full form (iou) is 115 bytes", () => {
test("full form (iou) is 114 bytes", () => {
const initData = buildInitData(8, {
type: "iou",
currency: FOO_CURRENCY,
Expand All @@ -108,8 +106,8 @@ describe("buildOnboardingPayload", () => {
ticketCount: 2n,
initData,
});
// 72 (fixed) + 43 (init_data) = 115 bytes => 230 hex chars
expect(out.length).toBe(230);
// 72 (fixed) + 42 (init_data) = 114 bytes => 228 hex chars
expect(out.length).toBe(228);
});
});

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/xrpl/fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function createXrplFundCommand(
.option("tickets", {
describe: "Ticket count to size the reserve for",
type: "number",
default: 200,
default: 150,
})
.option("faucet", {
describe: "Use the testnet/devnet faucet to fund --account",
Expand Down
10 changes: 5 additions & 5 deletions cli/src/commands/xrpl/reserve-tickets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
} from "../../xrpl/helpers";
import { withCommon } from "./common";

// XRPL caps an account at 250 tickets.
const MAX_TICKETS = 250;
// XRPL caps an account at 170 tickets.
const MAX_TICKETS = 170;

export function createXrplReserveTicketsCommand(
overrides: WormholeConfigOverrides<Network>
Expand All @@ -27,15 +27,15 @@ export function createXrplReserveTicketsCommand(
.option("count", {
describe: `Number of tickets to create (1-${MAX_TICKETS})`,
type: "number",
default: 200,
default: 150,
})
.option("issuer-seed", {
describe: "Custody account seed (or env ISSUER_SEED)",
type: "string",
})
.example(
"$0 xrpl reserve-tickets -n Testnet --count 200 --issuer-seed sEd7...",
"Reserve 200 tickets on the custody account"
"$0 xrpl reserve-tickets -n Testnet --count 150 --issuer-seed sEd7...",
"Reserve 150 tickets on the custody account"
),
handler: (argv: any) =>
runXrpl(async () => {
Expand Down
8 changes: 4 additions & 4 deletions cli/src/commands/xrpl/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export async function runTransfer(
if (!argv.relay) {
console.log(
colors.dim(
`\nRelay later with:\n ntt xrpl relay -n ${network} --request-type ern1 \\\n --tx-hash ${txHash} --dst-chain ${argv["dst-chain"]} \\\n --dst-addr ${argv.recipient} --manager ${custody} --executor <executor> --seed <seed>`
`\nRelay later with:\n ntt xrpl relay -n ${network} --request-type ERN1 \\\n --tx-hash ${txHash} --dst-chain ${argv["dst-chain"]} \\\n --dst-addr ${argv.recipient} --manager ${custody} --executor <executor> --seed <seed>`
)
);
return;
Expand All @@ -287,18 +287,18 @@ export async function runTransfer(
throw new Error("--executor is required to relay (or pass --no-relay)");
}

// Hand off to the existing relay flow: it re-derives the ern1 transceiver
// Hand off to the existing relay flow: it re-derives the ERN1 transceiver
// emitter + sequence from the tx, polls the VAA, and sends the executor memo.
// `--manager custody` lets relay derive the source NTT manager emitter.
console.log(colors.blue("\n↪ Relaying transfer (ern1)..."));
console.log(colors.blue("\n↪ Relaying transfer (ERN1)..."));
await runRelay(
{
network,
rpc: argv.rpc,
algorithm: argv.algorithm,
"tx-hash": txHash,
"dst-chain": argv["dst-chain"],
"request-type": "ern1",
"request-type": "ERN1",
"dst-addr": argv.recipient,
manager: custody,
"src-manager": argv["src-manager"],
Expand Down
8 changes: 5 additions & 3 deletions cli/src/xrpl/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const TOKEN_TYPE_IOU = "01";
const TOKEN_TYPE_MPT = "02";

// Size (in bytes) the token_id portion of init_data is right-padded to.
const TOKEN_ID_PADDED_BYTES = 42;
// Must match the Sequencer's `XrplTokenId::STORAGE_SIZE` (41 bytes:
// 1 discriminant + 20 currency + 20 issuer for the largest, IOU, variant).
const TOKEN_ID_PADDED_BYTES = 41;

export type TokenInit =
| { type: "xrp" }
Expand Down Expand Up @@ -110,8 +112,8 @@ export function currencyToHex40(currency: string): string {
/**
* Build the NTT/WTT `init_data` tail (hex, no 0x prefix):
* - xrp: short form — just the decimals byte.
* - iou: decimals byte + (0x01 + currency[20] + issuer[20]) right-padded to 42 bytes.
* - mpt: decimals byte + (0x02 + mpt_issuance_id[24]) right-padded to 42 bytes.
* - iou: decimals byte + (0x01 + currency[20] + issuer[20]) = 41 bytes (no padding).
* - mpt: decimals byte + (0x02 + mpt_issuance_id[24]) right-padded to 41 bytes.
*/
export function buildInitData(decimals: number, token: TokenInit): string {
const dec = u8Hex(decimals);
Expand Down
Loading