/** * 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 { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from "@solana/kit"; import { YVAULTS_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const SIGN_TERMS_DISCRIMINATOR = new Uint8Array([ 226, 42, 174, 143, 144, 159, 139, 1, ]); export function getSignTermsDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SIGN_TERMS_DISCRIMINATOR); } export type SignTermsInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountOwner extends string | AccountMeta = string, TAccountOwnerSignatureState extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TAccountRent extends string | AccountMeta = "SysvarRent111111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountOwner extends string ? WritableSignerAccount & AccountSignerMeta : TAccountOwner, TAccountOwnerSignatureState extends string ? WritableAccount : TAccountOwnerSignatureState, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountRent extends string ? ReadonlyAccount : TAccountRent, ...TRemainingAccounts, ] >; export type SignTermsInstructionData = { discriminator: ReadonlyUint8Array; signature: ReadonlyUint8Array; }; export type SignTermsInstructionDataArgs = { signature: ReadonlyUint8Array }; export function getSignTermsInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["signature", fixEncoderSize(getBytesEncoder(), 64)], ]), (value) => ({ ...value, discriminator: SIGN_TERMS_DISCRIMINATOR }), ); } export function getSignTermsInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["signature", fixDecoderSize(getBytesDecoder(), 64)], ]); } export function getSignTermsInstructionDataCodec(): FixedSizeCodec< SignTermsInstructionDataArgs, SignTermsInstructionData > { return combineCodec( getSignTermsInstructionDataEncoder(), getSignTermsInstructionDataDecoder(), ); } export type SignTermsInput< TAccountOwner extends string = string, TAccountOwnerSignatureState extends string = string, TAccountSystemProgram extends string = string, TAccountRent extends string = string, > = { owner: TransactionSigner; ownerSignatureState: Address; systemProgram?: Address; rent?: Address; signature: SignTermsInstructionDataArgs["signature"]; }; export function getSignTermsInstruction< TAccountOwner extends string, TAccountOwnerSignatureState extends string, TAccountSystemProgram extends string, TAccountRent extends string, TProgramAddress extends Address = typeof YVAULTS_PROGRAM_ADDRESS, >( input: SignTermsInput< TAccountOwner, TAccountOwnerSignatureState, TAccountSystemProgram, TAccountRent >, config?: { programAddress?: TProgramAddress }, ): SignTermsInstruction< TProgramAddress, TAccountOwner, TAccountOwnerSignatureState, TAccountSystemProgram, TAccountRent > { // Program address. const programAddress = config?.programAddress ?? YVAULTS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { owner: { value: input.owner ?? null, isWritable: true }, ownerSignatureState: { value: input.ownerSignatureState ?? null, isWritable: true, }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? 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.rent.value) { accounts.rent.value = "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.owner), getAccountMeta(accounts.ownerSignatureState), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.rent), ], data: getSignTermsInstructionDataEncoder().encode( args as SignTermsInstructionDataArgs, ), programAddress, } as SignTermsInstruction< TProgramAddress, TAccountOwner, TAccountOwnerSignatureState, TAccountSystemProgram, TAccountRent >); } export type ParsedSignTermsInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { owner: TAccountMetas[0]; ownerSignatureState: TAccountMetas[1]; systemProgram: TAccountMetas[2]; rent: TAccountMetas[3]; }; data: SignTermsInstructionData; }; export function parseSignTermsInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSignTermsInstruction { if (instruction.accounts.length < 4) { // 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: { owner: getNextAccount(), ownerSignatureState: getNextAccount(), systemProgram: getNextAccount(), rent: getNextAccount(), }, data: getSignTermsInstructionDataDecoder().decode(instruction.data), }; }