/** * This code was AUTOGENERATED using the Codama library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun Codama to update it. * * @see https://github.com/codama-idl/codama */ import { addDecoderSizePrefix, addEncoderSizePrefix, combineCodec, fixDecoderSize, fixEncoderSize, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from "@solana/kit"; import { SCOPE_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const REFRESH_PYTH_LAZER_PRICE_DISCRIMINATOR = new Uint8Array([ 122, 47, 177, 133, 177, 35, 93, 118, ]); export function getRefreshPythLazerPriceDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( REFRESH_PYTH_LAZER_PRICE_DISCRIMINATOR, ); } export type RefreshPythLazerPriceInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountUser extends string | AccountMeta = string, TAccountOraclePrices extends string | AccountMeta = string, TAccountOracleMappings extends string | AccountMeta = string, TAccountOracleTwaps extends string | AccountMeta = string, TAccountPythProgram extends string | AccountMeta = string, TAccountPythStorage extends string | AccountMeta = string, TAccountPythTreasury extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TAccountInstructionsSysvar extends string | AccountMeta = "Sysvar1nstructions1111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountUser extends string ? WritableSignerAccount & AccountSignerMeta : TAccountUser, TAccountOraclePrices extends string ? WritableAccount : TAccountOraclePrices, TAccountOracleMappings extends string ? ReadonlyAccount : TAccountOracleMappings, TAccountOracleTwaps extends string ? WritableAccount : TAccountOracleTwaps, TAccountPythProgram extends string ? ReadonlyAccount : TAccountPythProgram, TAccountPythStorage extends string ? ReadonlyAccount : TAccountPythStorage, TAccountPythTreasury extends string ? WritableAccount : TAccountPythTreasury, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountInstructionsSysvar extends string ? ReadonlyAccount : TAccountInstructionsSysvar, ...TRemainingAccounts, ] >; export type RefreshPythLazerPriceInstructionData = { discriminator: ReadonlyUint8Array; tokens: Array; serializedPythMessage: ReadonlyUint8Array; ed25519InstructionIndex: number; }; export type RefreshPythLazerPriceInstructionDataArgs = { tokens: Array; serializedPythMessage: ReadonlyUint8Array; ed25519InstructionIndex: number; }; export function getRefreshPythLazerPriceInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["tokens", getArrayEncoder(getU16Encoder())], [ "serializedPythMessage", addEncoderSizePrefix(getBytesEncoder(), getU32Encoder()), ], ["ed25519InstructionIndex", getU16Encoder()], ]), (value) => ({ ...value, discriminator: REFRESH_PYTH_LAZER_PRICE_DISCRIMINATOR, }), ); } export function getRefreshPythLazerPriceInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["tokens", getArrayDecoder(getU16Decoder())], [ "serializedPythMessage", addDecoderSizePrefix(getBytesDecoder(), getU32Decoder()), ], ["ed25519InstructionIndex", getU16Decoder()], ]); } export function getRefreshPythLazerPriceInstructionDataCodec(): Codec< RefreshPythLazerPriceInstructionDataArgs, RefreshPythLazerPriceInstructionData > { return combineCodec( getRefreshPythLazerPriceInstructionDataEncoder(), getRefreshPythLazerPriceInstructionDataDecoder(), ); } export type RefreshPythLazerPriceInput< TAccountUser extends string = string, TAccountOraclePrices extends string = string, TAccountOracleMappings extends string = string, TAccountOracleTwaps extends string = string, TAccountPythProgram extends string = string, TAccountPythStorage extends string = string, TAccountPythTreasury extends string = string, TAccountSystemProgram extends string = string, TAccountInstructionsSysvar extends string = string, > = { /** The account that signs the transaction. */ user: TransactionSigner; oraclePrices: Address; oracleMappings: Address; oracleTwaps: Address; pythProgram: Address; pythStorage: Address; pythTreasury: Address; systemProgram?: Address; instructionsSysvar?: Address; tokens: RefreshPythLazerPriceInstructionDataArgs["tokens"]; serializedPythMessage: RefreshPythLazerPriceInstructionDataArgs["serializedPythMessage"]; ed25519InstructionIndex: RefreshPythLazerPriceInstructionDataArgs["ed25519InstructionIndex"]; }; export function getRefreshPythLazerPriceInstruction< TAccountUser extends string, TAccountOraclePrices extends string, TAccountOracleMappings extends string, TAccountOracleTwaps extends string, TAccountPythProgram extends string, TAccountPythStorage extends string, TAccountPythTreasury extends string, TAccountSystemProgram extends string, TAccountInstructionsSysvar extends string, TProgramAddress extends Address = typeof SCOPE_PROGRAM_ADDRESS, >( input: RefreshPythLazerPriceInput< TAccountUser, TAccountOraclePrices, TAccountOracleMappings, TAccountOracleTwaps, TAccountPythProgram, TAccountPythStorage, TAccountPythTreasury, TAccountSystemProgram, TAccountInstructionsSysvar >, config?: { programAddress?: TProgramAddress }, ): RefreshPythLazerPriceInstruction< TProgramAddress, TAccountUser, TAccountOraclePrices, TAccountOracleMappings, TAccountOracleTwaps, TAccountPythProgram, TAccountPythStorage, TAccountPythTreasury, TAccountSystemProgram, TAccountInstructionsSysvar > { // Program address. const programAddress = config?.programAddress ?? SCOPE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { user: { value: input.user ?? null, isWritable: true }, oraclePrices: { value: input.oraclePrices ?? null, isWritable: true }, oracleMappings: { value: input.oracleMappings ?? null, isWritable: false }, oracleTwaps: { value: input.oracleTwaps ?? null, isWritable: true }, pythProgram: { value: input.pythProgram ?? null, isWritable: false }, pythStorage: { value: input.pythStorage ?? null, isWritable: false }, pythTreasury: { value: input.pythTreasury ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, instructionsSysvar: { value: input.instructionsSysvar ?? null, isWritable: false, }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } if (!accounts.instructionsSysvar.value) { accounts.instructionsSysvar.value = "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.user), getAccountMeta(accounts.oraclePrices), getAccountMeta(accounts.oracleMappings), getAccountMeta(accounts.oracleTwaps), getAccountMeta(accounts.pythProgram), getAccountMeta(accounts.pythStorage), getAccountMeta(accounts.pythTreasury), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.instructionsSysvar), ], data: getRefreshPythLazerPriceInstructionDataEncoder().encode( args as RefreshPythLazerPriceInstructionDataArgs, ), programAddress, } as RefreshPythLazerPriceInstruction< TProgramAddress, TAccountUser, TAccountOraclePrices, TAccountOracleMappings, TAccountOracleTwaps, TAccountPythProgram, TAccountPythStorage, TAccountPythTreasury, TAccountSystemProgram, TAccountInstructionsSysvar >); } export type ParsedRefreshPythLazerPriceInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The account that signs the transaction. */ user: TAccountMetas[0]; oraclePrices: TAccountMetas[1]; oracleMappings: TAccountMetas[2]; oracleTwaps: TAccountMetas[3]; pythProgram: TAccountMetas[4]; pythStorage: TAccountMetas[5]; pythTreasury: TAccountMetas[6]; systemProgram: TAccountMetas[7]; instructionsSysvar: TAccountMetas[8]; }; data: RefreshPythLazerPriceInstructionData; }; export function parseRefreshPythLazerPriceInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedRefreshPythLazerPriceInstruction { if (instruction.accounts.length < 9) { // TODO: Coded error. throw new Error("Not enough accounts"); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { user: getNextAccount(), oraclePrices: getNextAccount(), oracleMappings: getNextAccount(), oracleTwaps: getNextAccount(), pythProgram: getNextAccount(), pythStorage: getNextAccount(), pythTreasury: getNextAccount(), systemProgram: getNextAccount(), instructionsSysvar: getNextAccount(), }, data: getRefreshPythLazerPriceInstructionDataDecoder().decode( instruction.data, ), }; }