UNPKG

@kamino-finance/farms-sdk

Version:
381 lines 22.3 kB
#!/usr/bin/env npx ts-node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const anchor = __importStar(require("@coral-xyz/anchor")); const commander_1 = require("commander"); const decimal_js_1 = __importDefault(require("decimal.js")); const dotenv_1 = __importDefault(require("dotenv")); dotenv_1.default.config({ path: `../.env${process.env.ENV ? "." + process.env.ENV : ""}`, }); const utils_1 = require("./utils/utils"); const web3_js_1 = require("@solana/web3.js"); const Farms_1 = require("./Farms"); const utils_2 = require("./utils"); const utils_3 = require("./commands/utils"); const refresh_farm_1 = require("./commands/refresh_farm"); const refresh_klend_farm_1 = require("./commands/refresh_klend_farm"); const refresh_all_users_1 = require("./commands/refresh_all_users"); const init_global_config_1 = require("./commands/init_global_config"); const update_global_config_1 = require("./commands/update_global_config"); const init_farm_1 = require("./commands/init_farm"); const harvest_user_rewards_1 = require("./commands/harvest_user_rewards"); const update_farm_config_1 = require("./commands/update_farm_config"); const init_reward_1 = require("./commands/init_reward"); const refresh_all_klend_users_1 = require("./commands/refresh_all_klend_users"); const harvest_klend_user_rewards_1 = require("./commands/harvest_klend_user_rewards"); const download_all_klend_user_obligation_farms_1 = require("./commands/download_all_klend_user_obligation_farms"); const update_farm_admin_1 = require("./commands/update_farm_admin"); const update_global_admin_1 = require("./commands/update_global_admin"); const download_all_farm_states_1 = require("./commands/download_all_farm_states"); const update_all_farms_pending_admins_from_file_1 = require("./commands/update_all_farms_pending_admins_from_file"); const update_all_farms_admins_from_file_1 = require("./commands/update_all_farms_admins_from_file"); const init_klend_farm_1 = require("./commands/init_klend_farm"); const init_all_klend_user_obligation_farms_from_file_1 = require("./commands/init_all_klend_user_obligation_farms_from_file"); const refresh_all_klend_user_obligation_farms_from_file_1 = require("./commands/refresh_all_klend_user_obligation_farms_from_file"); const withdraw_farm_reward_command_1 = require("./commands/withdraw_farm_reward_command"); const download_all_farm_configs_1 = require("./commands/download_all_farm_configs"); const upsert_all_farm_configs_1 = require("./commands/upsert_all_farm_configs"); const spl_token_1 = require("@solana/spl-token"); const example_update_rps_and_top_up_1 = require("./commands/example_update_rps_and_top_up"); const init_farm_delegated_1 = require("./commands/init_farm_delegated"); const token_1 = require("./utils/token"); const BaseMintOptions = ["base-mint", "base-mint-file", "init-base-mint"]; async function main() { const commands = new commander_1.Command(); commands .name("farms-cli") .description("CLI to interact with the farms program"); commands.command("init-global-config").action(async () => { await (0, init_global_config_1.initGlobalConfigCommand)(); }); commands .command("update-global-config") .option("--update-mode <string>") .option("--flag-value-type <string>", "number|bool|publicKey") .option("--flag-value <string>") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .option("--mode <string>", "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation") .action(async ({ updateMode, flagValueType, flagValue, priorityFeeMultiplier, mode, }) => { await (0, update_global_config_1.updateGlobalConfigCommand)(updateMode, flagValueType, flagValue, mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("update-global-config-admin") .option("--global-config <string>", "global-config pubkey - overrides .env file value") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .option("--mode <string>", "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation") .action(async ({ globalConfig, priorityFeeMultiplier, mode }) => { await (0, update_global_admin_1.updateGlobalConfigAdminCommand)(globalConfig ? new web3_js_1.PublicKey(globalConfig) : web3_js_1.PublicKey.default, mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("init-farm") .option("--token-mint, <string>", "Token mint for farm token") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .option("--mode <string>", "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation") .action(async ({ tokenMint, priorityFeeMultiplier, mode }) => { await (0, init_farm_1.initFarm)(tokenMint, mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("init-farm-delegated") .option("--delegated-authority-path, <string>", "the delegated farm admin") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .option("--mode <string>", "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation") .action(async ({ delegatedAuthorityPath, priorityFeeMultiplier, mode }) => { const delegatedAuthorityKeyPair = (0, utils_2.parseKeypairFile)(delegatedAuthorityPath); await (0, init_farm_delegated_1.initFarmDelegated)(delegatedAuthorityKeyPair, mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("init-reward") .description("Add a new reward for an existing farm") .option("--farm, <string>") .option("--reward-mint, <string>", "Token mint for farm token") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .option("--mode <string>", "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation") .action(async ({ farm, rewardMint, priorityFeeMultiplier, mode }) => { await (0, init_reward_1.initRewardCommand)(farm, rewardMint, mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("update-farm-config") .description("Update config of an existing reward for an existing farm") .option("--farm, <string>") .option("--reward-mint, <string>") .option("--update-mode <string>", "The mode name") .option("--value <string>") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .option("--mode <string>", "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation, execute - will execute") .action(async ({ farm, rewardMint, updateMode, value, priorityFeeMultiplier, mode, }) => { await (0, update_farm_config_1.updateFarmConfigCommand)(farm, rewardMint, updateMode, value, mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("update-farm-admin") .description("Update admin of an existing farm by signing with the pending_admin") .option("--farm, <string>") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .option("--mode <string>", "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation, execute - will execute") .action(async ({ farm, priorityFeeMultiplier, mode }) => { await (0, update_farm_admin_1.updateFarmAdminCommand)(farm, mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("harvest-user-rewards") .description("Simulate the txn to harvest rewards for a user") .option("--farm, <string>") .option("--user, <string>") .option("--reward-mint, <string>") .action(async ({ farm, user, rewardMint }) => { await (0, harvest_user_rewards_1.harvestUserRewardsCommand)(farm, user, rewardMint); }); commands .command("refresh-farm") .description("Top up reward tokens to vault of existing reward") .option(`--farm <string>`, "The admin keypair file") .action(async ({ farm }) => { await (0, refresh_farm_1.refreshFarmCommand)(farm); }); commands .command("refresh-all-users") .description("Refresh all users for given farm") .option("--farm <string>") .action(async ({ farm }) => { await (0, refresh_all_users_1.refreshAllUsersCommand)(farm); }); commands .command("refresh-klend-farms") .option(`--reserve <string>`) .action(async ({ reserve }) => { await (0, refresh_klend_farm_1.refreshKlendFarmsCommand)(reserve); }); commands .command("refresh-all-klend-users") .option(`--reserve <string>`) .action(async ({ reserve }) => { await (0, refresh_all_klend_users_1.refreshAllKlendUsersCommand)(reserve); }); commands .command("download-all-user-obligations-for-reserve") .option(`--market <string>`) .option(`--reserve <string>`) .action(async ({ market, reserve }) => { await (0, download_all_klend_user_obligation_farms_1.downloadAllUserObligationsForReserve)(market, reserve); }); commands .command("init-all-klend-user-obligation-farms-from-file") .option(`--market <string>`) .option(`--file <string>`) .action(async ({ market, file }) => { await (0, init_all_klend_user_obligation_farms_from_file_1.initAllKlendUserObligationFarmsFromFileCommand)(market, file); }); commands .command("refresh-all-klend-obligation-farms-from-file") .option(`--market <string>`) .option(`--file <string>`) .action(async ({ market, file }) => { await (0, refresh_all_klend_user_obligation_farms_from_file_1.refreshAllKlendObligationFarmsFromFileCommand)(market, file); }); commands .command("harvest-klend-user-rewards") .description("Simulate the txn to harvest rewards for a user") .option("--reserve, <string>") .option("--user, <string>") .option("--reward-mint, <string>") .action(async ({ reserve, user, rewardMint }) => { await (0, harvest_klend_user_rewards_1.harvestKlendUserRewardsCommand)(reserve, user, rewardMint); }); commands .command("withdraw-farm-reward") .description("Simulate the txn to harvest rewards for a user") .option("--farm, <string>") .option("--reward-mint, <string>") .option("--amount, <string>") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .option("--mode <string>", "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation, execute - will execute") .action(async ({ farm, rewardMint, amount, priorityFeeMultiplier, mode }) => { await (0, withdraw_farm_reward_command_1.withdrawFarmRewardCommand)(farm, rewardMint, amount, mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("top-up-reward") .description("Top up reward tokens to vault of existing reward") .option(`--admin <string>`, "The admin keypair file") .option(`--rpc <string>`, "The Solana cluster to use") .option("--farm, <string>") .option("--reward-mint, <string>", "Mint for desired reward token") .option("--amount <number>", "Amount of reward tokens to add to vault") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .option("--mode <string>", "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation, execute - will execute") .action(async ({ admin, rpc, farm, rewardMint, amount, priorityFeeMultiplier, mode, }) => { const env = (0, utils_3.initializeClient)(rpc, admin, (0, utils_2.getFarmsProgramId)(rpc), mode === "multisig"); const farmsClient = new Farms_1.Farms(env.provider.connection); const sig = await farmsClient.addRewardAmountToFarm(env.initialOwner, new web3_js_1.PublicKey(farm), new web3_js_1.PublicKey(rewardMint), new decimal_js_1.default(amount), mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); mode !== "multisig" && console.log("Signature", sig); }); commands .command("download-all-farm-state-keys-and-admins") .action(async () => { await (0, download_all_farm_states_1.downloadAllFarmStates)(); }); commands .command("update-all-farms-pending-admins-from-file") .requiredOption(`--file <string>`, "The file with list of farms and current admin") .requiredOption(`--pending-admin <string>`, "The pending admin to be set") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .requiredOption(`--mode <string>`, "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation, execute - will execute") .action(async ({ file, pendingAdmin, priorityFeeMultiplier, mode }) => { await (0, update_all_farms_pending_admins_from_file_1.updateAllFarmsPendingAdminsFromFile)(file, pendingAdmin, mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("update-all-farms-admins-from-file") .requiredOption(`--file <string>`, "The file with list of farms and current admin") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .requiredOption(`--mode <string>`, "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation, execute - will execute") .action(async ({ file, priorityFeeMultiplier, mode }) => { await (0, update_all_farms_admins_from_file_1.updateAllFarmsAdminsFromFile)(file, mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("download-all-farm-configs") .requiredOption(`--target-path <string>`, "The path to download the farms to") .action(async ({ targetPath }) => { await (0, download_all_farm_configs_1.downloadAllFarmConfigs)(targetPath); }); commands .command("upsert-all-farm-configs") .requiredOption(`--target-path <string>`, "The path to download the farms to") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .requiredOption(`--mode <string>`, "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation, execute - will execute") .action(async ({ targetPath, priorityFeeMultiplier, mode }) => { await (0, upsert_all_farm_configs_1.upsertAllFarmConfigsCommand)(targetPath, mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("init-klend-farm") .requiredOption(`--reserve <string>`, "The reserve to create the farm for") .requiredOption(`--kind <string>`, "The kind of farm - Collateral | Debt") .requiredOption(`--multisig-to-execute <string>`, "The multisig used to execute the transaction - should be LendingMarket admin") .requiredOption(`--pending-admin <string>`, "The pending admin to be set in order to transfer authority on creation - usually farms multisig") .option("--priority-fee-multiplier <string>", "the amount of priority fees to add - (multiply 1 lamport)") .requiredOption(`--mode <string>`, "multisig - will print bs58 txn only, simulate - will print bs64 txn explorer link and simulation, execute - will execute") .action(async ({ reserve, kind, multisigToExecute, pendingAdmin, priorityFeeMultiplier, mode, }) => { await (0, init_klend_farm_1.initializeKlendFarmForReserve)(new web3_js_1.PublicKey(reserve), kind, new web3_js_1.PublicKey(multisigToExecute), new web3_js_1.PublicKey(pendingAdmin), mode, priorityFeeMultiplier ? new decimal_js_1.default(priorityFeeMultiplier).toNumber() : 1); }); commands .command("update-farm-rps-for-reward") .requiredOption(`--farm <string>`, "The farm") .requiredOption(`--reward <string>`, "The reward mint") .requiredOption(`--rps <string>`, "The rewards per second to set") .action(async ({ farm, reward, rps }) => { await (0, example_update_rps_and_top_up_1.updateFarmRpsForRewardCommand)(new web3_js_1.PublicKey(reward), new web3_js_1.PublicKey(farm), parseInt(rps)); }); commands .command("top-up-farm-for-reward") .requiredOption(`--farm <string>`, "The farm") .requiredOption(`--reward <string>`, "The reward mint") .requiredOption(`--amount <string>`, "The amount to top up") .action(async ({ farm, reward, amount }) => { await (0, example_update_rps_and_top_up_1.topUpFarmForRewardForStrategy)(new web3_js_1.PublicKey(reward), new web3_js_1.PublicKey(farm), new decimal_js_1.default(amount)); }); commands .command("create-mint") .option(`--admin <string>`, "The admin keypair file") .option(`--cluster <string>`, "The Solana cluster to use") .action(async ({ admin, cluster }) => { const env = (0, utils_3.initializeClient)(cluster, admin, (0, utils_2.getFarmsProgramId)(cluster), false); const tokenMint = new anchor.web3.Keypair(); await (0, token_1.createMintFromKeypair)(env.provider, env.initialOwner.publicKey, tokenMint); console.log("new mint: ", tokenMint.publicKey.toString()); }); commands .command("create-ata") .option(`--admin <string>`, "The admin keypair file") .option(`--cluster <string>`, "The Solana cluster to use") .option(`--mint <string>`, "The Mint to use") .action(async ({ admin, cluster, mint }) => { const env = (0, utils_3.initializeClient)(cluster, admin, (0, utils_2.getFarmsProgramId)(cluster), false); const tokenMint = new web3_js_1.PublicKey(mint); const ata = await (0, token_1.setupAta)(env.provider, tokenMint, env.initialOwner); console.log("new ata: ", ata.toString()); }); commands .command("mint-token") .option(`--admin <string>`, "The admin keypair file") .option(`--cluster <string>`, "The Solana cluster to use") .option(`--mint <string>`, "The Mint to use") .option(`--amount <string>`, "The amount to reward") .action(async ({ admin, cluster, mint, amount }) => { const env = (0, utils_3.initializeClient)(cluster, admin, (0, utils_2.getFarmsProgramId)(cluster), false); const tokenMint = new web3_js_1.PublicKey(mint); const adminAta = await (0, token_1.getAssociatedTokenAddress)(env.initialOwner.publicKey, tokenMint, spl_token_1.TOKEN_PROGRAM_ID); const mintDecimals = await (0, token_1.getMintDecimals)(env.provider.connection, tokenMint); const amountLamports = (0, utils_1.collToLamportsDecimal)(new decimal_js_1.default(amount), mintDecimals); await (0, token_1.mintTo)(env.provider, tokenMint, adminAta, amountLamports.toNumber()); console.log("success"); }); await commands.parseAsync(); } main() .then(() => { process.exit(); }) .catch((e) => { console.error("\n\nFarms CLI exited with error:\n\n", e); process.exit(1); }); //# sourceMappingURL=client.js.map