@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
90 lines (71 loc) • 7.35 kB
text/typescript
/**
* 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, type WritableSignerAccount } from '@solana/kit';
import { WHIRLPOOL_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const INITIALIZE_FEE_TIER_DISCRIMINATOR = new Uint8Array([183, 74, 156, 160, 112, 2, 42, 30]);
export function getInitializeFeeTierDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(INITIALIZE_FEE_TIER_DISCRIMINATOR); }
export type InitializeFeeTierInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountConfig extends string | AccountMeta<string> = string, TAccountFeeTier extends string | AccountMeta<string> = string, TAccountFunder extends string | AccountMeta<string> = string, TAccountFeeAuthority extends string | AccountMeta<string> = string, TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountConfig extends string ? ReadonlyAccount<TAccountConfig> : TAccountConfig, TAccountFeeTier extends string ? WritableAccount<TAccountFeeTier> : TAccountFeeTier, TAccountFunder extends string ? WritableSignerAccount<TAccountFunder> & AccountSignerMeta<TAccountFunder> : TAccountFunder, TAccountFeeAuthority extends string ? ReadonlySignerAccount<TAccountFeeAuthority> & AccountSignerMeta<TAccountFeeAuthority> : TAccountFeeAuthority, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, ...TRemainingAccounts]>;
export type InitializeFeeTierInstructionData = { discriminator: ReadonlyUint8Array; tickSpacing: number; defaultFeeRate: number; };
export type InitializeFeeTierInstructionDataArgs = { tickSpacing: number; defaultFeeRate: number; };
export function getInitializeFeeTierInstructionDataEncoder(): FixedSizeEncoder<InitializeFeeTierInstructionDataArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['tickSpacing', getU16Encoder()], ['defaultFeeRate', getU16Encoder()]]), (value) => ({ ...value, discriminator: INITIALIZE_FEE_TIER_DISCRIMINATOR }));
}
export function getInitializeFeeTierInstructionDataDecoder(): FixedSizeDecoder<InitializeFeeTierInstructionData> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['tickSpacing', getU16Decoder()], ['defaultFeeRate', getU16Decoder()]]);
}
export function getInitializeFeeTierInstructionDataCodec(): FixedSizeCodec<InitializeFeeTierInstructionDataArgs, InitializeFeeTierInstructionData> {
return combineCodec(getInitializeFeeTierInstructionDataEncoder(), getInitializeFeeTierInstructionDataDecoder());
}
export type InitializeFeeTierInput<TAccountConfig extends string = string, TAccountFeeTier extends string = string, TAccountFunder extends string = string, TAccountFeeAuthority extends string = string, TAccountSystemProgram extends string = string> = {
config: Address<TAccountConfig>;
feeTier: Address<TAccountFeeTier>;
funder: TransactionSigner<TAccountFunder>;
feeAuthority: TransactionSigner<TAccountFeeAuthority>;
systemProgram?: Address<TAccountSystemProgram>;
tickSpacing: InitializeFeeTierInstructionDataArgs["tickSpacing"];
defaultFeeRate: InitializeFeeTierInstructionDataArgs["defaultFeeRate"];
}
export function getInitializeFeeTierInstruction<TAccountConfig extends string, TAccountFeeTier extends string, TAccountFunder extends string, TAccountFeeAuthority extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: InitializeFeeTierInput<TAccountConfig, TAccountFeeTier, TAccountFunder, TAccountFeeAuthority, TAccountSystemProgram>, config?: { programAddress?: TProgramAddress } ): InitializeFeeTierInstruction<TProgramAddress, TAccountConfig, TAccountFeeTier, TAccountFunder, TAccountFeeAuthority, TAccountSystemProgram> {
// Program address.
const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { config: { value: input.config ?? null, isWritable: false }, feeTier: { value: input.feeTier ?? null, isWritable: true }, funder: { value: input.funder ?? null, isWritable: true }, feeAuthority: { value: input.feeAuthority ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false } }
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
// Original args.
const args = { ...input, };
// Resolve default values.
if (!accounts.systemProgram.value) {
accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.config), getAccountMeta(accounts.feeTier), getAccountMeta(accounts.funder), getAccountMeta(accounts.feeAuthority), getAccountMeta(accounts.systemProgram)], data: getInitializeFeeTierInstructionDataEncoder().encode(args as InitializeFeeTierInstructionDataArgs), programAddress } as InitializeFeeTierInstruction<TProgramAddress, TAccountConfig, TAccountFeeTier, TAccountFunder, TAccountFeeAuthority, TAccountSystemProgram>);
}
export type ParsedInitializeFeeTierInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
config: TAccountMetas[0];
feeTier: TAccountMetas[1];
funder: TAccountMetas[2];
feeAuthority: TAccountMetas[3];
systemProgram: TAccountMetas[4];
};
data: InitializeFeeTierInstructionData; };
export function parseInitializeFeeTierInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedInitializeFeeTierInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 5) {
// 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: { config: getNextAccount(), feeTier: getNextAccount(), funder: getNextAccount(), feeAuthority: getNextAccount(), systemProgram: getNextAccount() }, data: getInitializeFeeTierInstructionDataDecoder().decode(instruction.data) };
}