@kamino-finance/farms-sdk
Version:
111 lines • 4.62 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.STAKE_DISCRIMINATOR = void 0;
exports.getStakeDiscriminatorBytes = getStakeDiscriminatorBytes;
exports.getStakeInstructionDataEncoder = getStakeInstructionDataEncoder;
exports.getStakeInstructionDataDecoder = getStakeInstructionDataDecoder;
exports.getStakeInstructionDataCodec = getStakeInstructionDataCodec;
exports.getStakeInstruction = getStakeInstruction;
exports.parseStakeInstruction = parseStakeInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.STAKE_DISCRIMINATOR = new Uint8Array([
206, 176, 202, 18, 200, 209, 179, 108,
]);
function getStakeDiscriminatorBytes() {
return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.STAKE_DISCRIMINATOR);
}
function getStakeInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
["amount", (0, kit_1.getU64Encoder)()],
]), (value) => ({ ...value, discriminator: exports.STAKE_DISCRIMINATOR }));
}
function getStakeInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([
["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
["amount", (0, kit_1.getU64Decoder)()],
]);
}
function getStakeInstructionDataCodec() {
return (0, kit_1.combineCodec)(getStakeInstructionDataEncoder(), getStakeInstructionDataDecoder());
}
function getStakeInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.FARMS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
owner: { value: input.owner ?? null, isWritable: false },
userState: { value: input.userState ?? null, isWritable: true },
farmState: { value: input.farmState ?? null, isWritable: true },
farmVault: { value: input.farmVault ?? null, isWritable: true },
userAta: { value: input.userAta ?? null, isWritable: true },
tokenMint: { value: input.tokenMint ?? 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.owner),
getAccountMeta(accounts.userState),
getAccountMeta(accounts.farmState),
getAccountMeta(accounts.farmVault),
getAccountMeta(accounts.userAta),
getAccountMeta(accounts.tokenMint),
getAccountMeta(accounts.scopePrices),
getAccountMeta(accounts.tokenProgram),
],
data: getStakeInstructionDataEncoder().encode(args),
programAddress,
});
}
function parseStakeInstruction(instruction) {
if (instruction.accounts.length < 8) {
// 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: {
owner: getNextAccount(),
userState: getNextAccount(),
farmState: getNextAccount(),
farmVault: getNextAccount(),
userAta: getNextAccount(),
tokenMint: getNextAccount(),
scopePrices: getNextOptionalAccount(),
tokenProgram: getNextAccount(),
},
data: getStakeInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=stake.js.map