import { PublicKey } from '@metaplex-foundation/umi' import { GetDataEnumKind, GetDataEnumKindContent, Serializer, array, bool, bytes, dataEnum, publicKey as publicKeySerializer, struct, tuple, u16, u32, u64, u8, unit, } from '@metaplex-foundation/umi/serializers' export interface SolanaPacketPath { sender: PublicKey dstEid: number receiver: Uint8Array // length 32 } /** * Offset for message type. */ export const MSG_TYPE_OFFSET = 0 /** * Enum representing different message types. */ export enum MessageType { /** * Vanilla message type. */ VANILLA = 1, /** * Composed message type. */ COMPOSED_TYPE = 2, /** * ABA message type. */ ABA = 3, } /** * Interface representing the parameters for LzReceive. */ export interface LzReceiveParams { /** * Source EID. */ srcEid: number /** * Sender address (size: 32). */ sender: Uint8Array nonce: bigint /** * GUID (size: 32). */ guid: Uint8Array /** * Message content. */ message: Uint8Array /** * Caller parameters. */ callerParams: Uint8Array } export interface LzReceiveParamsArgs { srcEid: number sender: Uint8Array nonce: number | bigint guid: Uint8Array message: Uint8Array callerParams: Uint8Array } export function getLzReceiveParamsSerializer(): Serializer { return struct( [ ['srcEid', u32()], ['sender', bytes({ size: 32 })], ['nonce', u64()], ['guid', bytes({ size: 32 })], ['message', bytes({ size: u32() })], ['callerParams', bytes({ size: u32() })], ], { description: 'LzReceiveParams' } ) as Serializer } /** * pub from: Pubkey, pub to: Pubkey, pub guid: [u8; 32], pub index: u16, pub message: Vec, pub extra_data: Vec, **/ /** * Interface representing the parameters for LzCompose. */ export interface LzComposeParams { /** * Sender public key. */ from: PublicKey /** * Recipient public key. */ to: PublicKey /** * GUID (size: 32). */ guid: Uint8Array /** * Index value. */ index: number /** * Message content. */ message: Uint8Array /** * Extra data. */ extraData: Uint8Array } export function getLzComposeParamsSerializer(): Serializer { return struct( [ ['from', publicKeySerializer()], ['to', publicKeySerializer()], ['guid', bytes({ size: 32 })], ['index', u16()], ['message', bytes({ size: u32() })], ['extraData', bytes({ size: u32() })], ], { description: 'LzComposeParams' } ) } /** * Interface representing an LzReceive account. */ export interface LzReceiveAccount { /** * Public key of the account. */ pubkey: PublicKey /** * Indicates if the account is a signer. */ isSigner: boolean /** * Indicates if the account is writable. */ isWritable: boolean } export function getLzReceiveAccountSerializer(): Serializer { return struct( [ ['pubkey', publicKeySerializer()], ['isSigner', bool()], ['isWritable', bool()], ], { description: 'LzReceiveAccount' } ) } /** * Enum representing different executor option types. */ export enum ExecutorOptionType { /** * Placeholder option type. */ PlaceHolder = 0, /** * LzReceive option type. */ LzReceive = 1, /** * NativeDrop option type. */ NativeDrop = 2, /** * LzCompose option type. */ LzCompose = 3, /** * OrderExecution option type. */ OrderExecution = 4, } /** * Maximum length for executor option types. */ export const MaxExecutorOptionTypeLength = 10 export interface LzReceiveTypesV2Accounts { accounts: PublicKey[] } export interface LzComposeTypesV2Accounts { accounts: PublicKey[] } export type AddressLocator = | { __kind: 'Address'; fields: [PublicKey] } | { __kind: 'AltIndex'; fields: [number, number] } | { __kind: 'Payer' } | { __kind: 'Signer'; fields: [number] } | { __kind: 'Context' } export interface AccountMetaRef { pubkey: AddressLocator isWritable: boolean } export type InstructionForLzReceive = | { __kind: 'LzReceive'; accounts: AccountMetaRef[] } | { __kind: 'Standard'; programId: PublicKey; accounts: AccountMetaRef[]; data: Uint8Array } export type InstructionForLzCompose = | { __kind: 'LzCompose'; accounts: AccountMetaRef[] } | { __kind: 'Standard'; programId: PublicKey; accounts: AccountMetaRef[]; data: Uint8Array } export interface LzReceiveTypesV2Result { contextVersion: number alts: PublicKey[] instructions: InstructionForLzReceive[] } export interface LzComposeTypesV2Result { contextVersion: number alts: PublicKey[] instructions: InstructionForLzCompose[] } export function getAddressLocatorSerializer(): Serializer { return dataEnum( [ [ 'Address', struct>([['fields', tuple([publicKeySerializer()])]]), ], ['AltIndex', struct>([['fields', tuple([u8(), u8()])]])], ['Payer', unit()], ['Signer', struct>([['fields', tuple([u8()])]])], ['Context', unit()], ], { description: 'AddressLocator' } ) } export function getLzReceiveTypesV2AccountsSerializer(): Serializer< LzReceiveTypesV2Accounts, LzReceiveTypesV2Accounts > { return struct([['accounts', array(publicKeySerializer())]], { description: 'LzReceiveTypesV2Result', }) } export function getLzComposeTypesV2AccountsSerializer(): Serializer< LzComposeTypesV2Accounts, LzComposeTypesV2Accounts > { return struct([['accounts', array(publicKeySerializer())]], { description: 'LzComposeTypesV2Accounts', }) } export function getAccountMetaRefSerializer(): Serializer { return struct( [ ['pubkey', getAddressLocatorSerializer()], ['isWritable', bool()], ], { description: 'AccountMetaRef' } ) } export function getInstructionForLzReceiveSerializer(): Serializer { return dataEnum( [ [ 'LzReceive', struct>([ ['accounts', array(getAccountMetaRefSerializer())], ]), ], [ 'Standard', struct>([ ['programId', publicKeySerializer()], ['accounts', array(getAccountMetaRefSerializer())], ['data', bytes({ size: u32() })], ]), ], ], { description: 'Instruction' } ) } export function getInstructionForLzComposeSerializer(): Serializer { return dataEnum( [ [ 'LzCompose', struct>([ ['accounts', array(getAccountMetaRefSerializer())], ]), ], [ 'Standard', struct>([ ['programId', publicKeySerializer()], ['accounts', array(getAccountMetaRefSerializer())], ['data', bytes({ size: u32() })], ]), ], ], { description: 'Instruction' } ) } export function getLzReceiveTypesV2ResultSerializer(): Serializer { return struct( [ ['contextVersion', u8()], ['alts', array(publicKeySerializer())], ['instructions', array(getInstructionForLzReceiveSerializer())], ], { description: 'LzReceiveTypesV2Result' } ) } export function getLzComposeTypesV2ResultSerializer(): Serializer { return struct( [ ['contextVersion', u8()], ['alts', array(publicKeySerializer())], ['instructions', array(getInstructionForLzComposeSerializer())], ], { description: 'LzComposeTypesV2Result' } ) } // Data Enum Helpers. export function addressLocator(kind: 'Payer'): GetDataEnumKind export function addressLocator( kind: 'Signer', data: GetDataEnumKindContent['fields'] ): GetDataEnumKind export function addressLocator( kind: 'Address', data: GetDataEnumKindContent['fields'] ): GetDataEnumKind export function addressLocator( kind: 'AltIndex', data: GetDataEnumKindContent['fields'] ): GetDataEnumKind export function addressLocator( kind: K, // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types data?: any ): Extract { // eslint-disable-next-line @typescript-eslint/no-unsafe-return return Array.isArray(data) ? { __kind: kind, fields: data } : { __kind: kind, ...(data ?? {}) } } export function isAddressLocator( kind: K, value: AddressLocator ): value is AddressLocator & { __kind: K } { return value.__kind === kind }