@kamino-finance/farms-sdk
Version:
129 lines • 5.61 kB
JavaScript
;
/**
* 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
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.HARVEST_REWARD_DISCRIMINATOR = void 0;
exports.getHarvestRewardDiscriminatorBytes = getHarvestRewardDiscriminatorBytes;
exports.getHarvestRewardInstructionDataEncoder = getHarvestRewardInstructionDataEncoder;
exports.getHarvestRewardInstructionDataDecoder = getHarvestRewardInstructionDataDecoder;
exports.getHarvestRewardInstructionDataCodec = getHarvestRewardInstructionDataCodec;
exports.getHarvestRewardInstruction = getHarvestRewardInstruction;
exports.parseHarvestRewardInstruction = parseHarvestRewardInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.HARVEST_REWARD_DISCRIMINATOR = new Uint8Array([
68, 200, 228, 233, 184, 32, 226, 188,
]);
function getHarvestRewardDiscriminatorBytes() {
return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.HARVEST_REWARD_DISCRIMINATOR);
}
function getHarvestRewardInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
["rewardIndex", (0, kit_1.getU64Encoder)()],
]), (value) => ({ ...value, discriminator: exports.HARVEST_REWARD_DISCRIMINATOR }));
}
function getHarvestRewardInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([
["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
["rewardIndex", (0, kit_1.getU64Decoder)()],
]);
}
function getHarvestRewardInstructionDataCodec() {
return (0, kit_1.combineCodec)(getHarvestRewardInstructionDataEncoder(), getHarvestRewardInstructionDataDecoder());
}
function getHarvestRewardInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.FARMS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
payer: { value: input.payer ?? null, isWritable: true },
userState: { value: input.userState ?? null, isWritable: true },
farmState: { value: input.farmState ?? null, isWritable: true },
globalConfig: { value: input.globalConfig ?? null, isWritable: false },
rewardMint: { value: input.rewardMint ?? null, isWritable: false },
userRewardTokenAccount: {
value: input.userRewardTokenAccount ?? null,
isWritable: true,
},
rewardsVault: { value: input.rewardsVault ?? null, isWritable: true },
rewardsTreasuryVault: {
value: input.rewardsTreasuryVault ?? null,
isWritable: true,
},
farmVaultsAuthority: {
value: input.farmVaultsAuthority ?? null,
isWritable: false,
},
scopePrices: { value: input.scopePrices ?? null, isWritable: false },
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Original args.
const args = { ...input };
// Resolve default values.
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
}
const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, "programId");
return Object.freeze({
accounts: [
getAccountMeta(accounts.payer),
getAccountMeta(accounts.userState),
getAccountMeta(accounts.farmState),
getAccountMeta(accounts.globalConfig),
getAccountMeta(accounts.rewardMint),
getAccountMeta(accounts.userRewardTokenAccount),
getAccountMeta(accounts.rewardsVault),
getAccountMeta(accounts.rewardsTreasuryVault),
getAccountMeta(accounts.farmVaultsAuthority),
getAccountMeta(accounts.scopePrices),
getAccountMeta(accounts.tokenProgram),
],
data: getHarvestRewardInstructionDataEncoder().encode(args),
programAddress,
});
}
function parseHarvestRewardInstruction(instruction) {
if (instruction.accounts.length < 11) {
// TODO: Coded error.
throw new Error("Not enough accounts");
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts[accountIndex];
accountIndex += 1;
return accountMeta;
};
const getNextOptionalAccount = () => {
const accountMeta = getNextAccount();
return accountMeta.address === programs_1.FARMS_PROGRAM_ADDRESS
? undefined
: accountMeta;
};
return {
programAddress: instruction.programAddress,
accounts: {
payer: getNextAccount(),
userState: getNextAccount(),
farmState: getNextAccount(),
globalConfig: getNextAccount(),
rewardMint: getNextAccount(),
userRewardTokenAccount: getNextAccount(),
rewardsVault: getNextAccount(),
rewardsTreasuryVault: getNextAccount(),
farmVaultsAuthority: getNextAccount(),
scopePrices: getNextOptionalAccount(),
tokenProgram: getNextAccount(),
},
data: getHarvestRewardInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=harvestReward.js.map