@pythnetwork/pyth-solana-receiver
Version:
Pyth solana receiver SDK
101 lines • 5.29 kB
TypeScript
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
import { WormholeCoreBridgeSolana } from "./idl/wormhole_core_bridge_solana";
import { Program } from "@coral-xyz/anchor";
import { InstructionWithEphemeralSigners } from "@pythnetwork/solana-utils";
import { AccumulatorUpdateData } from "@pythnetwork/price-service-sdk";
/**
* Get the index of the guardian set that signed a VAA
*/
export declare function getGuardianSetIndex(vaa: Buffer): number;
/**
* The default number of signatures to keep in a VAA when using `trimSignatures`.
* This number was chosen as the maximum number of signatures so that the VAA's contents can be posted in a single Solana transaction.
*/
export declare const DEFAULT_REDUCED_GUARDIAN_SET_SIZE = 5;
/**
* The size of a guardian signature in a VAA.
*
* It is 66 bytes long, the first byte is the guardian index and the next 65 bytes are the signature (including a recovery id).
*/
export declare const VAA_SIGNATURE_SIZE = 66;
/**
* The start of the VAA bytes in an encoded VAA account. Before this offset, the account contains a header.
*/
export declare const VAA_START = 46;
/**
* Writing the VAA to an encoded VAA account is done in 2 instructions.
*
* The first one writes the first `VAA_SPLIT_INDEX` bytes and the second one writes the rest.
*
* This number was chosen as the biggest number such that one can still call `createInstruction`,
* `initEncodedVaa` and `writeEncodedVaa` in a single Solana transaction, while using an address lookup table.
* This way, the packing of the instructions to post an encoded vaa is more efficient.
*/
export declare const VAA_SPLIT_INDEX = 721;
/**
* Trim the number of signatures of a VAA.
*
* @returns the same VAA as the input, but with `n` signatures instead of the original number of signatures.
*
* A Wormhole VAA typically has a number of signatures equal to two thirds of the number of guardians. However,
* this function is useful to make VAAs smaller to post their contents in a single Solana transaction.
*/
export declare function trimSignatures(vaa: Buffer, n?: number): Buffer;
/**
* Build instructions to post a single VAA to the Wormhole program.
* The instructions can be packed efficiently into 2 transactions:
* - TX1: Create, init the encoded VAA account and write the first part of the VAA
* - TX2: Write the second part of the VAA and verify it
*
* @param wormhole - The Wormhole program instance
* @param vaa - The VAA buffer to post
* @returns {Object} Result containing:
* - encodedVaaAddress: Public key of the encoded VAA account
* - postInstructions: Instructions to post and verify the VAA
* - closeInstructions: Instructions to close the encoded VAA account and recover rent
*/
export declare function buildPostEncodedVaaInstructions(wormhole: Program<WormholeCoreBridgeSolana>, vaa: Buffer): Promise<{
encodedVaaAddress: PublicKey;
postInstructions: InstructionWithEphemeralSigners[];
closeInstructions: InstructionWithEphemeralSigners[];
}>;
/**
* Build instructions to post two VAAs for TWAP (Time-Weighted Average Price) calculations,
* optimized for 3 transactions. This is specifically designed for posting start and end
* accumulator update VAAs efficiently.
* The instructions are packed into 3 transactions:
* - TX1: Initialize and write first part of start VAA
* - TX2: Initialize and write first part of end VAA
* - TX3: Write second part and verify both VAAs
*
* @param wormhole - The Wormhole program instance
* @param startUpdateData - Accumulator update data containing the start VAA
* @param endUpdateData - Accumulator update data containing the end VAA
* @returns {Object} Result containing:
* - startEncodedVaaAddress: Public key of the start VAA account
* - endEncodedVaaAddress: Public key of the end VAA account
* - postInstructions: Instructions to post and verify both VAAs
* - closeInstructions: Instructions to close both encoded VAA accounts
*/
export declare function buildPostEncodedVaasForTwapInstructions(wormhole: Program<WormholeCoreBridgeSolana>, startUpdateData: AccumulatorUpdateData, endUpdateData: AccumulatorUpdateData): Promise<{
startEncodedVaaAddress: PublicKey;
endEncodedVaaAddress: PublicKey;
postInstructions: InstructionWithEphemeralSigners[];
closeInstructions: InstructionWithEphemeralSigners[];
}>;
/**
* Build an instruction to close an encoded VAA account, recovering the rent.
*/
export declare function buildCloseEncodedVaaInstruction(wormhole: Program<WormholeCoreBridgeSolana>, encodedVaa: PublicKey): Promise<InstructionWithEphemeralSigners>;
/**
* Build an instruction to create an encoded VAA account.
*
* This is the first step to post a VAA to the Wormhole program.
*/
export declare function buildEncodedVaaCreateInstruction(wormhole: Program<WormholeCoreBridgeSolana>, vaa: Buffer, encodedVaaKeypair: Keypair): Promise<InstructionWithEphemeralSigners>;
/**
* Find all the encoded VAA accounts that have a given write authority
* @returns a list of the public keys of the encoded VAA accounts
*/
export declare function findEncodedVaaAccountsByWriteAuthority(connection: Connection, writeAuthority: PublicKey, wormholeProgramId: PublicKey): Promise<PublicKey[]>;
//# sourceMappingURL=vaa.d.ts.map