@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
81 lines (61 loc) • 5.38 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, getU32Decoder, getU32Encoder, getU8Decoder, getU8Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit';
import { AMM_V3_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const UPDATE_AMM_CONFIG_DISCRIMINATOR = new Uint8Array([49, 60, 174, 136, 154, 28, 116, 200]);
export function getUpdateAmmConfigDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_AMM_CONFIG_DISCRIMINATOR); }
export type UpdateAmmConfigInstruction<TProgram extends string = typeof AMM_V3_PROGRAM_ADDRESS, TAccountOwner extends string | AccountMeta<string> = string, TAccountAmmConfig extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountOwner extends string ? ReadonlySignerAccount<TAccountOwner> & AccountSignerMeta<TAccountOwner> : TAccountOwner, TAccountAmmConfig extends string ? WritableAccount<TAccountAmmConfig> : TAccountAmmConfig, ...TRemainingAccounts]>;
export type UpdateAmmConfigInstructionData = { discriminator: ReadonlyUint8Array; param: number; value: number; };
export type UpdateAmmConfigInstructionDataArgs = { param: number; value: number; };
export function getUpdateAmmConfigInstructionDataEncoder(): FixedSizeEncoder<UpdateAmmConfigInstructionDataArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['param', getU8Encoder()], ['value', getU32Encoder()]]), (value) => ({ ...value, discriminator: UPDATE_AMM_CONFIG_DISCRIMINATOR }));
}
export function getUpdateAmmConfigInstructionDataDecoder(): FixedSizeDecoder<UpdateAmmConfigInstructionData> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['param', getU8Decoder()], ['value', getU32Decoder()]]);
}
export function getUpdateAmmConfigInstructionDataCodec(): FixedSizeCodec<UpdateAmmConfigInstructionDataArgs, UpdateAmmConfigInstructionData> {
return combineCodec(getUpdateAmmConfigInstructionDataEncoder(), getUpdateAmmConfigInstructionDataDecoder());
}
export type UpdateAmmConfigInput<TAccountOwner extends string = string, TAccountAmmConfig extends string = string> = {
owner: TransactionSigner<TAccountOwner>;
ammConfig: Address<TAccountAmmConfig>;
param: UpdateAmmConfigInstructionDataArgs["param"];
value: UpdateAmmConfigInstructionDataArgs["value"];
}
export function getUpdateAmmConfigInstruction<TAccountOwner extends string, TAccountAmmConfig extends string, TProgramAddress extends Address = typeof AMM_V3_PROGRAM_ADDRESS>(input: UpdateAmmConfigInput<TAccountOwner, TAccountAmmConfig>, config?: { programAddress?: TProgramAddress } ): UpdateAmmConfigInstruction<TProgramAddress, TAccountOwner, TAccountAmmConfig> {
// Program address.
const programAddress = config?.programAddress ?? AMM_V3_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { owner: { value: input.owner ?? null, isWritable: false }, ammConfig: { value: input.ammConfig ?? 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.owner), getAccountMeta(accounts.ammConfig)], data: getUpdateAmmConfigInstructionDataEncoder().encode(args as UpdateAmmConfigInstructionDataArgs), programAddress } as UpdateAmmConfigInstruction<TProgramAddress, TAccountOwner, TAccountAmmConfig>);
}
export type ParsedUpdateAmmConfigInstruction<TProgram extends string = typeof AMM_V3_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
owner: TAccountMetas[0];
ammConfig: TAccountMetas[1];
};
data: UpdateAmmConfigInstructionData; };
export function parseUpdateAmmConfigInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedUpdateAmmConfigInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 2) {
// 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: { owner: getNextAccount(), ammConfig: getNextAccount() }, data: getUpdateAmmConfigInstructionDataDecoder().decode(instruction.data) };
}