@kamino-finance/farms-sdk
Version:
33 lines • 1.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRewardsApyForStrategy = getRewardsApyForStrategy;
exports.getFarmIncentives = getFarmIncentives;
exports.getFarmIncentivesWithExistentState = getFarmIncentivesWithExistentState;
const kliquidity_sdk_1 = require("@kamino-finance/kliquidity-sdk");
const Farms_1 = require("../Farms");
const accounts_1 = require("../@codegen/farms/accounts");
const price_1 = require("./price");
async function getRewardsApyForStrategy(connection, strategy) {
const kaminoClient = new kliquidity_sdk_1.Kamino("mainnet-beta", connection);
const strategyState = await kaminoClient.getStrategyByAddress(strategy);
if (!strategyState) {
throw new Error(`Strategy state not found for strategy: ${strategy}`);
}
const farm = strategyState.farm;
const stakedTokenMintDecimals = strategyState.sharesMintDecimals.toNumber();
const stakedTokenPrice = await kaminoClient.getStrategySharePrice(strategy);
const farmsClient = new Farms_1.Farms(connection);
console.log(`Farm: ${farm}`);
return await getFarmIncentives(farmsClient, farm, stakedTokenPrice, stakedTokenMintDecimals);
}
async function getFarmIncentives(farmsClient, farm, stakedTokenPrice, stakedTokenMintDecimals, pricesMap) {
const farmAccount = await (0, accounts_1.fetchMaybeFarmState)(farmsClient.getConnection(), farm);
if (!farmAccount.exists) {
throw new Error(`Farm state not found for farm: ${farm}`);
}
return await getFarmIncentivesWithExistentState(farmsClient, farm, farmAccount.data, stakedTokenPrice, stakedTokenMintDecimals, pricesMap);
}
async function getFarmIncentivesWithExistentState(farmsClient, farm, farmState, stakedTokenPrice, stakedTokenMintDecimals, pricesMap) {
return await farmsClient.calculateFarmIncentivesApy({ farmState, key: farm }, price_1.getTokenPrice, stakedTokenPrice, stakedTokenMintDecimals, pricesMap);
}
//# sourceMappingURL=apy.js.map