@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
90 lines (73 loc) • 9.15 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, 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 COLLECT_PROTOCOL_FEES_DISCRIMINATOR = new Uint8Array([22, 67, 23, 98, 150, 178, 70, 220]);
export function getCollectProtocolFeesDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(COLLECT_PROTOCOL_FEES_DISCRIMINATOR); }
export type CollectProtocolFeesInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpoolsConfig extends string | AccountMeta<string> = string, TAccountWhirlpool extends string | AccountMeta<string> = string, TAccountCollectProtocolFeesAuthority extends string | AccountMeta<string> = string, TAccountTokenVaultA extends string | AccountMeta<string> = string, TAccountTokenVaultB extends string | AccountMeta<string> = string, TAccountTokenDestinationA extends string | AccountMeta<string> = string, TAccountTokenDestinationB extends string | AccountMeta<string> = string, TAccountTokenProgram extends string | AccountMeta<string> = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountWhirlpoolsConfig extends string ? ReadonlyAccount<TAccountWhirlpoolsConfig> : TAccountWhirlpoolsConfig, TAccountWhirlpool extends string ? WritableAccount<TAccountWhirlpool> : TAccountWhirlpool, TAccountCollectProtocolFeesAuthority extends string ? ReadonlySignerAccount<TAccountCollectProtocolFeesAuthority> & AccountSignerMeta<TAccountCollectProtocolFeesAuthority> : TAccountCollectProtocolFeesAuthority, TAccountTokenVaultA extends string ? WritableAccount<TAccountTokenVaultA> : TAccountTokenVaultA, TAccountTokenVaultB extends string ? WritableAccount<TAccountTokenVaultB> : TAccountTokenVaultB, TAccountTokenDestinationA extends string ? WritableAccount<TAccountTokenDestinationA> : TAccountTokenDestinationA, TAccountTokenDestinationB extends string ? WritableAccount<TAccountTokenDestinationB> : TAccountTokenDestinationB, TAccountTokenProgram extends string ? ReadonlyAccount<TAccountTokenProgram> : TAccountTokenProgram, ...TRemainingAccounts]>;
export type CollectProtocolFeesInstructionData = { discriminator: ReadonlyUint8Array; };
export type CollectProtocolFeesInstructionDataArgs = { };
export function getCollectProtocolFeesInstructionDataEncoder(): FixedSizeEncoder<CollectProtocolFeesInstructionDataArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: COLLECT_PROTOCOL_FEES_DISCRIMINATOR }));
}
export function getCollectProtocolFeesInstructionDataDecoder(): FixedSizeDecoder<CollectProtocolFeesInstructionData> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
}
export function getCollectProtocolFeesInstructionDataCodec(): FixedSizeCodec<CollectProtocolFeesInstructionDataArgs, CollectProtocolFeesInstructionData> {
return combineCodec(getCollectProtocolFeesInstructionDataEncoder(), getCollectProtocolFeesInstructionDataDecoder());
}
export type CollectProtocolFeesInput<TAccountWhirlpoolsConfig extends string = string, TAccountWhirlpool extends string = string, TAccountCollectProtocolFeesAuthority extends string = string, TAccountTokenVaultA extends string = string, TAccountTokenVaultB extends string = string, TAccountTokenDestinationA extends string = string, TAccountTokenDestinationB extends string = string, TAccountTokenProgram extends string = string> = {
whirlpoolsConfig: Address<TAccountWhirlpoolsConfig>;
whirlpool: Address<TAccountWhirlpool>;
collectProtocolFeesAuthority: TransactionSigner<TAccountCollectProtocolFeesAuthority>;
tokenVaultA: Address<TAccountTokenVaultA>;
tokenVaultB: Address<TAccountTokenVaultB>;
tokenDestinationA: Address<TAccountTokenDestinationA>;
tokenDestinationB: Address<TAccountTokenDestinationB>;
tokenProgram?: Address<TAccountTokenProgram>;
}
export function getCollectProtocolFeesInstruction<TAccountWhirlpoolsConfig extends string, TAccountWhirlpool extends string, TAccountCollectProtocolFeesAuthority extends string, TAccountTokenVaultA extends string, TAccountTokenVaultB extends string, TAccountTokenDestinationA extends string, TAccountTokenDestinationB extends string, TAccountTokenProgram extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: CollectProtocolFeesInput<TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountCollectProtocolFeesAuthority, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTokenDestinationA, TAccountTokenDestinationB, TAccountTokenProgram>, config?: { programAddress?: TProgramAddress } ): CollectProtocolFeesInstruction<TProgramAddress, TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountCollectProtocolFeesAuthority, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTokenDestinationA, TAccountTokenDestinationB, TAccountTokenProgram> {
// 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 }, collectProtocolFeesAuthority: { value: input.collectProtocolFeesAuthority ?? null, isWritable: false }, tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, tokenDestinationA: { value: input.tokenDestinationA ?? null, isWritable: true }, tokenDestinationB: { value: input.tokenDestinationB ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false } }
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
// Resolve default values.
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>;
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.whirlpoolsConfig), getAccountMeta(accounts.whirlpool), getAccountMeta(accounts.collectProtocolFeesAuthority), getAccountMeta(accounts.tokenVaultA), getAccountMeta(accounts.tokenVaultB), getAccountMeta(accounts.tokenDestinationA), getAccountMeta(accounts.tokenDestinationB), getAccountMeta(accounts.tokenProgram)], data: getCollectProtocolFeesInstructionDataEncoder().encode({}), programAddress } as CollectProtocolFeesInstruction<TProgramAddress, TAccountWhirlpoolsConfig, TAccountWhirlpool, TAccountCollectProtocolFeesAuthority, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTokenDestinationA, TAccountTokenDestinationB, TAccountTokenProgram>);
}
export type ParsedCollectProtocolFeesInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
whirlpoolsConfig: TAccountMetas[0];
whirlpool: TAccountMetas[1];
collectProtocolFeesAuthority: TAccountMetas[2];
tokenVaultA: TAccountMetas[3];
tokenVaultB: TAccountMetas[4];
tokenDestinationA: TAccountMetas[5];
tokenDestinationB: TAccountMetas[6];
tokenProgram: TAccountMetas[7];
};
data: CollectProtocolFeesInstructionData; };
export function parseCollectProtocolFeesInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedCollectProtocolFeesInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 8) {
// 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(), collectProtocolFeesAuthority: getNextAccount(), tokenVaultA: getNextAccount(), tokenVaultB: getNextAccount(), tokenDestinationA: getNextAccount(), tokenDestinationB: getNextAccount(), tokenProgram: getNextAccount() }, data: getCollectProtocolFeesInstructionDataDecoder().decode(instruction.data) };
}