/** * 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, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getOptionDecoder, getOptionEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type Option, type OptionOrNullable, 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, findDirectWithdrawInitReceiptPda, findProtocolPda, findStrategyInitReceiptPda, } from "../pdas"; import { VOLTR_VAULT_PROGRAM_ADDRESS } from "../programs"; export const INITIALIZE_DIRECT_WITHDRAW_STRATEGY_DISCRIMINATOR = new Uint8Array( [248, 207, 228, 15, 13, 191, 43, 58], ); export function getInitializeDirectWithdrawStrategyDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( INITIALIZE_DIRECT_WITHDRAW_STRATEGY_DISCRIMINATOR, ); } export type InitializeDirectWithdrawStrategyInstruction< 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, TAccountStrategy extends string | AccountMeta = string, TAccountStrategyInitReceipt extends string | AccountMeta = string, TAccountAdaptorAddReceipt extends string | AccountMeta = string, TAccountDirectWithdrawInitReceipt 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, TAccountStrategy extends string ? ReadonlyAccount : TAccountStrategy, TAccountStrategyInitReceipt extends string ? WritableAccount : TAccountStrategyInitReceipt, TAccountAdaptorAddReceipt extends string ? ReadonlyAccount : TAccountAdaptorAddReceipt, TAccountDirectWithdrawInitReceipt extends string ? WritableAccount : TAccountDirectWithdrawInitReceipt, TAccountAdaptorProgram extends string ? ReadonlyAccount : TAccountAdaptorProgram, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type InitializeDirectWithdrawStrategyInstructionData = { discriminator: ReadonlyUint8Array; instructionDiscriminator: Option; additionalArgs: Option; allowUserArgs: boolean; }; export type InitializeDirectWithdrawStrategyInstructionDataArgs = { instructionDiscriminator: OptionOrNullable; additionalArgs: OptionOrNullable; allowUserArgs: boolean; }; export function getInitializeDirectWithdrawStrategyInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], [ "instructionDiscriminator", getOptionEncoder( addEncoderSizePrefix(getBytesEncoder(), getU32Encoder()), ), ], [ "additionalArgs", getOptionEncoder( addEncoderSizePrefix(getBytesEncoder(), getU32Encoder()), ), ], ["allowUserArgs", getBooleanEncoder()], ]), (value) => ({ ...value, discriminator: INITIALIZE_DIRECT_WITHDRAW_STRATEGY_DISCRIMINATOR, }), ); } export function getInitializeDirectWithdrawStrategyInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], [ "instructionDiscriminator", getOptionDecoder( addDecoderSizePrefix(getBytesDecoder(), getU32Decoder()), ), ], [ "additionalArgs", getOptionDecoder( addDecoderSizePrefix(getBytesDecoder(), getU32Decoder()), ), ], ["allowUserArgs", getBooleanDecoder()], ]); } export function getInitializeDirectWithdrawStrategyInstructionDataCodec(): Codec< InitializeDirectWithdrawStrategyInstructionDataArgs, InitializeDirectWithdrawStrategyInstructionData > { return combineCodec( getInitializeDirectWithdrawStrategyInstructionDataEncoder(), getInitializeDirectWithdrawStrategyInstructionDataDecoder(), ); } export type InitializeDirectWithdrawStrategyAsyncInput< TAccountPayer extends string = string, TAccountAdmin extends string = string, TAccountProtocol extends string = string, TAccountVault extends string = string, TAccountStrategy extends string = string, TAccountStrategyInitReceipt extends string = string, TAccountAdaptorAddReceipt extends string = string, TAccountDirectWithdrawInitReceipt extends string = string, TAccountAdaptorProgram extends string = string, TAccountSystemProgram extends string = string, > = { payer: TransactionSigner; admin: TransactionSigner; protocol?: Address; vault: Address; strategy: Address; strategyInitReceipt?: Address; adaptorAddReceipt?: Address; directWithdrawInitReceipt?: Address; adaptorProgram: Address; systemProgram?: Address; instructionDiscriminator: InitializeDirectWithdrawStrategyInstructionDataArgs["instructionDiscriminator"]; additionalArgs: InitializeDirectWithdrawStrategyInstructionDataArgs["additionalArgs"]; allowUserArgs: InitializeDirectWithdrawStrategyInstructionDataArgs["allowUserArgs"]; }; export async function getInitializeDirectWithdrawStrategyInstructionAsync< TAccountPayer extends string, TAccountAdmin extends string, TAccountProtocol extends string, TAccountVault extends string, TAccountStrategy extends string, TAccountStrategyInitReceipt extends string, TAccountAdaptorAddReceipt extends string, TAccountDirectWithdrawInitReceipt extends string, TAccountAdaptorProgram extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof VOLTR_VAULT_PROGRAM_ADDRESS, >( input: InitializeDirectWithdrawStrategyAsyncInput< TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountStrategy, TAccountStrategyInitReceipt, TAccountAdaptorAddReceipt, TAccountDirectWithdrawInitReceipt, TAccountAdaptorProgram, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< InitializeDirectWithdrawStrategyInstruction< TProgramAddress, TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountStrategy, TAccountStrategyInitReceipt, TAccountAdaptorAddReceipt, TAccountDirectWithdrawInitReceipt, 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 }, strategy: { value: input.strategy ?? null, isWritable: false }, strategyInitReceipt: { value: input.strategyInitReceipt ?? null, isWritable: true, }, adaptorAddReceipt: { value: input.adaptorAddReceipt ?? null, isWritable: false, }, directWithdrawInitReceipt: { value: input.directWithdrawInitReceipt ?? 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 >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.protocol.value) { accounts.protocol.value = await findProtocolPda(); } if (!accounts.strategyInitReceipt.value) { accounts.strategyInitReceipt.value = await findStrategyInitReceiptPda({ vault: getAddressFromResolvedInstructionAccount( "vault", accounts.vault.value, ), strategy: getAddressFromResolvedInstructionAccount( "strategy", accounts.strategy.value, ), }); } if (!accounts.adaptorAddReceipt.value) { accounts.adaptorAddReceipt.value = await findAdaptorAddReceiptPda({ vault: getAddressFromResolvedInstructionAccount( "vault", accounts.vault.value, ), adaptorProgram: getAddressFromResolvedInstructionAccount( "adaptorProgram", accounts.adaptorProgram.value, ), }); } if (!accounts.directWithdrawInitReceipt.value) { accounts.directWithdrawInitReceipt.value = await findDirectWithdrawInitReceiptPda({ vault: getAddressFromResolvedInstructionAccount( "vault", accounts.vault.value, ), strategy: getAddressFromResolvedInstructionAccount( "strategy", accounts.strategy.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("strategy", accounts.strategy), getAccountMeta("strategyInitReceipt", accounts.strategyInitReceipt), getAccountMeta("adaptorAddReceipt", accounts.adaptorAddReceipt), getAccountMeta( "directWithdrawInitReceipt", accounts.directWithdrawInitReceipt, ), getAccountMeta("adaptorProgram", accounts.adaptorProgram), getAccountMeta("systemProgram", accounts.systemProgram), ], data: getInitializeDirectWithdrawStrategyInstructionDataEncoder().encode( args as InitializeDirectWithdrawStrategyInstructionDataArgs, ), programAddress, } as InitializeDirectWithdrawStrategyInstruction< TProgramAddress, TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountStrategy, TAccountStrategyInitReceipt, TAccountAdaptorAddReceipt, TAccountDirectWithdrawInitReceipt, TAccountAdaptorProgram, TAccountSystemProgram >); } export type InitializeDirectWithdrawStrategyInput< TAccountPayer extends string = string, TAccountAdmin extends string = string, TAccountProtocol extends string = string, TAccountVault extends string = string, TAccountStrategy extends string = string, TAccountStrategyInitReceipt extends string = string, TAccountAdaptorAddReceipt extends string = string, TAccountDirectWithdrawInitReceipt extends string = string, TAccountAdaptorProgram extends string = string, TAccountSystemProgram extends string = string, > = { payer: TransactionSigner; admin: TransactionSigner; protocol: Address; vault: Address; strategy: Address; strategyInitReceipt: Address; adaptorAddReceipt: Address; directWithdrawInitReceipt: Address; adaptorProgram: Address; systemProgram?: Address; instructionDiscriminator: InitializeDirectWithdrawStrategyInstructionDataArgs["instructionDiscriminator"]; additionalArgs: InitializeDirectWithdrawStrategyInstructionDataArgs["additionalArgs"]; allowUserArgs: InitializeDirectWithdrawStrategyInstructionDataArgs["allowUserArgs"]; }; export function getInitializeDirectWithdrawStrategyInstruction< TAccountPayer extends string, TAccountAdmin extends string, TAccountProtocol extends string, TAccountVault extends string, TAccountStrategy extends string, TAccountStrategyInitReceipt extends string, TAccountAdaptorAddReceipt extends string, TAccountDirectWithdrawInitReceipt extends string, TAccountAdaptorProgram extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof VOLTR_VAULT_PROGRAM_ADDRESS, >( input: InitializeDirectWithdrawStrategyInput< TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountStrategy, TAccountStrategyInitReceipt, TAccountAdaptorAddReceipt, TAccountDirectWithdrawInitReceipt, TAccountAdaptorProgram, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): InitializeDirectWithdrawStrategyInstruction< TProgramAddress, TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountStrategy, TAccountStrategyInitReceipt, TAccountAdaptorAddReceipt, TAccountDirectWithdrawInitReceipt, 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 }, strategy: { value: input.strategy ?? null, isWritable: false }, strategyInitReceipt: { value: input.strategyInitReceipt ?? null, isWritable: true, }, adaptorAddReceipt: { value: input.adaptorAddReceipt ?? null, isWritable: false, }, directWithdrawInitReceipt: { value: input.directWithdrawInitReceipt ?? 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 >; // Original args. const args = { ...input }; // 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("strategy", accounts.strategy), getAccountMeta("strategyInitReceipt", accounts.strategyInitReceipt), getAccountMeta("adaptorAddReceipt", accounts.adaptorAddReceipt), getAccountMeta( "directWithdrawInitReceipt", accounts.directWithdrawInitReceipt, ), getAccountMeta("adaptorProgram", accounts.adaptorProgram), getAccountMeta("systemProgram", accounts.systemProgram), ], data: getInitializeDirectWithdrawStrategyInstructionDataEncoder().encode( args as InitializeDirectWithdrawStrategyInstructionDataArgs, ), programAddress, } as InitializeDirectWithdrawStrategyInstruction< TProgramAddress, TAccountPayer, TAccountAdmin, TAccountProtocol, TAccountVault, TAccountStrategy, TAccountStrategyInitReceipt, TAccountAdaptorAddReceipt, TAccountDirectWithdrawInitReceipt, TAccountAdaptorProgram, TAccountSystemProgram >); } export type ParsedInitializeDirectWithdrawStrategyInstruction< 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]; strategy: TAccountMetas[4]; strategyInitReceipt: TAccountMetas[5]; adaptorAddReceipt: TAccountMetas[6]; directWithdrawInitReceipt: TAccountMetas[7]; adaptorProgram: TAccountMetas[8]; systemProgram: TAccountMetas[9]; }; data: InitializeDirectWithdrawStrategyInstructionData; }; export function parseInitializeDirectWithdrawStrategyInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedInitializeDirectWithdrawStrategyInstruction { if (instruction.accounts.length < 10) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 10, }, ); } 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(), strategy: getNextAccount(), strategyInitReceipt: getNextAccount(), adaptorAddReceipt: getNextAccount(), directWithdrawInitReceipt: getNextAccount(), adaptorProgram: getNextAccount(), systemProgram: getNextAccount(), }, data: getInitializeDirectWithdrawStrategyInstructionDataDecoder().decode( instruction.data, ), }; }