/** * 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, getU64Decoder, getU64Encoder, 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 { PERPETUALS_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; import { getOracleParamsDecoder, getOracleParamsEncoder, getPermissionsDecoder, getPermissionsEncoder, getPricingParamsDecoder, getPricingParamsEncoder, type OracleParams, type OracleParamsArgs, type Permissions, type PermissionsArgs, type PricingParams, type PricingParamsArgs, } from "../types"; export const SET_CUSTODY_CONFIG_DISCRIMINATOR = new Uint8Array([ 133, 97, 130, 143, 215, 229, 36, 176, ]); export function getSetCustodyConfigDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SET_CUSTODY_CONFIG_DISCRIMINATOR, ); } export type SetCustodyConfigInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountAdmin extends string | AccountMeta = string, TAccountPerpetuals extends string | AccountMeta = string, TAccountCustody extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountAdmin extends string ? WritableSignerAccount & AccountSignerMeta : TAccountAdmin, TAccountPerpetuals extends string ? ReadonlyAccount : TAccountPerpetuals, TAccountCustody extends string ? WritableAccount : TAccountCustody, ...TRemainingAccounts, ] >; export type SetCustodyConfigInstructionData = { discriminator: ReadonlyUint8Array; oracle: OracleParams; pricing: PricingParams; permissions: Permissions; hourlyFundingBps: bigint; targetRatioBps: bigint; }; export type SetCustodyConfigInstructionDataArgs = { oracle: OracleParamsArgs; pricing: PricingParamsArgs; permissions: PermissionsArgs; hourlyFundingBps: number | bigint; targetRatioBps: number | bigint; }; export function getSetCustodyConfigInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["oracle", getOracleParamsEncoder()], ["pricing", getPricingParamsEncoder()], ["permissions", getPermissionsEncoder()], ["hourlyFundingBps", getU64Encoder()], ["targetRatioBps", getU64Encoder()], ]), (value) => ({ ...value, discriminator: SET_CUSTODY_CONFIG_DISCRIMINATOR }), ); } export function getSetCustodyConfigInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["oracle", getOracleParamsDecoder()], ["pricing", getPricingParamsDecoder()], ["permissions", getPermissionsDecoder()], ["hourlyFundingBps", getU64Decoder()], ["targetRatioBps", getU64Decoder()], ]); } export function getSetCustodyConfigInstructionDataCodec(): FixedSizeCodec< SetCustodyConfigInstructionDataArgs, SetCustodyConfigInstructionData > { return combineCodec( getSetCustodyConfigInstructionDataEncoder(), getSetCustodyConfigInstructionDataDecoder(), ); } export type SetCustodyConfigInput< TAccountAdmin extends string = string, TAccountPerpetuals extends string = string, TAccountCustody extends string = string, > = { admin: TransactionSigner; perpetuals: Address; custody: Address; oracle: SetCustodyConfigInstructionDataArgs["oracle"]; pricing: SetCustodyConfigInstructionDataArgs["pricing"]; permissions: SetCustodyConfigInstructionDataArgs["permissions"]; hourlyFundingBps: SetCustodyConfigInstructionDataArgs["hourlyFundingBps"]; targetRatioBps: SetCustodyConfigInstructionDataArgs["targetRatioBps"]; }; export function getSetCustodyConfigInstruction< TAccountAdmin extends string, TAccountPerpetuals extends string, TAccountCustody extends string, TProgramAddress extends Address = typeof PERPETUALS_PROGRAM_ADDRESS, >( input: SetCustodyConfigInput< TAccountAdmin, TAccountPerpetuals, TAccountCustody >, config?: { programAddress?: TProgramAddress }, ): SetCustodyConfigInstruction< TProgramAddress, TAccountAdmin, TAccountPerpetuals, TAccountCustody > { // Program address. const programAddress = config?.programAddress ?? PERPETUALS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: true }, perpetuals: { value: input.perpetuals ?? null, isWritable: false }, custody: { value: input.custody ?? 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.admin), getAccountMeta(accounts.perpetuals), getAccountMeta(accounts.custody), ], data: getSetCustodyConfigInstructionDataEncoder().encode( args as SetCustodyConfigInstructionDataArgs, ), programAddress, } as SetCustodyConfigInstruction< TProgramAddress, TAccountAdmin, TAccountPerpetuals, TAccountCustody >); } export type ParsedSetCustodyConfigInstruction< TProgram extends string = typeof PERPETUALS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { admin: TAccountMetas[0]; perpetuals: TAccountMetas[1]; custody: TAccountMetas[2]; }; data: SetCustodyConfigInstructionData; }; export function parseSetCustodyConfigInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSetCustodyConfigInstruction { 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: { admin: getNextAccount(), perpetuals: getNextAccount(), custody: getNextAccount(), }, data: getSetCustodyConfigInstructionDataDecoder().decode(instruction.data), }; }