UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

94 lines (75 loc) 8.41 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, getU128Decoder, getU128Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, 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 { AMM_V3_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export const SET_REWARD_PARAMS_DISCRIMINATOR = new Uint8Array([112, 52, 167, 75, 32, 201, 211, 137]); export function getSetRewardParamsDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SET_REWARD_PARAMS_DISCRIMINATOR); } export type SetRewardParamsInstruction<TProgram extends string = typeof AMM_V3_PROGRAM_ADDRESS, TAccountAuthority extends string | AccountMeta<string> = string, TAccountAmmConfig extends string | AccountMeta<string> = string, TAccountPoolState extends string | AccountMeta<string> = string, TAccountOperationState extends string | AccountMeta<string> = string, TAccountTokenProgram extends string | AccountMeta<string> = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountTokenProgram2022 extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountAuthority extends string ? ReadonlySignerAccount<TAccountAuthority> & AccountSignerMeta<TAccountAuthority> : TAccountAuthority, TAccountAmmConfig extends string ? ReadonlyAccount<TAccountAmmConfig> : TAccountAmmConfig, TAccountPoolState extends string ? WritableAccount<TAccountPoolState> : TAccountPoolState, TAccountOperationState extends string ? ReadonlyAccount<TAccountOperationState> : TAccountOperationState, TAccountTokenProgram extends string ? ReadonlyAccount<TAccountTokenProgram> : TAccountTokenProgram, TAccountTokenProgram2022 extends string ? ReadonlyAccount<TAccountTokenProgram2022> : TAccountTokenProgram2022, ...TRemainingAccounts]>; export type SetRewardParamsInstructionData = { discriminator: ReadonlyUint8Array; rewardIndex: number; emissionsPerSecondX64: bigint; openTime: bigint; endTime: bigint; }; export type SetRewardParamsInstructionDataArgs = { rewardIndex: number; emissionsPerSecondX64: number | bigint; openTime: number | bigint; endTime: number | bigint; }; export function getSetRewardParamsInstructionDataEncoder(): FixedSizeEncoder<SetRewardParamsInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['rewardIndex', getU8Encoder()], ['emissionsPerSecondX64', getU128Encoder()], ['openTime', getU64Encoder()], ['endTime', getU64Encoder()]]), (value) => ({ ...value, discriminator: SET_REWARD_PARAMS_DISCRIMINATOR })); } export function getSetRewardParamsInstructionDataDecoder(): FixedSizeDecoder<SetRewardParamsInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['rewardIndex', getU8Decoder()], ['emissionsPerSecondX64', getU128Decoder()], ['openTime', getU64Decoder()], ['endTime', getU64Decoder()]]); } export function getSetRewardParamsInstructionDataCodec(): FixedSizeCodec<SetRewardParamsInstructionDataArgs, SetRewardParamsInstructionData> { return combineCodec(getSetRewardParamsInstructionDataEncoder(), getSetRewardParamsInstructionDataDecoder()); } export type SetRewardParamsInput<TAccountAuthority extends string = string, TAccountAmmConfig extends string = string, TAccountPoolState extends string = string, TAccountOperationState extends string = string, TAccountTokenProgram extends string = string, TAccountTokenProgram2022 extends string = string> = { authority: TransactionSigner<TAccountAuthority>; ammConfig: Address<TAccountAmmConfig>; poolState: Address<TAccountPoolState>; operationState: Address<TAccountOperationState>; tokenProgram?: Address<TAccountTokenProgram>; tokenProgram2022: Address<TAccountTokenProgram2022>; rewardIndex: SetRewardParamsInstructionDataArgs["rewardIndex"]; emissionsPerSecondX64: SetRewardParamsInstructionDataArgs["emissionsPerSecondX64"]; openTime: SetRewardParamsInstructionDataArgs["openTime"]; endTime: SetRewardParamsInstructionDataArgs["endTime"]; } export function getSetRewardParamsInstruction<TAccountAuthority extends string, TAccountAmmConfig extends string, TAccountPoolState extends string, TAccountOperationState extends string, TAccountTokenProgram extends string, TAccountTokenProgram2022 extends string, TProgramAddress extends Address = typeof AMM_V3_PROGRAM_ADDRESS>(input: SetRewardParamsInput<TAccountAuthority, TAccountAmmConfig, TAccountPoolState, TAccountOperationState, TAccountTokenProgram, TAccountTokenProgram2022>, config?: { programAddress?: TProgramAddress } ): SetRewardParamsInstruction<TProgramAddress, TAccountAuthority, TAccountAmmConfig, TAccountPoolState, TAccountOperationState, TAccountTokenProgram, TAccountTokenProgram2022> { // Program address. const programAddress = config?.programAddress ?? AMM_V3_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { authority: { value: input.authority ?? null, isWritable: false }, ammConfig: { value: input.ammConfig ?? null, isWritable: false }, poolState: { value: input.poolState ?? null, isWritable: true }, operationState: { value: input.operationState ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, tokenProgram2022: { value: input.tokenProgram2022 ?? null, isWritable: false } } const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>; // Original args. const args = { ...input, }; // 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.authority), getAccountMeta(accounts.ammConfig), getAccountMeta(accounts.poolState), getAccountMeta(accounts.operationState), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.tokenProgram2022)], data: getSetRewardParamsInstructionDataEncoder().encode(args as SetRewardParamsInstructionDataArgs), programAddress } as SetRewardParamsInstruction<TProgramAddress, TAccountAuthority, TAccountAmmConfig, TAccountPoolState, TAccountOperationState, TAccountTokenProgram, TAccountTokenProgram2022>); } export type ParsedSetRewardParamsInstruction<TProgram extends string = typeof AMM_V3_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { authority: TAccountMetas[0]; ammConfig: TAccountMetas[1]; poolState: TAccountMetas[2]; operationState: TAccountMetas[3]; tokenProgram: TAccountMetas[4]; tokenProgram2022: TAccountMetas[5]; }; data: SetRewardParamsInstructionData; }; export function parseSetRewardParamsInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSetRewardParamsInstruction<TProgram, TAccountMetas> { if (instruction.accounts.length < 6) { // 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: { authority: getNextAccount(), ammConfig: getNextAccount(), poolState: getNextAccount(), operationState: getNextAccount(), tokenProgram: getNextAccount(), tokenProgram2022: getNextAccount() }, data: getSetRewardParamsInstructionDataDecoder().decode(instruction.data) }; }