/** * 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, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from "@solana/kit"; import { getAccountMetaFactory, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount, } from "@solana/program-client-core"; import { findAdaptorAddReceiptPda, findProtocolPda } from "../pdas"; import { VOLTR_VAULT_PROGRAM_ADDRESS } from "../programs"; export const ADD_ADAPTOR_DISCRIMINATOR = new Uint8Array([ 161, 145, 203, 248, 211, 202, 203, 67, ]); export function getAddAdaptorDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(ADD_ADAPTOR_DISCRIMINATOR); } export type AddAdaptorInstruction< TProgram extends string = typeof VOLTR_VAULT_PROGRAM_ADDRESS, TAccountPayer extends string | AccountMeta = string, TAccountAdmin extends string | AccountMeta = string, TAccountProtocol extends string | AccountMeta = string, TAccountVault extends string | AccountMeta = string, TAccountAdaptorAddReceipt extends string | AccountMeta = string, TAccountAdaptorProgram extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountPayer extends string ? WritableSignerAccount & AccountSignerMeta : TAccountPayer, TAccountAdmin extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountAdmin, TAccountProtocol extends string ? ReadonlyAccount : TAccountProtocol, TAccountVault extends string ? WritableAccount : TAccountVault, TAccountAdaptorAddReceipt extends string ? WritableAccount : TAccountAdaptorAddReceipt, TAccountAdaptorProgram extends string ? ReadonlyAccount : TAccountAdaptorProgram, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type AddAdaptorInstructionData = { discriminator: ReadonlyUint8Array }; export type AddAdaptorInstructionDataArgs = {}; export function getAddAdaptorInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: ADD_ADAPTOR_DISCRIMINATOR }), ); } export function getAddAdaptorInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getAddAdaptorInstructionDataCodec(): FixedSizeCodec< AddAdaptorInstructionDataArgs, AddAdaptorInstructionData > { return combineCodec( getAddAdaptorInstructionDataEncoder(), getAddAdaptorInstructionDataDecoder(), ); } export type AddAdaptorAsyncInput< TAccountPayer extends string = string, TAccountAdmin extends string = string, TAccountProtocol extends string = string, TAccountVault extends string = string, TAccountAdaptorAddReceipt extends string = string, TAccountAdaptorProgram extends string = string, TAccountSystemProgram extends string = string, > = { payer: TransactionSigner; admin: TransactionSigner; protocol?: Address; vault: Address; adaptorAddReceipt?: Address; adaptorProgram: Address; systemProgram?: Address; }; export async function getAddAdaptorInstructionAsync< TAccountPayer extends string, TAccountAdmin extends string, TAccountProtocol extends string, TAccountVault extends string, TAccountAdaptorAddReceipt extends string, TAccountAdaptorProgram extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof VOLTR_VAULT_PROGRAM_ADDRESS, >( input: AddAdaptorAsyncInput< TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountAdaptorAddReceipt, TAccountAdaptorProgram, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< AddAdaptorInstruction< TProgramAddress, TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountAdaptorAddReceipt, TAccountAdaptorProgram, TAccountSystemProgram > > { // Program address. const programAddress = config?.programAddress ?? VOLTR_VAULT_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { payer: { value: input.payer ?? null, isWritable: true }, admin: { value: input.admin ?? null, isWritable: false }, protocol: { value: input.protocol ?? null, isWritable: false }, vault: { value: input.vault ?? null, isWritable: true }, adaptorAddReceipt: { value: input.adaptorAddReceipt ?? null, isWritable: true, }, adaptorProgram: { value: input.adaptorProgram ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Resolve default values. if (!accounts.protocol.value) { accounts.protocol.value = await findProtocolPda(); } if (!accounts.adaptorAddReceipt.value) { accounts.adaptorAddReceipt.value = await findAdaptorAddReceiptPda({ vault: getAddressFromResolvedInstructionAccount( "vault", accounts.vault.value, ), adaptorProgram: getAddressFromResolvedInstructionAccount( "adaptorProgram", accounts.adaptorProgram.value, ), }); } if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("payer", accounts.payer), getAccountMeta("admin", accounts.admin), getAccountMeta("protocol", accounts.protocol), getAccountMeta("vault", accounts.vault), getAccountMeta("adaptorAddReceipt", accounts.adaptorAddReceipt), getAccountMeta("adaptorProgram", accounts.adaptorProgram), getAccountMeta("systemProgram", accounts.systemProgram), ], data: getAddAdaptorInstructionDataEncoder().encode({}), programAddress, } as AddAdaptorInstruction< TProgramAddress, TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountAdaptorAddReceipt, TAccountAdaptorProgram, TAccountSystemProgram >); } export type AddAdaptorInput< TAccountPayer extends string = string, TAccountAdmin extends string = string, TAccountProtocol extends string = string, TAccountVault extends string = string, TAccountAdaptorAddReceipt extends string = string, TAccountAdaptorProgram extends string = string, TAccountSystemProgram extends string = string, > = { payer: TransactionSigner; admin: TransactionSigner; protocol: Address; vault: Address; adaptorAddReceipt: Address; adaptorProgram: Address; systemProgram?: Address; }; export function getAddAdaptorInstruction< TAccountPayer extends string, TAccountAdmin extends string, TAccountProtocol extends string, TAccountVault extends string, TAccountAdaptorAddReceipt extends string, TAccountAdaptorProgram extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof VOLTR_VAULT_PROGRAM_ADDRESS, >( input: AddAdaptorInput< TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountAdaptorAddReceipt, TAccountAdaptorProgram, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): AddAdaptorInstruction< TProgramAddress, TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountAdaptorAddReceipt, TAccountAdaptorProgram, TAccountSystemProgram > { // Program address. const programAddress = config?.programAddress ?? VOLTR_VAULT_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { payer: { value: input.payer ?? null, isWritable: true }, admin: { value: input.admin ?? null, isWritable: false }, protocol: { value: input.protocol ?? null, isWritable: false }, vault: { value: input.vault ?? null, isWritable: true }, adaptorAddReceipt: { value: input.adaptorAddReceipt ?? null, isWritable: true, }, adaptorProgram: { value: input.adaptorProgram ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("payer", accounts.payer), getAccountMeta("admin", accounts.admin), getAccountMeta("protocol", accounts.protocol), getAccountMeta("vault", accounts.vault), getAccountMeta("adaptorAddReceipt", accounts.adaptorAddReceipt), getAccountMeta("adaptorProgram", accounts.adaptorProgram), getAccountMeta("systemProgram", accounts.systemProgram), ], data: getAddAdaptorInstructionDataEncoder().encode({}), programAddress, } as AddAdaptorInstruction< TProgramAddress, TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountAdaptorAddReceipt, TAccountAdaptorProgram, TAccountSystemProgram >); } export type ParsedAddAdaptorInstruction< TProgram extends string = typeof VOLTR_VAULT_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { payer: TAccountMetas[0]; admin: TAccountMetas[1]; protocol: TAccountMetas[2]; vault: TAccountMetas[3]; adaptorAddReceipt: TAccountMetas[4]; adaptorProgram: TAccountMetas[5]; systemProgram: TAccountMetas[6]; }; data: AddAdaptorInstructionData; }; export function parseAddAdaptorInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedAddAdaptorInstruction { if (instruction.accounts.length < 7) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 7, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { payer: getNextAccount(), admin: getNextAccount(), protocol: getNextAccount(), vault: getNextAccount(), adaptorAddReceipt: getNextAccount(), adaptorProgram: getNextAccount(), systemProgram: getNextAccount(), }, data: getAddAdaptorInstructionDataDecoder().decode(instruction.data), }; }