@kamino-finance/farms-sdk
Version:
757 lines (748 loc) • 21.6 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 {
assertIsInstructionWithAccounts,
containsBytes,
fixEncoderSize,
getBytesEncoder,
type Address,
type Instruction,
type InstructionWithData,
type ReadonlyUint8Array,
} from "@solana/kit";
import {
parseAddRewardsInstruction,
parseCloseEmptyUserStateInstruction,
parseDepositToFarmVaultInstruction,
parseHarvestRewardInstruction,
parseIdlMissingTypesInstruction,
parseInitializeFarmDelegatedInstruction,
parseInitializeFarmInstruction,
parseInitializeGlobalConfigInstruction,
parseInitializeRewardInstruction,
parseInitializeUserInstruction,
parseRefreshFarmInstruction,
parseRefreshUserStateInstruction,
parseRewardUserOnceInstruction,
parseSetStakeDelegatedInstruction,
parseStakeInstruction,
parseTransferOwnershipInstruction,
parseUnstakeInstruction,
parseUpdateFarmAdminInstruction,
parseUpdateFarmConfigInstruction,
parseUpdateGlobalConfigAdminInstruction,
parseUpdateGlobalConfigInstruction,
parseUpdateSecondDelegatedAuthorityInstruction,
parseWithdrawFromFarmVaultInstruction,
parseWithdrawRewardInstruction,
parseWithdrawSlashedAmountInstruction,
parseWithdrawTreasuryInstruction,
parseWithdrawUnstakedDepositsInstruction,
type ParsedAddRewardsInstruction,
type ParsedCloseEmptyUserStateInstruction,
type ParsedDepositToFarmVaultInstruction,
type ParsedHarvestRewardInstruction,
type ParsedIdlMissingTypesInstruction,
type ParsedInitializeFarmDelegatedInstruction,
type ParsedInitializeFarmInstruction,
type ParsedInitializeGlobalConfigInstruction,
type ParsedInitializeRewardInstruction,
type ParsedInitializeUserInstruction,
type ParsedRefreshFarmInstruction,
type ParsedRefreshUserStateInstruction,
type ParsedRewardUserOnceInstruction,
type ParsedSetStakeDelegatedInstruction,
type ParsedStakeInstruction,
type ParsedTransferOwnershipInstruction,
type ParsedUnstakeInstruction,
type ParsedUpdateFarmAdminInstruction,
type ParsedUpdateFarmConfigInstruction,
type ParsedUpdateGlobalConfigAdminInstruction,
type ParsedUpdateGlobalConfigInstruction,
type ParsedUpdateSecondDelegatedAuthorityInstruction,
type ParsedWithdrawFromFarmVaultInstruction,
type ParsedWithdrawRewardInstruction,
type ParsedWithdrawSlashedAmountInstruction,
type ParsedWithdrawTreasuryInstruction,
type ParsedWithdrawUnstakedDepositsInstruction,
} from "../instructions";
export const FARMS_PROGRAM_ADDRESS = "FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr" as Address<"FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr">;
export enum FarmsAccount {
FarmState,
GlobalConfig,
UserState,
OraclePrices,
}
export function identifyFarmsAccount(
account: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
): FarmsAccount {
const data = "data" in account ? account.data : account;
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([198, 102, 216, 74, 63, 66, 163, 190]),
),
0,
)
) {
return FarmsAccount.FarmState;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([149, 8, 156, 202, 160, 252, 176, 217]),
),
0,
)
) {
return FarmsAccount.GlobalConfig;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([72, 177, 85, 249, 76, 167, 186, 126]),
),
0,
)
) {
return FarmsAccount.UserState;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([89, 128, 118, 221, 6, 72, 180, 146]),
),
0,
)
) {
return FarmsAccount.OraclePrices;
}
throw new Error(
"The provided account could not be identified as a farms account.",
);
}
export enum FarmsInstruction {
InitializeGlobalConfig,
UpdateGlobalConfig,
InitializeFarm,
InitializeFarmDelegated,
InitializeReward,
AddRewards,
UpdateFarmConfig,
InitializeUser,
TransferOwnership,
RewardUserOnce,
RefreshFarm,
Stake,
SetStakeDelegated,
HarvestReward,
Unstake,
RefreshUserState,
WithdrawUnstakedDeposits,
WithdrawTreasury,
DepositToFarmVault,
WithdrawFromFarmVault,
WithdrawSlashedAmount,
UpdateFarmAdmin,
UpdateGlobalConfigAdmin,
WithdrawReward,
UpdateSecondDelegatedAuthority,
CloseEmptyUserState,
IdlMissingTypes,
}
export function identifyFarmsInstruction(
instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
): FarmsInstruction {
const data = "data" in instruction ? instruction.data : instruction;
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([113, 216, 122, 131, 225, 209, 22, 55]),
),
0,
)
) {
return FarmsInstruction.InitializeGlobalConfig;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([164, 84, 130, 189, 111, 58, 250, 200]),
),
0,
)
) {
return FarmsInstruction.UpdateGlobalConfig;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([252, 28, 185, 172, 244, 74, 117, 165]),
),
0,
)
) {
return FarmsInstruction.InitializeFarm;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([250, 84, 101, 25, 51, 77, 204, 91]),
),
0,
)
) {
return FarmsInstruction.InitializeFarmDelegated;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([95, 135, 192, 196, 242, 129, 230, 68]),
),
0,
)
) {
return FarmsInstruction.InitializeReward;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([88, 186, 25, 227, 38, 137, 81, 23]),
),
0,
)
) {
return FarmsInstruction.AddRewards;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([214, 176, 188, 244, 203, 59, 230, 207]),
),
0,
)
) {
return FarmsInstruction.UpdateFarmConfig;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([111, 17, 185, 250, 60, 122, 38, 254]),
),
0,
)
) {
return FarmsInstruction.InitializeUser;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([65, 177, 215, 73, 53, 45, 99, 47]),
),
0,
)
) {
return FarmsInstruction.TransferOwnership;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([219, 137, 57, 22, 94, 186, 96, 114]),
),
0,
)
) {
return FarmsInstruction.RewardUserOnce;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([214, 131, 138, 183, 144, 194, 172, 42]),
),
0,
)
) {
return FarmsInstruction.RefreshFarm;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([206, 176, 202, 18, 200, 209, 179, 108]),
),
0,
)
) {
return FarmsInstruction.Stake;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([73, 171, 184, 75, 30, 56, 198, 223]),
),
0,
)
) {
return FarmsInstruction.SetStakeDelegated;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([68, 200, 228, 233, 184, 32, 226, 188]),
),
0,
)
) {
return FarmsInstruction.HarvestReward;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([90, 95, 107, 42, 205, 124, 50, 225]),
),
0,
)
) {
return FarmsInstruction.Unstake;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([1, 135, 12, 62, 243, 140, 77, 108]),
),
0,
)
) {
return FarmsInstruction.RefreshUserState;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([36, 102, 187, 49, 220, 36, 132, 67]),
),
0,
)
) {
return FarmsInstruction.WithdrawUnstakedDeposits;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([40, 63, 122, 158, 144, 216, 83, 96]),
),
0,
)
) {
return FarmsInstruction.WithdrawTreasury;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([131, 166, 64, 94, 108, 213, 114, 183]),
),
0,
)
) {
return FarmsInstruction.DepositToFarmVault;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([22, 82, 128, 250, 86, 79, 124, 78]),
),
0,
)
) {
return FarmsInstruction.WithdrawFromFarmVault;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([202, 217, 67, 74, 172, 22, 140, 216]),
),
0,
)
) {
return FarmsInstruction.WithdrawSlashedAmount;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([20, 37, 136, 19, 122, 239, 36, 130]),
),
0,
)
) {
return FarmsInstruction.UpdateFarmAdmin;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([184, 87, 23, 193, 156, 238, 175, 119]),
),
0,
)
) {
return FarmsInstruction.UpdateGlobalConfigAdmin;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([191, 187, 176, 137, 9, 25, 187, 244]),
),
0,
)
) {
return FarmsInstruction.WithdrawReward;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([127, 26, 6, 181, 203, 248, 117, 64]),
),
0,
)
) {
return FarmsInstruction.UpdateSecondDelegatedAuthority;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([240, 24, 9, 227, 86, 225, 199, 95]),
),
0,
)
) {
return FarmsInstruction.CloseEmptyUserState;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([130, 80, 38, 153, 80, 212, 182, 253]),
),
0,
)
) {
return FarmsInstruction.IdlMissingTypes;
}
throw new Error(
"The provided instruction could not be identified as a farms instruction.",
);
}
export type ParsedFarmsInstruction<TProgram extends string = ""> =
| ({
instructionType: FarmsInstruction.InitializeGlobalConfig;
} & ParsedInitializeGlobalConfigInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.UpdateGlobalConfig;
} & ParsedUpdateGlobalConfigInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.InitializeFarm;
} & ParsedInitializeFarmInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.InitializeFarmDelegated;
} & ParsedInitializeFarmDelegatedInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.InitializeReward;
} & ParsedInitializeRewardInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.AddRewards;
} & ParsedAddRewardsInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.UpdateFarmConfig;
} & ParsedUpdateFarmConfigInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.InitializeUser;
} & ParsedInitializeUserInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.TransferOwnership;
} & ParsedTransferOwnershipInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.RewardUserOnce;
} & ParsedRewardUserOnceInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.RefreshFarm;
} & ParsedRefreshFarmInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.Stake;
} & ParsedStakeInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.SetStakeDelegated;
} & ParsedSetStakeDelegatedInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.HarvestReward;
} & ParsedHarvestRewardInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.Unstake;
} & ParsedUnstakeInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.RefreshUserState;
} & ParsedRefreshUserStateInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.WithdrawUnstakedDeposits;
} & ParsedWithdrawUnstakedDepositsInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.WithdrawTreasury;
} & ParsedWithdrawTreasuryInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.DepositToFarmVault;
} & ParsedDepositToFarmVaultInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.WithdrawFromFarmVault;
} & ParsedWithdrawFromFarmVaultInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.WithdrawSlashedAmount;
} & ParsedWithdrawSlashedAmountInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.UpdateFarmAdmin;
} & ParsedUpdateFarmAdminInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.UpdateGlobalConfigAdmin;
} & ParsedUpdateGlobalConfigAdminInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.WithdrawReward;
} & ParsedWithdrawRewardInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.UpdateSecondDelegatedAuthority;
} & ParsedUpdateSecondDelegatedAuthorityInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.CloseEmptyUserState;
} & ParsedCloseEmptyUserStateInstruction<TProgram>)
| ({
instructionType: FarmsInstruction.IdlMissingTypes;
} & ParsedIdlMissingTypesInstruction<TProgram>);
export function parseFarmsInstruction<TProgram extends string>(
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
): ParsedFarmsInstruction<TProgram> {
const instructionType = identifyFarmsInstruction(instruction);
switch (instructionType) {
case FarmsInstruction.InitializeGlobalConfig: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.InitializeGlobalConfig,
...parseInitializeGlobalConfigInstruction(instruction),
};
}
case FarmsInstruction.UpdateGlobalConfig: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.UpdateGlobalConfig,
...parseUpdateGlobalConfigInstruction(instruction),
};
}
case FarmsInstruction.InitializeFarm: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.InitializeFarm,
...parseInitializeFarmInstruction(instruction),
};
}
case FarmsInstruction.InitializeFarmDelegated: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.InitializeFarmDelegated,
...parseInitializeFarmDelegatedInstruction(instruction),
};
}
case FarmsInstruction.InitializeReward: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.InitializeReward,
...parseInitializeRewardInstruction(instruction),
};
}
case FarmsInstruction.AddRewards: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.AddRewards,
...parseAddRewardsInstruction(instruction),
};
}
case FarmsInstruction.UpdateFarmConfig: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.UpdateFarmConfig,
...parseUpdateFarmConfigInstruction(instruction),
};
}
case FarmsInstruction.InitializeUser: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.InitializeUser,
...parseInitializeUserInstruction(instruction),
};
}
case FarmsInstruction.TransferOwnership: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.TransferOwnership,
...parseTransferOwnershipInstruction(instruction),
};
}
case FarmsInstruction.RewardUserOnce: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.RewardUserOnce,
...parseRewardUserOnceInstruction(instruction),
};
}
case FarmsInstruction.RefreshFarm: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.RefreshFarm,
...parseRefreshFarmInstruction(instruction),
};
}
case FarmsInstruction.Stake: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.Stake,
...parseStakeInstruction(instruction),
};
}
case FarmsInstruction.SetStakeDelegated: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.SetStakeDelegated,
...parseSetStakeDelegatedInstruction(instruction),
};
}
case FarmsInstruction.HarvestReward: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.HarvestReward,
...parseHarvestRewardInstruction(instruction),
};
}
case FarmsInstruction.Unstake: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.Unstake,
...parseUnstakeInstruction(instruction),
};
}
case FarmsInstruction.RefreshUserState: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.RefreshUserState,
...parseRefreshUserStateInstruction(instruction),
};
}
case FarmsInstruction.WithdrawUnstakedDeposits: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.WithdrawUnstakedDeposits,
...parseWithdrawUnstakedDepositsInstruction(instruction),
};
}
case FarmsInstruction.WithdrawTreasury: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.WithdrawTreasury,
...parseWithdrawTreasuryInstruction(instruction),
};
}
case FarmsInstruction.DepositToFarmVault: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.DepositToFarmVault,
...parseDepositToFarmVaultInstruction(instruction),
};
}
case FarmsInstruction.WithdrawFromFarmVault: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.WithdrawFromFarmVault,
...parseWithdrawFromFarmVaultInstruction(instruction),
};
}
case FarmsInstruction.WithdrawSlashedAmount: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.WithdrawSlashedAmount,
...parseWithdrawSlashedAmountInstruction(instruction),
};
}
case FarmsInstruction.UpdateFarmAdmin: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.UpdateFarmAdmin,
...parseUpdateFarmAdminInstruction(instruction),
};
}
case FarmsInstruction.UpdateGlobalConfigAdmin: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.UpdateGlobalConfigAdmin,
...parseUpdateGlobalConfigAdminInstruction(instruction),
};
}
case FarmsInstruction.WithdrawReward: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.WithdrawReward,
...parseWithdrawRewardInstruction(instruction),
};
}
case FarmsInstruction.UpdateSecondDelegatedAuthority: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.UpdateSecondDelegatedAuthority,
...parseUpdateSecondDelegatedAuthorityInstruction(instruction),
};
}
case FarmsInstruction.CloseEmptyUserState: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.CloseEmptyUserState,
...parseCloseEmptyUserStateInstruction(instruction),
};
}
case FarmsInstruction.IdlMissingTypes: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: FarmsInstruction.IdlMissingTypes,
...parseIdlMissingTypesInstruction(instruction),
};
}
default:
throw new Error(
`Unrecognized instruction type: ${instructionType as string}`,
);
}
}