@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
77 lines (59 loc) • 6.84 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 SET_REWARD_EMISSIONS_SUPER_AUTHORITY_DISCRIMINATOR = new Uint8Array([207, 5, 200, 209, 122, 56, 82, 183]);
export function getSetRewardEmissionsSuperAuthorityDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SET_REWARD_EMISSIONS_SUPER_AUTHORITY_DISCRIMINATOR); }
export type SetRewardEmissionsSuperAuthorityInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpoolsConfig extends string | AccountMeta<string> = string, TAccountRewardEmissionsSuperAuthority extends string | AccountMeta<string> = string, TAccountNewRewardEmissionsSuperAuthority extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountWhirlpoolsConfig extends string ? WritableAccount<TAccountWhirlpoolsConfig> : TAccountWhirlpoolsConfig, TAccountRewardEmissionsSuperAuthority extends string ? ReadonlySignerAccount<TAccountRewardEmissionsSuperAuthority> & AccountSignerMeta<TAccountRewardEmissionsSuperAuthority> : TAccountRewardEmissionsSuperAuthority, TAccountNewRewardEmissionsSuperAuthority extends string ? ReadonlyAccount<TAccountNewRewardEmissionsSuperAuthority> : TAccountNewRewardEmissionsSuperAuthority, ...TRemainingAccounts]>;
export type SetRewardEmissionsSuperAuthorityInstructionData = { discriminator: ReadonlyUint8Array; };
export type SetRewardEmissionsSuperAuthorityInstructionDataArgs = { };
export function getSetRewardEmissionsSuperAuthorityInstructionDataEncoder(): FixedSizeEncoder<SetRewardEmissionsSuperAuthorityInstructionDataArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: SET_REWARD_EMISSIONS_SUPER_AUTHORITY_DISCRIMINATOR }));
}
export function getSetRewardEmissionsSuperAuthorityInstructionDataDecoder(): FixedSizeDecoder<SetRewardEmissionsSuperAuthorityInstructionData> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
}
export function getSetRewardEmissionsSuperAuthorityInstructionDataCodec(): FixedSizeCodec<SetRewardEmissionsSuperAuthorityInstructionDataArgs, SetRewardEmissionsSuperAuthorityInstructionData> {
return combineCodec(getSetRewardEmissionsSuperAuthorityInstructionDataEncoder(), getSetRewardEmissionsSuperAuthorityInstructionDataDecoder());
}
export type SetRewardEmissionsSuperAuthorityInput<TAccountWhirlpoolsConfig extends string = string, TAccountRewardEmissionsSuperAuthority extends string = string, TAccountNewRewardEmissionsSuperAuthority extends string = string> = {
whirlpoolsConfig: Address<TAccountWhirlpoolsConfig>;
rewardEmissionsSuperAuthority: TransactionSigner<TAccountRewardEmissionsSuperAuthority>;
newRewardEmissionsSuperAuthority: Address<TAccountNewRewardEmissionsSuperAuthority>;
}
export function getSetRewardEmissionsSuperAuthorityInstruction<TAccountWhirlpoolsConfig extends string, TAccountRewardEmissionsSuperAuthority extends string, TAccountNewRewardEmissionsSuperAuthority extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: SetRewardEmissionsSuperAuthorityInput<TAccountWhirlpoolsConfig, TAccountRewardEmissionsSuperAuthority, TAccountNewRewardEmissionsSuperAuthority>, config?: { programAddress?: TProgramAddress } ): SetRewardEmissionsSuperAuthorityInstruction<TProgramAddress, TAccountWhirlpoolsConfig, TAccountRewardEmissionsSuperAuthority, TAccountNewRewardEmissionsSuperAuthority> {
// Program address.
const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { whirlpoolsConfig: { value: input.whirlpoolsConfig ?? null, isWritable: true }, rewardEmissionsSuperAuthority: { value: input.rewardEmissionsSuperAuthority ?? null, isWritable: false }, newRewardEmissionsSuperAuthority: { value: input.newRewardEmissionsSuperAuthority ?? null, isWritable: false } }
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.whirlpoolsConfig), getAccountMeta(accounts.rewardEmissionsSuperAuthority), getAccountMeta(accounts.newRewardEmissionsSuperAuthority)], data: getSetRewardEmissionsSuperAuthorityInstructionDataEncoder().encode({}), programAddress } as SetRewardEmissionsSuperAuthorityInstruction<TProgramAddress, TAccountWhirlpoolsConfig, TAccountRewardEmissionsSuperAuthority, TAccountNewRewardEmissionsSuperAuthority>);
}
export type ParsedSetRewardEmissionsSuperAuthorityInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
whirlpoolsConfig: TAccountMetas[0];
rewardEmissionsSuperAuthority: TAccountMetas[1];
newRewardEmissionsSuperAuthority: TAccountMetas[2];
};
data: SetRewardEmissionsSuperAuthorityInstructionData; };
export function parseSetRewardEmissionsSuperAuthorityInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSetRewardEmissionsSuperAuthorityInstruction<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(), rewardEmissionsSuperAuthority: getNextAccount(), newRewardEmissionsSuperAuthority: getNextAccount() }, data: getSetRewardEmissionsSuperAuthorityInstructionDataDecoder().decode(instruction.data) };
}