@kamino-finance/farms-sdk
Version:
111 lines • 4.85 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_TREASURY_DISCRIMINATOR = void 0;
exports.getWithdrawTreasuryDiscriminatorBytes = getWithdrawTreasuryDiscriminatorBytes;
exports.getWithdrawTreasuryInstructionDataEncoder = getWithdrawTreasuryInstructionDataEncoder;
exports.getWithdrawTreasuryInstructionDataDecoder = getWithdrawTreasuryInstructionDataDecoder;
exports.getWithdrawTreasuryInstructionDataCodec = getWithdrawTreasuryInstructionDataCodec;
exports.getWithdrawTreasuryInstruction = getWithdrawTreasuryInstruction;
exports.parseWithdrawTreasuryInstruction = parseWithdrawTreasuryInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.WITHDRAW_TREASURY_DISCRIMINATOR = new Uint8Array([
40, 63, 122, 158, 144, 216, 83, 96,
]);
function getWithdrawTreasuryDiscriminatorBytes() {
return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.WITHDRAW_TREASURY_DISCRIMINATOR);
}
function getWithdrawTreasuryInstructionDataEncoder() {
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.WITHDRAW_TREASURY_DISCRIMINATOR }));
}
function getWithdrawTreasuryInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([
["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
["amount", (0, kit_1.getU64Decoder)()],
]);
}
function getWithdrawTreasuryInstructionDataCodec() {
return (0, kit_1.combineCodec)(getWithdrawTreasuryInstructionDataEncoder(), getWithdrawTreasuryInstructionDataDecoder());
}
function getWithdrawTreasuryInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.FARMS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
globalAdmin: { value: input.globalAdmin ?? null, isWritable: true },
globalConfig: { value: input.globalConfig ?? null, isWritable: false },
rewardMint: { value: input.rewardMint ?? null, isWritable: false },
rewardTreasuryVault: {
value: input.rewardTreasuryVault ?? null,
isWritable: true,
},
treasuryVaultAuthority: {
value: input.treasuryVaultAuthority ?? null,
isWritable: false,
},
withdrawDestinationTokenAccount: {
value: input.withdrawDestinationTokenAccount ?? null,
isWritable: true,
},
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.globalAdmin),
getAccountMeta(accounts.globalConfig),
getAccountMeta(accounts.rewardMint),
getAccountMeta(accounts.rewardTreasuryVault),
getAccountMeta(accounts.treasuryVaultAuthority),
getAccountMeta(accounts.withdrawDestinationTokenAccount),
getAccountMeta(accounts.tokenProgram),
],
data: getWithdrawTreasuryInstructionDataEncoder().encode(args),
programAddress,
});
}
function parseWithdrawTreasuryInstruction(instruction) {
if (instruction.accounts.length < 7) {
// 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: {
globalAdmin: getNextAccount(),
globalConfig: getNextAccount(),
rewardMint: getNextAccount(),
rewardTreasuryVault: getNextAccount(),
treasuryVaultAuthority: getNextAccount(),
withdrawDestinationTokenAccount: getNextAccount(),
tokenProgram: getNextAccount(),
},
data: getWithdrawTreasuryInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=withdrawTreasury.js.map