UNPKG

@kamino-finance/farms-sdk

Version:
119 lines 5.15 kB
"use strict"; /** * 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_REWARD_DISCRIMINATOR = void 0; exports.getWithdrawRewardDiscriminatorBytes = getWithdrawRewardDiscriminatorBytes; exports.getWithdrawRewardInstructionDataEncoder = getWithdrawRewardInstructionDataEncoder; exports.getWithdrawRewardInstructionDataDecoder = getWithdrawRewardInstructionDataDecoder; exports.getWithdrawRewardInstructionDataCodec = getWithdrawRewardInstructionDataCodec; exports.getWithdrawRewardInstruction = getWithdrawRewardInstruction; exports.parseWithdrawRewardInstruction = parseWithdrawRewardInstruction; const kit_1 = require("@solana/kit"); const programs_1 = require("../programs"); const shared_1 = require("../shared"); exports.WITHDRAW_REWARD_DISCRIMINATOR = new Uint8Array([ 191, 187, 176, 137, 9, 25, 187, 244, ]); function getWithdrawRewardDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.WITHDRAW_REWARD_DISCRIMINATOR); } function getWithdrawRewardInstructionDataEncoder() { return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([ ["discriminator", (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ["amount", (0, kit_1.getU64Encoder)()], ["rewardIndex", (0, kit_1.getU64Encoder)()], ]), (value) => ({ ...value, discriminator: exports.WITHDRAW_REWARD_DISCRIMINATOR })); } function getWithdrawRewardInstructionDataDecoder() { return (0, kit_1.getStructDecoder)([ ["discriminator", (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ["amount", (0, kit_1.getU64Decoder)()], ["rewardIndex", (0, kit_1.getU64Decoder)()], ]); } function getWithdrawRewardInstructionDataCodec() { return (0, kit_1.combineCodec)(getWithdrawRewardInstructionDataEncoder(), getWithdrawRewardInstructionDataDecoder()); } function getWithdrawRewardInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? programs_1.FARMS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { farmAdmin: { value: input.farmAdmin ?? null, isWritable: true }, farmState: { value: input.farmState ?? null, isWritable: true }, rewardMint: { value: input.rewardMint ?? null, isWritable: false }, rewardVault: { value: input.rewardVault ?? null, isWritable: true }, farmVaultsAuthority: { value: input.farmVaultsAuthority ?? null, isWritable: false, }, adminRewardTokenAta: { value: input.adminRewardTokenAta ?? null, isWritable: true, }, 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.farmAdmin), getAccountMeta(accounts.farmState), getAccountMeta(accounts.rewardMint), getAccountMeta(accounts.rewardVault), getAccountMeta(accounts.farmVaultsAuthority), getAccountMeta(accounts.adminRewardTokenAta), getAccountMeta(accounts.scopePrices), getAccountMeta(accounts.tokenProgram), ], data: getWithdrawRewardInstructionDataEncoder().encode(args), programAddress, }); } function parseWithdrawRewardInstruction(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: { farmAdmin: getNextAccount(), farmState: getNextAccount(), rewardMint: getNextAccount(), rewardVault: getNextAccount(), farmVaultsAuthority: getNextAccount(), adminRewardTokenAta: getNextAccount(), scopePrices: getNextOptionalAccount(), tokenProgram: getNextAccount(), }, data: getWithdrawRewardInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=withdrawReward.js.map