UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

84 lines (64 loc) 6.46 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 UPDATE_COLLATERAL_INFO_DISCRIMINATOR = new Uint8Array([76, 94, 131, 44, 137, 61, 161, 110]); export function getUpdateCollateralInfoDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_COLLATERAL_INFO_DISCRIMINATOR); } export type UpdateCollateralInfoInstruction<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 UpdateCollateralInfoInstructionData = { discriminator: ReadonlyUint8Array; index: bigint; mode: bigint; value: ReadonlyUint8Array; }; export type UpdateCollateralInfoInstructionDataArgs = { index: number | bigint; mode: number | bigint; value: ReadonlyUint8Array; }; export function getUpdateCollateralInfoInstructionDataEncoder(): FixedSizeEncoder<UpdateCollateralInfoInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['index', getU64Encoder()], ['mode', getU64Encoder()], ['value', fixEncoderSize(getBytesEncoder(), 32)]]), (value) => ({ ...value, discriminator: UPDATE_COLLATERAL_INFO_DISCRIMINATOR })); } export function getUpdateCollateralInfoInstructionDataDecoder(): FixedSizeDecoder<UpdateCollateralInfoInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['index', getU64Decoder()], ['mode', getU64Decoder()], ['value', fixDecoderSize(getBytesDecoder(), 32)]]); } export function getUpdateCollateralInfoInstructionDataCodec(): FixedSizeCodec<UpdateCollateralInfoInstructionDataArgs, UpdateCollateralInfoInstructionData> { return combineCodec(getUpdateCollateralInfoInstructionDataEncoder(), getUpdateCollateralInfoInstructionDataDecoder()); } export type UpdateCollateralInfoInput<TAccountAdminAuthority extends string = string, TAccountGlobalConfig extends string = string, TAccountTokenInfos extends string = string> = { adminAuthority: TransactionSigner<TAccountAdminAuthority>; globalConfig: Address<TAccountGlobalConfig>; tokenInfos: Address<TAccountTokenInfos>; index: UpdateCollateralInfoInstructionDataArgs["index"]; mode: UpdateCollateralInfoInstructionDataArgs["mode"]; value: UpdateCollateralInfoInstructionDataArgs["value"]; } export function getUpdateCollateralInfoInstruction<TAccountAdminAuthority extends string, TAccountGlobalConfig extends string, TAccountTokenInfos extends string, TProgramAddress extends Address = typeof YVAULTS_PROGRAM_ADDRESS>(input: UpdateCollateralInfoInput<TAccountAdminAuthority, TAccountGlobalConfig, TAccountTokenInfos>, config?: { programAddress?: TProgramAddress } ): UpdateCollateralInfoInstruction<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: getUpdateCollateralInfoInstructionDataEncoder().encode(args as UpdateCollateralInfoInstructionDataArgs), programAddress } as UpdateCollateralInfoInstruction<TProgramAddress, TAccountAdminAuthority, TAccountGlobalConfig, TAccountTokenInfos>); } export type ParsedUpdateCollateralInfoInstruction<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: UpdateCollateralInfoInstructionData; }; export function parseUpdateCollateralInfoInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedUpdateCollateralInfoInstruction<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: getUpdateCollateralInfoInstructionDataDecoder().decode(instruction.data) }; }