Skip to content

Commit f88b1ea

Browse files
committed
tweak args for init, remove utils file
1 parent c5fd66e commit f88b1ea

File tree

7 files changed

+29
-52
lines changed

7 files changed

+29
-52
lines changed

sdk/__tests__/utils.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ async function deployEvm(ctx: Ctx): Promise<Ctx> {
481481
async function deploySolana(ctx: Ctx): Promise<Ctx> {
482482
const { signer, nativeSigner: keypair } = ctx.signers as Signers<"Solana">;
483483
const connection = (await ctx.context.getRpc()) as Connection;
484-
const address = new PublicKey(signer.address());
484+
const sender = Wormhole.chainAddress("Solana", signer.address());
485+
const address = sender.address.toNative("Solana").unwrap();
485486
console.log(`Using public key: ${address}`);
486487

487488
const mint = await spl.createMint(connection, keypair, address, null, 9);
@@ -534,10 +535,7 @@ async function deploySolana(ctx: Ctx): Promise<Ctx> {
534535
manager.pdas.tokenAuthority().toString()
535536
);
536537

537-
const initTxs = manager.initialize({
538-
payer: keypair.publicKey,
539-
owner: keypair.publicKey,
540-
chain: "Solana",
538+
const initTxs = manager.initialize(sender.address, {
541539
mint,
542540
outboundLimit: 1000000000n,
543541
mode: ctx.mode,

solana/tests/anchor.test.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,7 @@ describe("example-native-token-transfers", () => {
222222
);
223223

224224
// init
225-
const initTxs = ntt.initialize({
226-
payer: payer.publicKey,
227-
owner: payer.publicKey,
228-
chain: "Solana",
225+
const initTxs = ntt.initialize(sender, {
229226
mint: mint.publicKey,
230227
outboundLimit: 1000000n,
231228
mode: "burning",

solana/ts/lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./ntt.js";
22
export * from "./quoter.js";
33
export * from "./bindings.js";
4+
export * from "./anchor-idl/index.js";

solana/ts/lib/ntt.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ import {
4646
} from "./utils.js";
4747

4848
export namespace NTT {
49+
/** Arguments for transfer instruction */
4950
export interface TransferArgs {
5051
amount: BN;
5152
recipientChain: { id: ChainId };
5253
recipientAddress: number[];
5354
shouldQueue: boolean;
5455
}
5556

57+
/** utility to create TransferArgs from SDK types */
5658
export function transferArgs(
5759
amount: bigint,
5860
recipient: ChainAddress,
@@ -68,7 +70,9 @@ export namespace NTT {
6870
};
6971
}
7072

73+
/** Type of object containing methods to compute program addresses */
7174
export type Pdas = ReturnType<typeof pdas>;
75+
/** pdas returns an object containing all functions to compute program addresses */
7276
export const pdas = (programId: PublicKeyInitData) => {
7377
const configAccount = (): PublicKey => derivePda("config", programId);
7478
const emitterAccount = (): PublicKey => derivePda("emitter", programId);
@@ -111,7 +115,7 @@ export namespace NTT {
111115
sender.toBytes(),
112116
keccak256(
113117
encoding.bytes.concat(
114-
encoding.bytes.zpad(new Uint8Array(args.amount.toBuffer()), 8),
118+
encoding.bytes.zpad(new Uint8Array(args.amount.toArray()), 8),
115119
chainToBytes(args.recipientChain.id),
116120
new Uint8Array(args.recipientAddress),
117121
new Uint8Array([args.shouldQueue ? 1 : 0])

solana/ts/lib/utils/wormhole.ts

-30
This file was deleted.

solana/ts/sdk/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ import "@wormhole-foundation/sdk-definitions-ntt";
55

66
registerProtocol(_platform, "Ntt", SolanaNtt);
77

8-
export * as idl from "../lib/anchor-idl/index.js";
98
export * from "./ntt.js";

solana/ts/sdk/ntt.ts

+19-11
Original file line numberDiff line numberDiff line change
@@ -165,35 +165,43 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
165165
);
166166
}
167167

168-
async *initialize(args: {
169-
payer: PublicKey;
170-
owner: PublicKey;
171-
chain: Chain;
172-
mint: PublicKey;
173-
outboundLimit: bigint;
174-
mode: "burning" | "locking";
175-
}) {
168+
async *initialize(
169+
sender: AccountAddress<C>,
170+
args: {
171+
mint: PublicKey;
172+
mode: Ntt.Mode;
173+
outboundLimit: bigint;
174+
}
175+
) {
176176
const mintInfo = await this.connection.getAccountInfo(args.mint);
177177
if (mintInfo === null)
178178
throw new Error(
179179
"Couldn't determine token program. Mint account is null."
180180
);
181181

182+
const payer = new SolanaAddress(sender).unwrap();
183+
182184
const ix = await NTT.createInitializeInstruction(
183185
this.program,
184-
{ ...args, tokenProgram: mintInfo.owner },
186+
{
187+
...args,
188+
payer,
189+
owner: payer,
190+
chain: this.chain,
191+
tokenProgram: mintInfo.owner,
192+
},
185193
this.pdas
186194
);
187195

188196
const tx = new Transaction();
189-
tx.feePayer = args.payer;
197+
tx.feePayer = payer;
190198
tx.add(ix);
191199
yield this.createUnsignedTx(
192200
{ transaction: tx, signers: [] },
193201
"Ntt.Initialize"
194202
);
195203

196-
yield* this.initializeOrUpdateLUT({ payer: args.payer });
204+
yield* this.initializeOrUpdateLUT({ payer });
197205
}
198206

199207
// This function should be called after each upgrade. If there's nothing to

0 commit comments

Comments
 (0)