UNPKG

@hubbleprotocol/farms-sdk

Version:
64 lines 3.65 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.withdrawFarmRewardCommand = withdrawFarmRewardCommand; const web3_js_1 = require("@solana/web3.js"); const decimal_js_1 = __importDefault(require("decimal.js")); const Farms_1 = require("../Farms"); const accounts_1 = require("../rpc_client/accounts"); const utils_1 = require("../utils"); const utils_2 = require("./utils"); const refresh_all_klend_user_obligation_farms_from_file_1 = require("./refresh_all_klend_user_obligation_farms_from_file"); const microLamport = 5 * Math.pow(10, 6); // 1 lamport const computeUnits = 1000000; const microLamportsPrioritizationFee = microLamport / computeUnits; function withdrawFarmRewardCommand(farm, rewardMint, amount, mode, priorityFeeMultiplier) { return __awaiter(this, void 0, void 0, function* () { const admin = process.env.ADMIN; const rpc = process.env.RPC; const env = (0, utils_2.initializeClient)(rpc, admin, (0, utils_1.getFarmsProgramId)(rpc), false); const farmsClient = new Farms_1.Farms(env.provider.connection); const farmPubkey = new web3_js_1.PublicKey(farm); const farmState = yield accounts_1.FarmState.fetch(env.provider.connection, farmPubkey); const rewardMintPubkey = new web3_js_1.PublicKey(rewardMint); const amountToWithdraw = new decimal_js_1.default(amount); if (!farmState) { throw new Error("Farm not found"); } const withdrawIxn = yield farmsClient.withdrawRewardAmountFromFarmIx(env.initialOwner.publicKey, farmPubkey, rewardMintPubkey, amountToWithdraw); // 5. Send or print txn const { blockhash } = yield env.provider.connection.getLatestBlockhash(); let txn = new web3_js_1.Transaction(); txn.recentBlockhash = blockhash; txn.feePayer = env.initialOwner.publicKey; if (mode !== "multisig") { const priorityFeeIxn = (0, utils_2.createAddExtraComputeUnitFeeTransaction)(computeUnits, microLamportsPrioritizationFee * priorityFeeMultiplier); txn.add(...priorityFeeIxn); } txn.add(withdrawIxn); if (mode === "simulate") { yield (0, Farms_1.printSimulateTx)(env.provider.connection, txn); } else if (mode === "multisig") { yield (0, Farms_1.printMultisigTx)(txn); } else if (mode === "execute") { console.log("Sending."); const sig = yield (0, refresh_all_klend_user_obligation_farms_from_file_1.sendAndConfirmTransactionV0)(env.provider.connection, env.initialOwner, txn.instructions, [], [env.initialOwner]); console.log("Farm", farmPubkey.toString()); console.log("Signature", sig); } }); } //# sourceMappingURL=withdraw_farm_reward_command.js.map