Skip to content
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
10 changes: 7 additions & 3 deletions cli/src/commands/token-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ import type {
Ntt,
NttWithExecutor,
} from "@wormhole-foundation/sdk-definitions-ntt";
import "@wormhole-foundation/sdk-evm-ntt";
import "@wormhole-foundation/sdk-solana-ntt";
import "@wormhole-foundation/sdk-sui-ntt";
import { register as registerEvm } from "@wormhole-foundation/sdk-evm-ntt";
import { register as registerSolana } from "@wormhole-foundation/sdk-solana-ntt";
import { register as registerSui } from "@wormhole-foundation/sdk-sui-ntt";

registerEvm();
registerSolana();
registerSui();
import { loadConfig, type ChainConfig, type Config } from "../deployments";
import fs from "fs";
import readline from "readline";
Expand Down
11 changes: 7 additions & 4 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import type { WormholeConfigOverrides } from "@wormhole-foundation/sdk-connect";
import fs from "fs";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import "@wormhole-foundation/sdk-evm-ntt";
import "@wormhole-foundation/sdk-solana-ntt";
import "@wormhole-foundation/sdk-sui-ntt";
import "@wormhole-foundation/sdk-definitions-ntt";
import { register as registerEvm } from "@wormhole-foundation/sdk-evm-ntt";
import { register as registerSolana } from "@wormhole-foundation/sdk-solana-ntt";
import { register as registerSui } from "@wormhole-foundation/sdk-sui-ntt";

registerEvm();
registerSolana();
registerSui();

import { createTokenTransferCommand } from "./commands/token-transfer";
import {
Expand Down
22 changes: 14 additions & 8 deletions evm/ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import { EvmMultiTokenNtt } from "./multiTokenNtt.js";
import { EvmMultiTokenNttWithExecutor } from "./multiTokenNttWithExecutor.js";
import { register as registerDefinitions } from "@wormhole-foundation/sdk-definitions-ntt";

let _explicitlyRegistered = false;

/** Explicitly register EVM NTT protocols. Idempotent — safe to call multiple times. */
export function register(topLevel = false): void {
if (topLevel) {
console.warn(
"@wormhole-foundation/sdk-evm-ntt: auto-registration on import is deprecated. Import { register } and call it explicitly."
);
}
export function register(_deprecatedTopLevel?: boolean): void {
_explicitlyRegistered = true;
registerDefinitions();
if (!protocolIsRegistered(_platform, "Ntt")) {
registerProtocol(_platform, "Ntt", EvmNtt);
Expand All @@ -35,9 +33,17 @@ export function register(topLevel = false): void {
}
}

// Backward-compatible: auto-register on import
// Backward-compatible: auto-register on import.
// Deferred so that consumers who call register() explicitly don't see the warning.
// TODO: remove this next time we are cool with a major version bump and are OK requiring integrators to make code changes
register(true);
setTimeout(() => {
if (!_explicitlyRegistered) {
console.warn(
"@wormhole-foundation/sdk-evm-ntt: auto-registration on import is deprecated. Import { register } and call it explicitly."
);
}
register();
}, 0);

export * as ethers_contracts from "./ethers-contracts/index.js";
export * from "./ntt.js";
Expand Down
38 changes: 38 additions & 0 deletions sdk/definitions/__tests__/registerWarning.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
describe("definitions register warning behavior", () => {
let warnSpy: jest.SpyInstance;

beforeEach(() => {
jest.resetModules();
jest.useFakeTimers();
warnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
});

afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
warnSpy.mockRestore();
});

test("does not warn when register() is called explicitly", async () => {
await jest.isolateModulesAsync(async () => {
const mod = await import("../src/index.js");
mod.register();
});

jest.runOnlyPendingTimers();
expect(warnSpy).not.toHaveBeenCalled();
});

test("warns when relying on side-effect import auto-registration", async () => {
await jest.isolateModulesAsync(async () => {
await import("../src/index.js");
});

jest.runOnlyPendingTimers();
expect(warnSpy).toHaveBeenCalledWith(
expect.stringContaining(
"@wormhole-foundation/sdk-definitions-ntt: auto-registration on import is deprecated."
)
);
});
});
22 changes: 14 additions & 8 deletions sdk/definitions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import {
nttNamedPayloads,
} from "./layouts/index.js";

let _explicitlyRegistered = false;

/** Explicitly register NTT payload types. Idempotent — safe to call multiple times. */
export function register(topLevel = false): void {
if (topLevel) {
console.warn(
"@wormhole-foundation/sdk-definitions-ntt: auto-registration on import is deprecated. Import { register } and call it explicitly."
);
}
export function register(_deprecatedTopLevel?: boolean): void {
_explicitlyRegistered = true;
if (!payloadFactory.has(composeLiteral("Ntt", nttNamedPayloads[0]![0]))) {
registerPayloadTypes("Ntt", nttNamedPayloads);
}
Expand All @@ -27,9 +25,17 @@ export function register(topLevel = false): void {
}
}

// Backward-compatible: auto-register on import
// Backward-compatible: auto-register on import.
// Deferred so that consumers who call register() explicitly don't see the warning.
// TODO: remove this next time we are cool with a major version bump and are OK requiring integrators to make code changes
register(true);
setTimeout(() => {
if (!_explicitlyRegistered) {
console.warn(
"@wormhole-foundation/sdk-definitions-ntt: auto-registration on import is deprecated. Import { register } and call it explicitly."
);
}
register();
}, 0);

export * from "./ntt.js";
export * from "./nttWithExecutor.js";
Expand Down
22 changes: 14 additions & 8 deletions solana/ts/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import { SolanaNttWithExecutor } from "./nttWithExecutor.js";
import { register as registerDefinitions } from "@wormhole-foundation/sdk-definitions-ntt";
import "./side-effects";

let _explicitlyRegistered = false;

/** Explicitly register Solana NTT protocols. Idempotent — safe to call multiple times. */
export function register(topLevel = false): void {
if (topLevel) {
console.warn(
"@wormhole-foundation/sdk-solana-ntt: auto-registration on import is deprecated. Import { register } and call it explicitly."
);
}
export function register(_deprecatedTopLevel?: boolean): void {
_explicitlyRegistered = true;
registerDefinitions();
if (!protocolIsRegistered(_platform, "Ntt")) {
registerProtocol(_platform, "Ntt", SolanaNtt);
Expand All @@ -24,9 +22,17 @@ export function register(topLevel = false): void {
}
}

// Backward-compatible: auto-register on import
// Backward-compatible: auto-register on import.
// Deferred so that consumers who call register() explicitly don't see the warning.
// TODO: remove this next time we are cool with a major version bump and are OK requiring integrators to make code changes
register(true);
setTimeout(() => {
if (!_explicitlyRegistered) {
console.warn(
"@wormhole-foundation/sdk-solana-ntt: auto-registration on import is deprecated. Import { register } and call it explicitly."
);
}
register();
}, 0);

export * from "./ntt.js";
export * from "./nttWithExecutor.js";
22 changes: 14 additions & 8 deletions sui/ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import { SuiNtt } from "./ntt.js";
import { SuiNttWithExecutor } from "./nttWithExecutor.js";
import { register as registerDefinitions } from "@wormhole-foundation/sdk-definitions-ntt";

let _explicitlyRegistered = false;

/** Explicitly register Sui NTT protocols. Idempotent — safe to call multiple times. */
export function register(topLevel = false): void {
if (topLevel) {
console.warn(
"@wormhole-foundation/sdk-sui-ntt: auto-registration on import is deprecated. Import { register } and call it explicitly."
);
}
export function register(_deprecatedTopLevel?: boolean): void {
_explicitlyRegistered = true;
registerDefinitions();
if (!protocolIsRegistered(_platform, "Ntt")) {
registerProtocol(_platform, "Ntt", SuiNtt);
Expand All @@ -23,9 +21,17 @@ export function register(topLevel = false): void {
}
}

// Backward-compatible: auto-register on import
// Backward-compatible: auto-register on import.
// Deferred so that consumers who call register() explicitly don't see the warning.
// TODO: remove this next time we are cool with a major version bump and are OK requiring integrators to make code changes
register(true);
setTimeout(() => {
if (!_explicitlyRegistered) {
console.warn(
"@wormhole-foundation/sdk-sui-ntt: auto-registration on import is deprecated. Import { register } and call it explicitly."
);
}
register();
}, 0);

export * from "./ntt.js";
export * from "./nttWithExecutor.js";
Loading