UNPKG

@kamino-finance/kliquidity-sdk

Version:

Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol

82 lines (62 loc) 6.19 kB
/** * 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 { YVAULTS_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export const DEPRECATE_COLLATERAL_INFO_DISCRIMINATOR = new Uint8Array([143, 221, 36, 89, 12, 97, 29, 173]); export function getDeprecateCollateralInfoDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(DEPRECATE_COLLATERAL_INFO_DISCRIMINATOR); } export type DeprecateCollateralInfoInstruction<TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountAdminAuthority extends string | AccountMeta<string> = string, TAccountGlobalConfig extends string | AccountMeta<string> = string, TAccountTokenInfos extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountAdminAuthority extends string ? WritableSignerAccount<TAccountAdminAuthority> & AccountSignerMeta<TAccountAdminAuthority> : TAccountAdminAuthority, TAccountGlobalConfig extends string ? ReadonlyAccount<TAccountGlobalConfig> : TAccountGlobalConfig, TAccountTokenInfos extends string ? WritableAccount<TAccountTokenInfos> : TAccountTokenInfos, ...TRemainingAccounts]>; export type DeprecateCollateralInfoInstructionData = { discriminator: ReadonlyUint8Array; index: bigint; }; export type DeprecateCollateralInfoInstructionDataArgs = { index: number | bigint; }; export function getDeprecateCollateralInfoInstructionDataEncoder(): FixedSizeEncoder<DeprecateCollateralInfoInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['index', getU64Encoder()]]), (value) => ({ ...value, discriminator: DEPRECATE_COLLATERAL_INFO_DISCRIMINATOR })); } export function getDeprecateCollateralInfoInstructionDataDecoder(): FixedSizeDecoder<DeprecateCollateralInfoInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['index', getU64Decoder()]]); } export function getDeprecateCollateralInfoInstructionDataCodec(): FixedSizeCodec<DeprecateCollateralInfoInstructionDataArgs, DeprecateCollateralInfoInstructionData> { return combineCodec(getDeprecateCollateralInfoInstructionDataEncoder(), getDeprecateCollateralInfoInstructionDataDecoder()); } export type DeprecateCollateralInfoInput<TAccountAdminAuthority extends string = string, TAccountGlobalConfig extends string = string, TAccountTokenInfos extends string = string> = { adminAuthority: TransactionSigner<TAccountAdminAuthority>; globalConfig: Address<TAccountGlobalConfig>; tokenInfos: Address<TAccountTokenInfos>; index: DeprecateCollateralInfoInstructionDataArgs["index"]; } export function getDeprecateCollateralInfoInstruction<TAccountAdminAuthority extends string, TAccountGlobalConfig extends string, TAccountTokenInfos extends string, TProgramAddress extends Address = typeof YVAULTS_PROGRAM_ADDRESS>(input: DeprecateCollateralInfoInput<TAccountAdminAuthority, TAccountGlobalConfig, TAccountTokenInfos>, config?: { programAddress?: TProgramAddress } ): DeprecateCollateralInfoInstruction<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: getDeprecateCollateralInfoInstructionDataEncoder().encode(args as DeprecateCollateralInfoInstructionDataArgs), programAddress } as DeprecateCollateralInfoInstruction<TProgramAddress, TAccountAdminAuthority, TAccountGlobalConfig, TAccountTokenInfos>); } export type ParsedDeprecateCollateralInfoInstruction<TProgram extends string = typeof YVAULTS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { adminAuthority: TAccountMetas[0]; globalConfig: TAccountMetas[1]; tokenInfos: TAccountMetas[2]; }; data: DeprecateCollateralInfoInstructionData; }; export function parseDeprecateCollateralInfoInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedDeprecateCollateralInfoInstruction<TProgram, TAccountMetas> { 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: getDeprecateCollateralInfoInstructionDataDecoder().decode(instruction.data) }; }