# lottery/v1.ts

    import { ethers } from "ethers";
    import type { CallbackType } from "@evo/utils/ethers/contractHelper";
    import {
      triggerContractByContractName,
      viewContractByContractName,
      getContractAddressAndAbiByContractName,
    } from "@evo/utils/ethers/contractHelper";
    import { LandId } from "@evo/config/constants";
    import { TransactionResponse } from "@ethersproject/providers";

    /**
     * Get points balance from account.
     * @param landId Land Id
     * @param provider Provider
     * @param account Address
     * @param callback Callback
     * @returns any
     */
    export const lotteryGetPointsBalance = async (
      landId: LandId,
      provider: ethers.providers.Provider,
      account: string,
      callback?: CallbackType
    ): Promise<string> => {
      const results = await viewContractByContractName(
        landId,
        provider,
        "userPoints",
        "pointsBalanceOf",
        [account],
        callback
      );
      return results.length ? (results[0] as ethers.BigNumber).toHexString() : ethers.utils.hexValue(0);
    };

    /**
     * Json lottery.
     * @param landId Land Id
     * @param signer Signer
     * @param type s for small, l for larget
     * @param callback
     * @returns any
     */
    export const lotteryPlayWithTicket = (
      landId: LandId,
      signer: ethers.Signer,
      type: "s" | "l",
      callback?: CallbackType
    ): Promise<TransactionResponse> => {
      const methodName = type === "s" ? "playWithSmallTicket" : "playWithLargeTicket";
      return triggerContractByContractName(landId, signer, "lottery", methodName, [], callback, {
        gasLimit: ethers.BigNumber.from(500000),
      });
    };

    /**
     * Get reward balance in pool.
     * @param landId Land Id
     * @param provider Provider
     * @param callback Callback
     * @returns any
     */
    export const lotteryGetTotalRewardInPool = async (
      landId: LandId,
      provider: ethers.providers.Provider,
      callback?: CallbackType
    ): Promise<string> => {
      const ring = getContractAddressAndAbiByContractName(landId, provider, "ring");

      const results = await viewContractByContractName(
        landId,
        provider,
        "lottery",
        "totalRewardInPool",
        [ring.address],
        callback
      );
      return results.length ? (results[0] as ethers.BigNumber).toHexString() : ethers.utils.hexValue(0);
    };