UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

82 lines (62 loc) 5.84 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, getU16Decoder, getU16Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit'; import { WHIRLPOOL_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export const SET_FEE_RATE_DISCRIMINATOR = new Uint8Array([53, 243, 137, 65, 8, 140, 158, 6]); export function getSetFeeRateDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SET_FEE_RATE_DISCRIMINATOR); } export type SetFeeRateInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpoolsConfig extends string | AccountMeta<string> = string, TAccountWhirlpool extends string | AccountMeta<string> = string, TAccountFeeAuthority extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountWhirlpoolsConfig extends string ? ReadonlyAccount<TAccountWhirlpoolsConfig> : TAccountWhirlpoolsConfig, TAccountWhirlpool extends string ? WritableAccount<TAccountWhirlpool> : TAccountWhirlpool, TAccountFeeAuthority extends string ? ReadonlySignerAccount<TAccountFeeAuthority> & AccountSignerMeta<TAccountFeeAuthority> : TAccountFeeAuthority, ...TRemainingAccounts]>; export type SetFeeRateInstructionData = { discriminator: ReadonlyUint8Array; feeRate: number; }; export type SetFeeRateInstructionDataArgs = { feeRate: number; }; export function getSetFeeRateInstructionDataEncoder(): FixedSizeEncoder<SetFeeRateInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['feeRate', getU16Encoder()]]), (value) => ({ ...value, discriminator: SET_FEE_RATE_DISCRIMINATOR })); } export function getSetFeeRateInstructionDataDecoder(): FixedSizeDecoder<SetFeeRateInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['feeRate', getU16Decoder()]]); } export function getSetFeeRateInstructionDataCodec(): FixedSizeCodec<SetFeeRateInstructionDataArgs, SetFeeRateInstructionData> { return combineCodec(getSetFeeRateInstructionDataEncoder(), getSetFeeRateInstructionDataDecoder()); } export type SetFeeRateInput<TAccountWhirlpoolsConfig extends string = string, TAccountWhirlpool extends string = string, TAccountFeeAuthority extends string = string> = { whirlpoolsConfig: Address<TAccountWhirlpoolsConfig>; whirlpool: Address<TAccountWhirlpool>; feeAuthority: TransactionSigner<TAccountFeeAuthority>; feeRate: SetFeeRateInstructionDataArgs["feeRate"]; } export function getSetFeeRateInstruction<TAccountWhirlpoolsConfig extends string, TAccountWhirlpool extends string, TAccountFeeAuthority extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: SetFeeRateInput<TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountFeeAuthority>, config?: { programAddress?: TProgramAddress } ): SetFeeRateInstruction<TProgramAddress, TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountFeeAuthority> { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { whirlpoolsConfig: { value: input.whirlpoolsConfig ?? null, isWritable: false }, whirlpool: { value: input.whirlpool ?? null, isWritable: true }, feeAuthority: { value: input.feeAuthority ?? null, isWritable: false } } 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.whirlpoolsConfig), getAccountMeta(accounts.whirlpool), getAccountMeta(accounts.feeAuthority)], data: getSetFeeRateInstructionDataEncoder().encode(args as SetFeeRateInstructionDataArgs), programAddress } as SetFeeRateInstruction<TProgramAddress, TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountFeeAuthority>); } export type ParsedSetFeeRateInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { whirlpoolsConfig: TAccountMetas[0]; whirlpool: TAccountMetas[1]; feeAuthority: TAccountMetas[2]; }; data: SetFeeRateInstructionData; }; export function parseSetFeeRateInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSetFeeRateInstruction<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: { whirlpoolsConfig: getNextAccount(), whirlpool: getNextAccount(), feeAuthority: getNextAccount() }, data: getSetFeeRateInstructionDataDecoder().decode(instruction.data) }; }