@kamino-finance/farms-sdk
Version:
36 lines • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.refreshAllUsersCommand = refreshAllUsersCommand;
const klend_sdk_1 = require("@kamino-finance/klend-sdk");
const web3_js_1 = require("@solana/web3.js");
const Farms_1 = require("../Farms");
const accounts_1 = require("../rpc_client/accounts");
const utils_1 = require("./utils");
const utils_2 = require("../utils");
async function refreshAllUsersCommand(farm) {
const admin = process.env.ADMIN;
const rpc = process.env.RPC;
const env = (0, utils_1.initializeClient)(rpc, admin, (0, utils_2.getFarmsProgramId)(rpc), false);
const farmsClient = new Farms_1.Farms(env.provider.connection);
const allUserFarms = await farmsClient.getAllUserStatesForFarm(new web3_js_1.PublicKey(farm));
const farmState = await accounts_1.FarmState.fetch(env.provider.connection, new web3_js_1.PublicKey(farm));
if (!farmState) {
throw new Error("Farm not found");
}
let scopePrices = farmState.scopePrices.equals(web3_js_1.PublicKey.default)
? klend_sdk_1.PROGRAM_ID
: farmState.scopePrices;
let ixns = [];
let numIxnsPerTxn = 20;
for (let i = 0; i < allUserFarms.length; i++) {
const ix = await farmsClient.refreshUserIx(allUserFarms[i].key, new web3_js_1.PublicKey(farm), scopePrices);
ixns.push(ix);
if ((i + 1 == allUserFarms.length && ixns.length > 0) ||
(i > 0 && ixns.length % numIxnsPerTxn == 0 && ixns.length > 0)) {
const sig = await farmsClient.executeTransaction(ixns, env.initialOwner, []);
console.log(`${i + 1}/${allUserFarms.length} Refreshed Signature ${sig}`);
ixns = [];
}
}
}
//# sourceMappingURL=refresh_all_users.js.map