Skip to content

Commit 8ee41c4

Browse files
authored
cli: add Solana Wormhole transceiver registration to the add-chain command (#727)
* add Solana Wormhole transceier registration to the add-chain command * remove try catch around registerSolanaTransceiver, cause the function already has a try catch and doesn't rethrow * use try & catch block around helper function, instead of inside it * move registerSolanaTransceiver function to the initialize section of solana deploy * change back bindings * remove space * remove postmessageShim guard
1 parent 2743293 commit 8ee41c4

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

cli/src/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import {
6767
SolanaAddress,
6868
} from "@wormhole-foundation/sdk-solana";
6969
import { type SuiChains } from "@wormhole-foundation/sdk-sui";
70+
import { registerSolanaTransceiver } from "./solanaHelpers";
7071

7172
import { colorizeDiff, diffObjects } from "./diff";
7273
import { forgeSignerArgs, getSigner, type SignerType } from "./getSigner";
@@ -1260,12 +1261,9 @@ yargs(hideBin(process.argv))
12601261
continue;
12611262
}
12621263
const solanaNtt = ntt as SolanaNtt<Network, SolanaChains>;
1263-
const tx = solanaNtt.registerWormholeTransceiver({
1264-
payer: signer.address.address as AccountAddress<SolanaChains>,
1265-
owner: signer.address.address as AccountAddress<SolanaChains>,
1266-
});
1264+
const solanaCtx = ctx as ChainContext<Network, SolanaChains>;
12671265
try {
1268-
await signSendWait(ctx, tx, signer.signer);
1266+
await registerSolanaTransceiver(solanaNtt, solanaCtx, signer);
12691267
} catch (e: any) {
12701268
console.error(e.logs);
12711269
}
@@ -3461,6 +3459,13 @@ async function deploySolana<N extends Network, C extends SolanaChains>(
34613459
} catch (e: any) {
34623460
console.error(e.logs);
34633461
}
3462+
3463+
// After initialize, attempt to register the Wormhole transceiver
3464+
try {
3465+
await registerSolanaTransceiver(ntt as any, ch, signer);
3466+
} catch (e: any) {
3467+
console.error(e.logs);
3468+
}
34643469
}
34653470

34663471
return { chain: ch.chain, address: toUniversal(ch.chain, providedProgramId) };

cli/src/solanaHelpers.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import chalk from "chalk";
2+
import { signSendWait, type AccountAddress, chainToPlatform } from "@wormhole-foundation/sdk";
3+
import type { SolanaChains } from "@wormhole-foundation/sdk-solana";
4+
import type { SolanaNtt } from "@wormhole-foundation/sdk-solana-ntt";
5+
6+
export async function registerSolanaTransceiver<N, C extends SolanaChains>(
7+
solanaNtt: SolanaNtt<any, C>,
8+
ctx: any,
9+
signer: any
10+
): Promise<void> {
11+
if (!ctx || chainToPlatform(ctx.chain) !== "Solana") {
12+
throw new Error("registerSolanaTransceiver called with non-Solana context");
13+
}
14+
15+
const registerTx = solanaNtt.registerWormholeTransceiver({
16+
payer: signer.address.address as any as AccountAddress<C>,
17+
owner: signer.address.address as any as AccountAddress<C>,
18+
});
19+
await signSendWait(ctx, registerTx, signer.signer as any);
20+
console.log(chalk.green("Wormhole transceiver registered successfully"));
21+
}

0 commit comments

Comments
 (0)