Skip to content

Commit 937ba6f

Browse files
committed
replace redeem instructions
1 parent 0260c34 commit 937ba6f

File tree

2 files changed

+38
-44
lines changed

2 files changed

+38
-44
lines changed

solana/ts/lib/ntt.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
Chain,
1818
ChainAddress,
1919
ChainId,
20-
deserialize,
20+
VAA,
2121
deserializeLayout,
2222
encoding,
2323
keccak256,
@@ -727,12 +727,13 @@ export namespace NTT {
727727
args: {
728728
wormholeId: PublicKey;
729729
payer: PublicKey;
730-
vaa: Uint8Array;
731-
}
730+
vaa: VAA<"Ntt:WormholeTransfer">;
731+
},
732+
pdas?: Pdas
732733
): Promise<TransactionInstruction> {
733-
const pdas = NTT.pdas(program.programId);
734+
pdas = pdas ?? NTT.pdas(program.programId);
734735

735-
const wormholeNTT = deserialize("Ntt:WormholeTransfer", args.vaa);
736+
const wormholeNTT = args.vaa;
736737
const nttMessage = wormholeNTT.payload.nttManagerPayload;
737738
const chain = wormholeNTT.emitterChain;
738739

@@ -760,13 +761,13 @@ export namespace NTT {
760761
config: NttBindings.Config<IdlVersion>,
761762
args: {
762763
payer: PublicKey;
763-
vaa: Uint8Array;
764+
vaa: VAA<"Ntt:WormholeTransfer">;
764765
},
765766
pdas?: Pdas
766767
): Promise<TransactionInstruction> {
767768
pdas = pdas ?? NTT.pdas(program.programId);
768769

769-
const wormholeNTT = deserialize("Ntt:WormholeTransfer", args.vaa);
770+
const wormholeNTT = args.vaa;
770771
const nttMessage = wormholeNTT.payload.nttManagerPayload;
771772
const chain = wormholeNTT.emitterChain;
772773

@@ -790,6 +791,7 @@ export namespace NTT {
790791
}
791792

792793
// Account access
794+
793795
/**
794796
* Fetches the Config account from the contract.
795797
*

solana/ts/sdk/ntt.ts

+29-37
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,19 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
615615
yield* this.core.postVaa(payer, wormholeNTT);
616616

617617
const senderAddress = new SolanaAddress(payer).unwrap();
618-
const nttMessage = wormholeNTT.payload["nttManagerPayload"];
619-
const emitterChain = wormholeNTT.emitterChain;
620618

619+
const receiveMessageIx = NTT.createReceiveWormholeMessageInstruction(
620+
this.program,
621+
{
622+
wormholeId: new PublicKey(this.core.address),
623+
payer: senderAddress,
624+
vaa: wormholeNTT,
625+
},
626+
this.pdas
627+
);
628+
629+
const nttMessage = wormholeNTT.payload.nttManagerPayload;
630+
const emitterChain = wormholeNTT.emitterChain;
621631
const releaseArgs = {
622632
payer: senderAddress,
623633
config,
@@ -629,17 +639,27 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
629639
revertOnDelay: false,
630640
};
631641

632-
const [receiveMessageIx, redeemIx, releaseIx] = await Promise.all([
633-
this.createReceiveWormholeMessageInstruction(senderAddress, wormholeNTT),
634-
this.createRedeemInstruction(senderAddress, wormholeNTT),
642+
const redeemIx = NTT.createRedeemInstruction(this.program, config, {
643+
payer: senderAddress,
644+
vaa: wormholeNTT,
645+
});
646+
647+
const releaseIx =
635648
config.mode.locking != null
636-
? this.createReleaseInboundUnlockInstruction(releaseArgs)
637-
: this.createReleaseInboundMintInstruction(releaseArgs),
638-
]);
649+
? NTT.createReleaseInboundUnlockInstruction(
650+
this.program,
651+
config,
652+
releaseArgs
653+
)
654+
: NTT.createReleaseInboundMintInstruction(
655+
this.program,
656+
config,
657+
releaseArgs
658+
);
639659

640660
const tx = new Transaction();
641661
tx.feePayer = senderAddress;
642-
tx.add(receiveMessageIx, redeemIx, releaseIx);
662+
tx.add(...(await Promise.all([receiveMessageIx, redeemIx, releaseIx])));
643663

644664
const luts: AddressLookupTableAccount[] = [];
645665

@@ -757,34 +777,6 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
757777
return xfer;
758778
}
759779

760-
async createReceiveWormholeMessageInstruction(
761-
payer: PublicKey,
762-
wormholeNTT: WormholeNttTransceiver.VAA
763-
): Promise<TransactionInstruction> {
764-
const config = await this.getConfig();
765-
if (config.paused) throw new Error("Contract is paused");
766-
767-
const nttMessage = wormholeNTT.payload["nttManagerPayload"];
768-
const emitterChain = wormholeNTT.emitterChain;
769-
return await this.program.methods
770-
.receiveWormholeMessage()
771-
.accountsStrict({
772-
payer: payer,
773-
config: { config: this.pdas.configAccount() },
774-
peer: this.pdas.transceiverPeerAccount(emitterChain),
775-
vaa: utils.derivePostedVaaKey(
776-
this.core.address,
777-
Buffer.from(wormholeNTT.hash)
778-
),
779-
transceiverMessage: this.pdas.transceiverMessageAccount(
780-
emitterChain,
781-
nttMessage.id
782-
),
783-
systemProgram: SystemProgram.programId,
784-
})
785-
.instruction();
786-
}
787-
788780
async createRedeemInstruction(
789781
payer: PublicKey,
790782
wormholeNTT: WormholeNttTransceiver.VAA

0 commit comments

Comments
 (0)