@hubbleprotocol/farms-sdk
Version:
353 lines • 23 kB
JavaScript
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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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 });
const anchor = __importStar(require("@coral-xyz/anchor"));
const commander_1 = require("commander");
const market_1 = require("@project-serum/serum/lib/market");
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 BaseMintOptions = ["base-mint", "base-mint-file", "init-base-mint"];
function main() {
return __awaiter(this, void 0, void 0, function* () {
const commands = new commander_1.Command();
commands
.name("farms-cli")
.description("CLI to interact with the farms program");
commands.command("init-global-config").action(() => __awaiter(this, void 0, void 0, function* () {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ updateMode, flagValueType, flagValue, priorityFeeMultiplier, mode, }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ globalConfig, priorityFeeMultiplier, mode }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ tokenMint, priorityFeeMultiplier, mode }) {
yield (0, init_farm_1.initFarm)(tokenMint, 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((_a) => __awaiter(this, [_a], void 0, function* ({ farm, rewardMint, priorityFeeMultiplier, mode }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ farm, rewardMint, updateMode, value, priorityFeeMultiplier, mode, }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ farm, priorityFeeMultiplier, mode }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ farm, user, rewardMint }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ farm }) {
yield (0, refresh_farm_1.refreshFarmCommand)(farm);
}));
commands
.command("refresh-all-users")
.description("Refresh all users for given farm")
.option("--farm <string>")
.action((_a) => __awaiter(this, [_a], void 0, function* ({ farm }) {
yield (0, refresh_all_users_1.refreshAllUsersCommand)(farm);
}));
commands
.command("refresh-klend-farms")
.option(`--reserve <string>`)
.action((_a) => __awaiter(this, [_a], void 0, function* ({ reserve }) {
yield (0, refresh_klend_farm_1.refreshKlendFarmsCommand)(reserve);
}));
commands
.command("refresh-all-klend-users")
.option(`--reserve <string>`)
.action((_a) => __awaiter(this, [_a], void 0, function* ({ reserve }) {
yield (0, refresh_all_klend_users_1.refreshAllKlendUsersCommand)(reserve);
}));
commands
.command("download-all-user-obligations-for-reserve")
.option(`--market <string>`)
.option(`--reserve <string>`)
.action((_a) => __awaiter(this, [_a], void 0, function* ({ market, reserve }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ market, file }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ market, file }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ reserve, user, rewardMint }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ farm, rewardMint, amount, priorityFeeMultiplier, mode }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ 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 = yield 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(() => __awaiter(this, void 0, void 0, function* () {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ file, pendingAdmin, priorityFeeMultiplier, mode }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ file, priorityFeeMultiplier, mode }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ targetPath }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ targetPath, priorityFeeMultiplier, mode }) {
yield (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((_a) => __awaiter(this, [_a], void 0, function* ({ reserve, kind, multisigToExecute, pendingAdmin, priorityFeeMultiplier, mode, }) {
yield (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("create-mint")
.option(`--admin <string>`, "The admin keypair file")
.option(`--cluster <string>`, "The Solana cluster to use")
.action((_a) => __awaiter(this, [_a], void 0, function* ({ admin, cluster }) {
const env = (0, utils_3.initializeClient)(cluster, admin, (0, utils_2.getFarmsProgramId)(cluster), false);
const tokenMint = new anchor.web3.Keypair();
yield (0, utils_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((_a) => __awaiter(this, [_a], void 0, function* ({ 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 = yield (0, utils_2.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((_a) => __awaiter(this, [_a], void 0, function* ({ 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 = yield (0, utils_1.getAssociatedTokenAddress)(env.initialOwner.publicKey, tokenMint, spl_token_1.TOKEN_PROGRAM_ID);
const mintDecimals = yield (0, market_1.getMintDecimals)(env.provider.connection, tokenMint);
const amountLamports = (0, utils_1.collToLamportsDecimal)(new decimal_js_1.default(amount), mintDecimals);
yield (0, utils_2.mintTo)(env.provider, tokenMint, adminAta, amountLamports.toNumber());
console.log("success");
}));
yield 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
;