"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFarmIncentivesForClient = getFarmIncentivesForClient;
exports.getFarmIncentivesWithExistentStateForClient = getFarmIncentivesWithExistentStateForClient;
exports.getReserveFarmRewardsAPY = getReserveFarmRewardsAPY;
const farms_sdk_1 = require("@kamino-finance/farms-sdk");
const lib_1 = require("../lib");
function toFarmsClient(farmsClient) {
    return new farms_sdk_1.Farms(farmsClient.getConnection(), farmsClient.getProgramID());
}
async function getFarmIncentivesForClient(farmsClient, farm, stakedTokenPrice, stakedTokenMintDecimals, pricesMap) {
    return (0, farms_sdk_1.getFarmIncentives)(toFarmsClient(farmsClient), farm, stakedTokenPrice, stakedTokenMintDecimals, pricesMap);
}
async function getFarmIncentivesWithExistentStateForClient(farmsClient, farm, farmState, stakedTokenPrice, stakedTokenMintDecimals, pricesMap) {
    return (0, farms_sdk_1.getFarmIncentivesWithExistentState)(toFarmsClient(farmsClient), farm, farmState, stakedTokenPrice, stakedTokenMintDecimals, pricesMap);
}
async function getReserveFarmRewardsAPY(rpc, recentSlotDurationMs, reserve, reserveLiquidityTokenPrice, farmsClient, slot, reserveState, tokensPrices) {
    const reserveIncentives = {
        collateralFarmIncentives: {
            incentivesStats: [],
            totalIncentivesApy: 0,
        },
        debtFarmIncentives: {
            incentivesStats: [],
            totalIncentivesApy: 0,
        },
    };
    const kaminoReserve = await lib_1.KaminoReserve.initializeFromAddress(reserve, rpc, recentSlotDurationMs, reserveState);
    const farmCollateral = kaminoReserve.state.farmCollateral;
    const farmDebt = kaminoReserve.state.farmDebt;
    const stakedTokenMintDecimals = kaminoReserve.getMintDecimals();
    const reserveCtokenPrice = reserveLiquidityTokenPrice.div(kaminoReserve.getEstimatedCollateralExchangeRate(slot, 0));
    if (farmCollateral !== farms_sdk_1.DEFAULT_PUBLIC_KEY) {
        const farmIncentivesCollateral = await getFarmIncentivesForClient(farmsClient, farmCollateral, reserveCtokenPrice, stakedTokenMintDecimals, tokensPrices);
        reserveIncentives.collateralFarmIncentives = farmIncentivesCollateral;
    }
    if (farmDebt !== farms_sdk_1.DEFAULT_PUBLIC_KEY) {
        const farmIncentivesDebt = await getFarmIncentivesForClient(farmsClient, farmDebt, reserveLiquidityTokenPrice, stakedTokenMintDecimals, tokensPrices);
        reserveIncentives.debtFarmIncentives = farmIncentivesDebt;
    }
    return reserveIncentives;
}
//# sourceMappingURL=farmUtils.js.map