@kamino-finance/farms-sdk
Version:
184 lines (168 loc) • 5.55 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 ReadonlyUint8Array,
type TransactionSigner,
type WritableAccount,
type WritableSignerAccount,
} from "@solana/kit";
import { FARMS_PROGRAM_ADDRESS } from "../programs";
import { getAccountMetaFactory, type ResolvedAccount } from "../shared";
export const UPDATE_FARM_ADMIN_DISCRIMINATOR = new Uint8Array([
20, 37, 136, 19, 122, 239, 36, 130,
]);
export function getUpdateFarmAdminDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(
UPDATE_FARM_ADMIN_DISCRIMINATOR,
);
}
export type UpdateFarmAdminInstruction<
TProgram extends string = typeof FARMS_PROGRAM_ADDRESS,
TAccountPendingFarmAdmin extends string | AccountMeta<string> = string,
TAccountFarmState extends string | AccountMeta<string> = string,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountPendingFarmAdmin extends string
? WritableSignerAccount<TAccountPendingFarmAdmin> &
AccountSignerMeta<TAccountPendingFarmAdmin>
: TAccountPendingFarmAdmin,
TAccountFarmState extends string
? WritableAccount<TAccountFarmState>
: TAccountFarmState,
...TRemainingAccounts,
]
>;
export type UpdateFarmAdminInstructionData = {
discriminator: ReadonlyUint8Array;
};
export type UpdateFarmAdminInstructionDataArgs = {};
export function getUpdateFarmAdminInstructionDataEncoder(): FixedSizeEncoder<UpdateFarmAdminInstructionDataArgs> {
return transformEncoder(
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
(value) => ({ ...value, discriminator: UPDATE_FARM_ADMIN_DISCRIMINATOR }),
);
}
export function getUpdateFarmAdminInstructionDataDecoder(): FixedSizeDecoder<UpdateFarmAdminInstructionData> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
]);
}
export function getUpdateFarmAdminInstructionDataCodec(): FixedSizeCodec<
UpdateFarmAdminInstructionDataArgs,
UpdateFarmAdminInstructionData
> {
return combineCodec(
getUpdateFarmAdminInstructionDataEncoder(),
getUpdateFarmAdminInstructionDataDecoder(),
);
}
export type UpdateFarmAdminInput<
TAccountPendingFarmAdmin extends string = string,
TAccountFarmState extends string = string,
> = {
pendingFarmAdmin: TransactionSigner<TAccountPendingFarmAdmin>;
farmState: Address<TAccountFarmState>;
};
export function getUpdateFarmAdminInstruction<
TAccountPendingFarmAdmin extends string,
TAccountFarmState extends string,
TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS,
>(
input: UpdateFarmAdminInput<TAccountPendingFarmAdmin, TAccountFarmState>,
config?: { programAddress?: TProgramAddress },
): UpdateFarmAdminInstruction<
TProgramAddress,
TAccountPendingFarmAdmin,
TAccountFarmState
> {
// Program address.
const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
pendingFarmAdmin: {
value: input.pendingFarmAdmin ?? null,
isWritable: true,
},
farmState: { value: input.farmState ?? null, isWritable: true },
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
ResolvedAccount
>;
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
return Object.freeze({
accounts: [
getAccountMeta(accounts.pendingFarmAdmin),
getAccountMeta(accounts.farmState),
],
data: getUpdateFarmAdminInstructionDataEncoder().encode({}),
programAddress,
} as UpdateFarmAdminInstruction<
TProgramAddress,
TAccountPendingFarmAdmin,
TAccountFarmState
>);
}
export type ParsedUpdateFarmAdminInstruction<
TProgram extends string = typeof FARMS_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
pendingFarmAdmin: TAccountMetas[0];
farmState: TAccountMetas[1];
};
data: UpdateFarmAdminInstructionData;
};
export function parseUpdateFarmAdminInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedUpdateFarmAdminInstruction<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: {
pendingFarmAdmin: getNextAccount(),
farmState: getNextAccount(),
},
data: getUpdateFarmAdminInstructionDataDecoder().decode(instruction.data),
};
}