/** * 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, getAddressDecoder, getAddressEncoder, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, 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 INSERT_COLLATERAL_INFO_DISCRIMINATOR = new Uint8Array([ 22, 97, 4, 78, 166, 188, 51, 190, ]); export function getInsertCollateralInfoDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( INSERT_COLLATERAL_INFO_DISCRIMINATOR, ); } export type InsertCollateralInfoInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountAdminAuthority extends string | AccountMeta = string, TAccountGlobalConfig extends string | AccountMeta = string, TAccountTokenInfos extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdminAuthority extends string ? WritableSignerAccount & AccountSignerMeta : TAccountAdminAuthority, TAccountGlobalConfig extends string ? ReadonlyAccount : TAccountGlobalConfig, TAccountTokenInfos extends string ? WritableAccount : TAccountTokenInfos, ...TRemainingAccounts, ] >; export type InsertCollateralInfoInstructionData = { discriminator: ReadonlyUint8Array; index: bigint; mint: Address; lowerHeuristic: bigint; upperHeuristic: bigint; expHeuristic: bigint; maxTwapDivergenceBps: bigint; scopeTwapPriceChain: Array; scopePriceChain: Array; name: ReadonlyUint8Array; maxAgePriceSeconds: bigint; maxAgeTwapSeconds: bigint; maxIgnorableAmountAsReward: bigint; disabled: number; scopeStakingRateChain: Array; }; export type InsertCollateralInfoInstructionDataArgs = { index: number | bigint; mint: Address; lowerHeuristic: number | bigint; upperHeuristic: number | bigint; expHeuristic: number | bigint; maxTwapDivergenceBps: number | bigint; scopeTwapPriceChain: Array; scopePriceChain: Array; name: ReadonlyUint8Array; maxAgePriceSeconds: number | bigint; maxAgeTwapSeconds: number | bigint; maxIgnorableAmountAsReward: number | bigint; disabled: number; scopeStakingRateChain: Array; }; export function getInsertCollateralInfoInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["index", getU64Encoder()], ["mint", getAddressEncoder()], ["lowerHeuristic", getU64Encoder()], ["upperHeuristic", getU64Encoder()], ["expHeuristic", getU64Encoder()], ["maxTwapDivergenceBps", getU64Encoder()], ["scopeTwapPriceChain", getArrayEncoder(getU16Encoder(), { size: 4 })], ["scopePriceChain", getArrayEncoder(getU16Encoder(), { size: 4 })], ["name", fixEncoderSize(getBytesEncoder(), 32)], ["maxAgePriceSeconds", getU64Encoder()], ["maxAgeTwapSeconds", getU64Encoder()], ["maxIgnorableAmountAsReward", getU64Encoder()], ["disabled", getU8Encoder()], ["scopeStakingRateChain", getArrayEncoder(getU16Encoder(), { size: 4 })], ]), (value) => ({ ...value, discriminator: INSERT_COLLATERAL_INFO_DISCRIMINATOR, }), ); } export function getInsertCollateralInfoInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["index", getU64Decoder()], ["mint", getAddressDecoder()], ["lowerHeuristic", getU64Decoder()], ["upperHeuristic", getU64Decoder()], ["expHeuristic", getU64Decoder()], ["maxTwapDivergenceBps", getU64Decoder()], ["scopeTwapPriceChain", getArrayDecoder(getU16Decoder(), { size: 4 })], ["scopePriceChain", getArrayDecoder(getU16Decoder(), { size: 4 })], ["name", fixDecoderSize(getBytesDecoder(), 32)], ["maxAgePriceSeconds", getU64Decoder()], ["maxAgeTwapSeconds", getU64Decoder()], ["maxIgnorableAmountAsReward", getU64Decoder()], ["disabled", getU8Decoder()], ["scopeStakingRateChain", getArrayDecoder(getU16Decoder(), { size: 4 })], ]); } export function getInsertCollateralInfoInstructionDataCodec(): FixedSizeCodec< InsertCollateralInfoInstructionDataArgs, InsertCollateralInfoInstructionData > { return combineCodec( getInsertCollateralInfoInstructionDataEncoder(), getInsertCollateralInfoInstructionDataDecoder(), ); } export type InsertCollateralInfoInput< TAccountAdminAuthority extends string = string, TAccountGlobalConfig extends string = string, TAccountTokenInfos extends string = string, > = { adminAuthority: TransactionSigner; globalConfig: Address; tokenInfos: Address; index: InsertCollateralInfoInstructionDataArgs["index"]; mint: InsertCollateralInfoInstructionDataArgs["mint"]; lowerHeuristic: InsertCollateralInfoInstructionDataArgs["lowerHeuristic"]; upperHeuristic: InsertCollateralInfoInstructionDataArgs["upperHeuristic"]; expHeuristic: InsertCollateralInfoInstructionDataArgs["expHeuristic"]; maxTwapDivergenceBps: InsertCollateralInfoInstructionDataArgs["maxTwapDivergenceBps"]; scopeTwapPriceChain: InsertCollateralInfoInstructionDataArgs["scopeTwapPriceChain"]; scopePriceChain: InsertCollateralInfoInstructionDataArgs["scopePriceChain"]; name: InsertCollateralInfoInstructionDataArgs["name"]; maxAgePriceSeconds: InsertCollateralInfoInstructionDataArgs["maxAgePriceSeconds"]; maxAgeTwapSeconds: InsertCollateralInfoInstructionDataArgs["maxAgeTwapSeconds"]; maxIgnorableAmountAsReward: InsertCollateralInfoInstructionDataArgs["maxIgnorableAmountAsReward"]; disabled: InsertCollateralInfoInstructionDataArgs["disabled"]; scopeStakingRateChain: InsertCollateralInfoInstructionDataArgs["scopeStakingRateChain"]; }; export function getInsertCollateralInfoInstruction< TAccountAdminAuthority extends string, TAccountGlobalConfig extends string, TAccountTokenInfos extends string, TProgramAddress extends Address = typeof YVAULTS_PROGRAM_ADDRESS, >( input: InsertCollateralInfoInput< TAccountAdminAuthority, TAccountGlobalConfig, TAccountTokenInfos >, config?: { programAddress?: TProgramAddress }, ): InsertCollateralInfoInstruction< TProgramAddress, TAccountAdminAuthority, TAccountGlobalConfig, TAccountTokenInfos > { // Program address. const programAddress = config?.programAddress ?? YVAULTS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { adminAuthority: { value: input.adminAuthority ?? null, isWritable: true }, globalConfig: { value: input.globalConfig ?? null, isWritable: false }, tokenInfos: { value: input.tokenInfos ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.adminAuthority), getAccountMeta(accounts.globalConfig), getAccountMeta(accounts.tokenInfos), ], data: getInsertCollateralInfoInstructionDataEncoder().encode( args as InsertCollateralInfoInstructionDataArgs, ), programAddress, } as InsertCollateralInfoInstruction< TProgramAddress, TAccountAdminAuthority, TAccountGlobalConfig, TAccountTokenInfos >); } export type ParsedInsertCollateralInfoInstruction< TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { adminAuthority: TAccountMetas[0]; globalConfig: TAccountMetas[1]; tokenInfos: TAccountMetas[2]; }; data: InsertCollateralInfoInstructionData; }; export function parseInsertCollateralInfoInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedInsertCollateralInfoInstruction { if (instruction.accounts.length < 3) { // 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: { adminAuthority: getNextAccount(), globalConfig: getNextAccount(), tokenInfos: getNextAccount(), }, data: getInsertCollateralInfoInstructionDataDecoder().decode( instruction.data, ), }; }