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());
    });
};
import { getContract, getContractAddressAndAbiByContractName, viewContract, triggerContract, } from "../../../utils/ethers/contractHelper";
import { viewContractByContractName } from "../../../utils/ethers/contractHelper";
/**
 * Get staker contract address by staking token
 * @param landId Land Id
 * @param provider Provider
 * @param stakingToken Staking token contract address
 * @param callback Callback
 * @returns any
 */
export const farmGetStakerAddress = (landId, provider, stakingToken, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const result = yield viewContractByContractName(landId, provider, "liquidityStakerFactory", "stakingRewardsInfoByStakingToken", [stakingToken], callback);
    return result.toString();
});
/**
 * Get the amount of staking token
 * @param landId Land Id
 * @param provider Provider
 * @param stakerContractAddress Contract address of staker
 * @param callback Callback
 * @returns any
 */
export const farmGetStakerTotalSupply = (landId, provider, stakerContractAddress, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const liquidityStaker = getContractAddressAndAbiByContractName(landId, provider, "liquidityStaker");
    if (!liquidityStaker.interface)
        return "0";
    const contract = yield getContract(provider, stakerContractAddress, liquidityStaker.interface);
    const result = yield viewContract(contract, "totalSupply", [], callback);
    return result.toString();
});
/**
 * Get the amount of staking token for a specific address
 * @param landId Land Id
 * @param provider Provider
 * @param stakerContractAddress Contract address of staker
 * @param account Address
 * @param callback Callback
 * @returns any
 */
export const farmGetStakerBalanceOf = (landId, provider, stakerContractAddress, account, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const liquidityStaker = getContractAddressAndAbiByContractName(landId, provider, "liquidityStaker");
    if (!liquidityStaker.interface)
        return "0";
    const contract = yield getContract(provider, stakerContractAddress, liquidityStaker.interface);
    const result = yield viewContract(contract, "balanceOf", [account], callback);
    return result.toString();
});
/**
 * Get the amount of token already earned
 * @param landId Land Id
 * @param provider Provider
 * @param stakerContractAddress Contract address of staker
 * @param account Address
 * @param callback Callback
 * @returns any
 */
export const farmGetStakerEarned = (landId, provider, stakerContractAddress, account, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const liquidityStaker = getContractAddressAndAbiByContractName(landId, provider, "liquidityStaker");
    if (!liquidityStaker.interface)
        return "0";
    const contract = yield getContract(provider, stakerContractAddress, liquidityStaker.interface);
    const result = yield viewContract(contract, "earned", [account], callback);
    return result.toString();
});
/**
 * Stake token to staker contract
 * @param landId Land Id
 * @param signer Signer
 * @param stakerContractAddress Staker contract address
 * @param amount Stake amount
 * @param callback Callback
 * @returns any
 */
export const farmGetStakerStakeToken = (landId, signer, stakerContractAddress, amount, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const liquidityStaker = getContractAddressAndAbiByContractName(landId, signer, "liquidityStaker");
    const contract = yield getContract(signer, stakerContractAddress, liquidityStaker.interface);
    const tx = yield triggerContract(contract, "stake", [amount], callback);
    return tx;
});
/**
 * Withdraw token from staker contract
 * @param landId Land Id
 * @param signer Signer
 * @param stakerContractAddress Staker contract address
 * @param amount Withdraw amount
 * @param callback Callback
 * @returns any
 */
export const farmStakerWithdraw = (landId, signer, stakerContractAddress, amount, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const liquidityStaker = getContractAddressAndAbiByContractName(landId, signer, "liquidityStaker");
    const contract = yield getContract(signer, stakerContractAddress, liquidityStaker.interface);
    const tx = yield triggerContract(contract, "withdraw", [amount], callback);
    return tx;
});
/**
 * Claim reward
 * @param landId Land Id
 * @param signer Signer
 * @param stakerContractAddress Staker contract address
 * @param callback Callback
 * @returns any
 */
export const farmGetStakerGetReward = (landId, signer, stakerContractAddress, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const liquidityStaker = getContractAddressAndAbiByContractName(landId, signer, "liquidityStaker");
    const contract = yield getContract(signer, stakerContractAddress, liquidityStaker.interface);
    const tx = yield triggerContract(contract, "getReward", [], callback);
    return tx;
});
/**
 * Exit staker
 * @param landId Land Id
 * @param signer Signer
 * @param stakerContractAddress Staker contract address
 * @param callback Callback
 * @returns any
 */
export const farmGetStakerExit = (landId, signer, stakerContractAddress, callback) => __awaiter(void 0, void 0, void 0, function* () {
    const liquidityStaker = getContractAddressAndAbiByContractName(landId, signer, "liquidityStaker");
    const contract = yield getContract(signer, stakerContractAddress, liquidityStaker.interface);
    const tx = yield triggerContract(contract, "exit", [], callback);
    return tx;
});
