From 764126b162e2ddc9bc9b404f0759a20ab0065344 Mon Sep 17 00:00:00 2001 From: kev1n-peters <96065607+kev1n-peters@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:28:30 -0600 Subject: [PATCH] solana sdk: Fix getIsApproved to check inbox item (#550) * solana sdk: Fix getIsApproved to check inbox item getIsApproved() was returning true when the VAA was posted, causing track() to set the receipt state to DestinationInitiated prematurely. It should check if the inbox item is initialized instead. Fixes an issue that caused calls to NttManualRoute.complete() to return early and never actually complete the transfer in rare cases (receipt.DestinationInitiated === true and inbox item not created). * throw instead of return false --- solana/ts/sdk/ntt.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/solana/ts/sdk/ntt.ts b/solana/ts/sdk/ntt.ts index 67b1e8e09..3e87b81f2 100644 --- a/solana/ts/sdk/ntt.ts +++ b/solana/ts/sdk/ntt.ts @@ -800,14 +800,22 @@ export class SolanaNtt } async getIsApproved(attestation: Ntt.Attestation): Promise { - const digest = (attestation as WormholeNttTransceiver.VAA).hash; - const vaaAddress = utils.derivePostedVaaKey( - this.core.address, - Buffer.from(digest) - ); - - const info = await this.connection.getAccountInfo(vaaAddress); - return info !== null; + if (attestation.payloadName !== "WormholeTransfer") { + throw new Error(`Invalid payload: ${attestation.payloadName}`); + } + const payload = attestation.payload["nttManagerPayload"]; + try { + // check that the inbox item was initialized + const inboxItem = await this.program.account.inboxItem.fetch( + this.pdas.inboxItemAccount(attestation.emitterChain, payload) + ); + return inboxItem.init; + } catch (e: any) { + if (e.message?.includes("Account does not exist")) { + return false; + } + throw e; + } } async *completeInboundQueuedTransfer(