@kamino-finance/farms-sdk
Version:
102 lines • 4.53 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.WITHDRAW_SLASHED_AMOUNT_DISCRIMINATOR = void 0;
exports.getWithdrawSlashedAmountDiscriminatorBytes = getWithdrawSlashedAmountDiscriminatorBytes;
exports.getWithdrawSlashedAmountInstructionDataEncoder = getWithdrawSlashedAmountInstructionDataEncoder;
exports.getWithdrawSlashedAmountInstructionDataDecoder = getWithdrawSlashedAmountInstructionDataDecoder;
exports.getWithdrawSlashedAmountInstructionDataCodec = getWithdrawSlashedAmountInstructionDataCodec;
exports.getWithdrawSlashedAmountInstruction = getWithdrawSlashedAmountInstruction;
exports.parseWithdrawSlashedAmountInstruction = parseWithdrawSlashedAmountInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.WITHDRAW_SLASHED_AMOUNT_DISCRIMINATOR = new Uint8Array([
202, 217, 67, 74, 172, 22, 140, 216,
]);
function getWithdrawSlashedAmountDiscriminatorBytes() {
return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.WITHDRAW_SLASHED_AMOUNT_DISCRIMINATOR);
}
function getWithdrawSlashedAmountInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)]]), (value) => ({
...value,
discriminator: exports.WITHDRAW_SLASHED_AMOUNT_DISCRIMINATOR,
}));
}
function getWithdrawSlashedAmountInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([
["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
]);
}
function getWithdrawSlashedAmountInstructionDataCodec() {
return (0, kit_1.combineCodec)(getWithdrawSlashedAmountInstructionDataEncoder(), getWithdrawSlashedAmountInstructionDataDecoder());
}
function getWithdrawSlashedAmountInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.FARMS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
crank: { value: input.crank ?? null, isWritable: true },
farmState: { value: input.farmState ?? null, isWritable: true },
slashedAmountSpillAddress: {
value: input.slashedAmountSpillAddress ?? null,
isWritable: true,
},
farmVault: { value: input.farmVault ?? null, isWritable: true },
farmVaultsAuthority: {
value: input.farmVaultsAuthority ?? null,
isWritable: false,
},
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// 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.crank),
getAccountMeta(accounts.farmState),
getAccountMeta(accounts.slashedAmountSpillAddress),
getAccountMeta(accounts.farmVault),
getAccountMeta(accounts.farmVaultsAuthority),
getAccountMeta(accounts.tokenProgram),
],
data: getWithdrawSlashedAmountInstructionDataEncoder().encode({}),
programAddress,
});
}
function parseWithdrawSlashedAmountInstruction(instruction) {
if (instruction.accounts.length < 6) {
// TODO: Coded error.
throw new Error("Not enough accounts");
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts[accountIndex];
accountIndex += 1;
return accountMeta;
};
return {
programAddress: instruction.programAddress,
accounts: {
crank: getNextAccount(),
farmState: getNextAccount(),
slashedAmountSpillAddress: getNextAccount(),
farmVault: getNextAccount(),
farmVaultsAuthority: getNextAccount(),
tokenProgram: getNextAccount(),
},
data: getWithdrawSlashedAmountInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=withdrawSlashedAmount.js.map