kohin-js
Version:
The Kohin JS is a comprehensive developer toolkit designed to integrate Kohin's decentralized insurance system seamlessly into your applications. It enables efficient interaction with Kohin smart contracts and backend APIs, facilitating management and ana
831 lines (830 loc) • 33.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Kohin = exports.BetCategory = void 0;
const ApiCall_1 = require("../client/ApiCall");
const commonFunctions_1 = require("../config/commonFunctions");
const errorHandlerUtils_1 = require("../config/errorHandlerUtils");
const serverConstants_1 = require("../config/serverConstants");
const abis_1 = require("../abis");
const mlrFunctions_1 = require("../config/mlrFunctions");
const ActiveBetTypes_1 = require("../types/ActiveBetTypes");
const apiEndPoints_1 = require("../config/apiEndPoints");
const configStore_1 = require("../config/configStore");
const constantVariables_1 = require("../config/constantVariables");
/**
* The `Kohin` class acts as a centralized API service that manages
* different functionalities such as fetching odd history, active bets,
* and bet details.
*/
var BetCategory;
(function (BetCategory) {
BetCategory[BetCategory["Single"] = 0] = "Single";
BetCategory[BetCategory["Combo"] = 1] = "Combo";
})(BetCategory || (exports.BetCategory = BetCategory = {}));
class Kohin {
constructor(params) {
this.debounceTimer = null;
const { accessKey, secretKey, rpcUrl, envMode, affiliateAddress } = params; // Destructure the params
configStore_1.configStore.setEnvMode(envMode); // Set the environment mode
this.accessKey = accessKey;
this.secretKey = secretKey;
if (rpcUrl) {
const parseUrl = (0, commonFunctions_1.parseString)(rpcUrl);
configStore_1.configStore.setRpcUrl(parseUrl);
}
this.apiCall = new ApiCall_1.ApiCall(this.accessKey, this.secretKey);
this.POLYGON_CHAIN = serverConstants_1.CONSTANTS[envMode].POLYGON_CHAIN;
const parseAffiliateAddress = (0, commonFunctions_1.parseString)(affiliateAddress);
const affiliateAddressValidations = (0, errorHandlerUtils_1.validateAffiliateAddress)(parseAffiliateAddress);
if (!affiliateAddressValidations.success) {
throw affiliateAddressValidations;
}
this.affiliateAddress = parseAffiliateAddress;
}
async getActiveBetData(params) {
try {
const response = await this.apiCall.getData(apiEndPoints_1.API_ENDPOINTS.GET_ACTIVE_BETS, params);
return response;
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getBetsStatusData(params) {
try {
const { betId, betType } = params;
const convertedBetType = betType === ActiveBetTypes_1.BetTypeEnum.Combo ? "Express" : "Ordinar";
const data = { betId: betId, betType: convertedBetType };
const response = await this.apiCall.postData(apiEndPoints_1.API_ENDPOINTS.GET_BET_STATUS, data);
return response;
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getBetDetails(params) {
try {
const response = await this.apiCall.getData(apiEndPoints_1.API_ENDPOINTS.GET_BET_DETAILS, params);
return response;
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getOddsHistory(params) {
try {
const response = await this.apiCall.getData(apiEndPoints_1.API_ENDPOINTS.ODDS_HISTORY, params);
return response;
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getMySlips(params) {
try {
const response = await this.apiCall.getData(apiEndPoints_1.API_ENDPOINTS.GET_MY_SLIPS, params);
return response;
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getSlipHistory(params) {
try {
const response = await this.apiCall.getData(apiEndPoints_1.API_ENDPOINTS.GET_SLIP_HISTORY, params);
return response;
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getTransactionHistory(params) {
try {
const response = await this.apiCall.getData(apiEndPoints_1.API_ENDPOINTS.GET_TRANSACTION_HISTORY, params);
return response;
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getPoolApr() {
try {
const response = await this.apiCall.getData(apiEndPoints_1.API_ENDPOINTS.GET_POOL_APR);
return response;
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getMyDeposits(params) {
try {
const response = await this.apiCall.getData(apiEndPoints_1.API_ENDPOINTS.GET_MY_DEPOSITS, params);
return response;
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getOppositeOdds(params) {
try {
const response = await this.apiCall.getData(apiEndPoints_1.API_ENDPOINTS.GET_OUTCOME_ODDS, params);
return response;
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
static convertBetType(betType) {
if (typeof betType === "string") {
return betType === ActiveBetTypes_1.BetTypeEnum.Single
? BetCategory.Single
: BetCategory.Combo;
}
return betType;
}
async buyCover(params) {
try {
const { betId, betType, slippagePercent, coverPremium, betAmount, walletClient, } = params;
const slippagePerValue = slippagePercent * constantVariables_1.SLIPPAGE_MULTIPLIER;
const maxSlippagePercent = 100 * constantVariables_1.SLIPPAGE_MULTIPLIER;
const covetStatusRes = await this.hasCoverBooked({ betId, betType });
if (!covetStatusRes.success) {
return covetStatusRes;
}
const isBooked = covetStatusRes?.isBooked || false;
const tokenBalance = await this.getTokenBalance({
walletClient: walletClient,
});
const balance = tokenBalance.balance || BigInt(0);
const validation = (0, errorHandlerUtils_1.validateForBuyCover)(slippagePerValue, maxSlippagePercent, isBooked, coverPremium, balance);
if (!validation.success) {
return validation; // Return the error response from validation
}
const mlrValidations = await (0, mlrFunctions_1.checkMLRBeforeBuyCover)(Number(betAmount));
if (!mlrValidations.success) {
return mlrValidations;
}
const publicClient = (0, commonFunctions_1.getPublicClient)();
const type = Kohin.convertBetType(betType);
// TODO: Remove condition once we deploy single on prod
let args;
if (configStore_1.configStore.getEnvMode() === "prod") {
args = [betId, type, coverPremium, slippagePerValue];
}
else {
args = [
betId,
type,
coverPremium,
slippagePerValue,
this.affiliateAddress,
];
}
const gasEstimateRes = await (0, commonFunctions_1.publicEstimateGasIns)({
functionName: "buyCover",
args: args,
walletClient: walletClient,
});
if (!gasEstimateRes?.success) {
return gasEstimateRes;
}
// Interact with the contract to buy cover
const hash = await walletClient.writeContract({
address: (0, serverConstants_1.getEnvConstant)("INSURANCE_POOL_ADDRESS"),
abi: abis_1.ABIs.InsurancePoolAbi,
functionName: "buyCover",
args: args,
chain: this.POLYGON_CHAIN,
account: walletClient.account,
gas: gasEstimateRes.gas, // Convert gasEstimate to bigint
});
// Wait for the transaction receipt
const transactionReceipt = await publicClient.waitForTransactionReceipt({
hash: hash,
});
return {
success: true,
transactionData: transactionReceipt,
transactionHash: transactionReceipt.transactionHash,
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "buyCover");
}
}
async approveAmount({ amount, walletClient, }) {
try {
const publicClient = (0, commonFunctions_1.getPublicClient)();
const amountInBigInt = (0, commonFunctions_1.convertToBigInt)(amount);
const approvalTx = await walletClient?.writeContract({
address: (0, serverConstants_1.getEnvConstant)("TOKEN_ADDRESS"),
abi: abis_1.ABIs.TokenAbi,
functionName: "approve",
args: [(0, serverConstants_1.getEnvConstant)("INSURANCE_POOL_ADDRESS"), amountInBigInt],
chain: this.POLYGON_CHAIN,
account: walletClient.account,
});
// Wait for the approval transaction to complete
const approvalReceipt = await publicClient.waitForTransactionReceipt({
hash: approvalTx,
});
return {
success: true,
approveHash: approvalTx,
approveData: approvalReceipt,
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async addLiquidity(params) {
try {
const { amount, walletClient } = params;
if (amount < 0 || amount === undefined || isNaN(amount)) {
return {
success: false,
error: "Invalid amount. Please provide a valid number.",
};
}
const publicClient = (0, commonFunctions_1.getPublicClient)();
const maxDepositRes = await this.getMaxDeposit();
if (!maxDepositRes.success) {
return maxDepositRes;
}
const minDepositRes = await this.getMinDeposit();
if (!minDepositRes.success) {
return minDepositRes;
}
const validateRes = (0, errorHandlerUtils_1.validateForAddLiquidity)({
maxDeposit: maxDepositRes.maxDeposit ?? 0,
minDeposit: minDepositRes.minDeposit ?? 0,
amount: amount,
});
if (!validateRes.success) {
return validateRes;
}
const amountBigInt = (0, commonFunctions_1.convertToBigInt)(amount);
const args = [amountBigInt, this.affiliateAddress];
const gasEstimateRes = await (0, commonFunctions_1.publicEstimateGasIns)({
functionName: "addLiquidity",
args: args,
walletClient: walletClient,
});
if (!gasEstimateRes?.success) {
return gasEstimateRes;
}
// Execute addLiquidity
const hash = await walletClient.writeContract({
address: (0, serverConstants_1.getEnvConstant)("INSURANCE_POOL_ADDRESS"),
abi: abis_1.ABIs.InsurancePoolAbi,
functionName: "addLiquidity",
args: args,
account: walletClient.account,
chain: this.POLYGON_CHAIN,
gas: gasEstimateRes.gas,
});
const transactionReceipt = await publicClient.waitForTransactionReceipt({
hash: hash,
});
return {
success: true,
transactionData: transactionReceipt,
transactionHash: hash,
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "addLiquidity");
}
}
async getSingleBetInsurancePremium(params) {
try {
// TODO: Remove condition once we deploy single on prod
if (configStore_1.configStore.getEnvMode() === "prod") {
return {
success: false,
error: "Oops! Single bets aren't allowed in production. Please try a different combo bet.",
};
}
const { betAmount, betType, conditionId, outcomeId } = params;
const validateIdRes = (0, errorHandlerUtils_1.validateConditionIdAndOutcomeId)({
conditionId: conditionId || "",
outcomeId: outcomeId || "",
});
if (!validateIdRes.success) {
return validateIdRes;
}
const betLimitsRes = await this.getBetLimits({ betType: betType });
if (!betLimitsRes.success) {
return betLimitsRes;
}
const oppositeOddsRes = await this.getOppositeOdds({
conditionId: conditionId || "",
outcomeId: outcomeId || "",
});
if (!oppositeOddsRes.success) {
return oppositeOddsRes;
}
const oppositeOdds = oppositeOddsRes?.data?.oppositeOdds?.map(BigInt);
const selectedOdd = BigInt(oppositeOddsRes?.data?.selectedOdd ?? "0");
const odds = (0, commonFunctions_1.formatNumber)(selectedOdd, constantVariables_1.ODDS_SCALE);
const validation = (0, errorHandlerUtils_1.validateForCalculatePremium)({
odds,
betAmount,
limits: {
minOdds: betLimitsRes.minOdds ?? 0,
maxOdds: betLimitsRes.maxOdds ?? 0,
minAmount: betLimitsRes.minAmount ?? 0,
maxAmount: betLimitsRes.maxAmount ?? 0,
},
betType,
});
if (!validation.success) {
return validation;
}
const stake = (0, commonFunctions_1.convertToBigInt)(betAmount);
const args = [selectedOdd, stake, oppositeOdds];
const result = await (0, commonFunctions_1.publicClientRead)({
functionName: "getInsurancePremium",
args: args,
contractType: commonFunctions_1.ContractType.Single,
});
return {
success: true,
calculatedPremium: result,
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "calculatePremium");
}
}
async getComboBetInsurancePremium(params) {
try {
const { odds, betAmount, betType, numLegs } = params;
const maxSubBetLimitRes = await this.getMaxSubBetLimit();
if (!maxSubBetLimitRes.success) {
return maxSubBetLimitRes;
}
const maxSubBetLimit = maxSubBetLimitRes?.maxSubBetLimit;
const betLimitsRes = await this.getBetLimits({ betType: betType });
if (!betLimitsRes.success) {
return betLimitsRes;
}
const validation = (0, errorHandlerUtils_1.validateForCalculatePremium)({
odds,
betAmount,
limits: {
minOdds: betLimitsRes.minOdds ?? 0,
maxOdds: betLimitsRes.maxOdds ?? 0,
minAmount: betLimitsRes.minAmount ?? 0,
maxAmount: betLimitsRes.maxAmount ?? 0,
},
betType,
numLegs,
maxSubBetLimit,
});
if (!validation.success) {
return validation;
}
const stake = (0, commonFunctions_1.convertToBigInt)(betAmount);
const passingOdds = (0, commonFunctions_1.formattedTotalOdds)(odds);
const args = [passingOdds, numLegs, stake];
let result;
// TODO: Remove else part once we deploy Single Bets Insurance Cover
if (configStore_1.configStore.getEnvMode() === "prod") {
const { abi } = (0, commonFunctions_1.getContractDetails)(commonFunctions_1.ContractType.Combo);
const address = "0x022092Bd0Fb440fea4df787279AF1ffDbbFeE6D0";
const publicClient = (0, commonFunctions_1.getPublicClient)();
result = await publicClient.readContract({
address: address,
abi: abi,
functionName: "getInsurancePremium",
args: args,
});
}
else {
result = await (0, commonFunctions_1.publicClientRead)({
functionName: "getInsurancePremium",
args: args,
contractType: commonFunctions_1.ContractType.Combo,
});
}
return {
success: true,
calculatedPremium: result,
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "calculatePremium");
}
}
async getInsurancePremium(params) {
return new Promise((resolve) => {
if (this.debounceTimer) {
clearTimeout(this.debounceTimer);
}
this.debounceTimer = setTimeout(async () => {
const response = params.betType === ActiveBetTypes_1.BetTypeEnum.Single
? await this.getSingleBetInsurancePremium(params)
: await this.getComboBetInsurancePremium(params);
resolve(response);
}, 1000); // Adjust debounce time
});
}
async calculatePremium(params) {
try {
const { betId, betType, odds, betAmount, numLegs } = params;
const maxSubBetLimitRes = await (betType === ActiveBetTypes_1.BetTypeEnum.Combo
? this.getMaxSubBetLimit()
: Promise.resolve({ success: true, maxSubBetLimit: 1 }));
if (!maxSubBetLimitRes.success) {
return maxSubBetLimitRes;
}
const maxSubBetLimit = maxSubBetLimitRes?.maxSubBetLimit;
const type = Kohin.convertBetType(betType);
const betLimitsRes = await this.getBetLimits({ betType: betType });
if (!betLimitsRes.success) {
return betLimitsRes;
}
const validation = (0, errorHandlerUtils_1.validateForCalculatePremium)({
odds,
betAmount,
limits: {
minOdds: betLimitsRes.minOdds ?? 0,
maxOdds: betLimitsRes.maxOdds ?? 0,
minAmount: betLimitsRes.minAmount ?? 0,
maxAmount: betLimitsRes.maxAmount ?? 0,
},
betType,
numLegs,
maxSubBetLimit,
});
if (!validation.success) {
return validation; // Return the error response from validation
}
// TODO: Remove condition once we deploy single on prod
let result;
if (configStore_1.configStore.getEnvMode() === "prod") {
result = await (0, commonFunctions_1.publicClientRead)({
functionName: "calculateCoverPremium",
args: [betId, type],
contractType: commonFunctions_1.ContractType.InsurancePool,
});
}
else {
result = await (0, commonFunctions_1.publicClientRead)({
functionName: "calculatePremium",
args: [betId, type],
contractType: commonFunctions_1.ContractType.Policy,
});
}
return {
success: true,
calculatedPremium: result[0],
amount: result[1],
odds: result[2],
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "calculatePremium");
}
}
async hasCoverBooked({ betId, betType, }) {
try {
const type = Kohin.convertBetType(betType);
// TODO: Remove condition once we deploy single on prod
let result;
if (configStore_1.configStore.getEnvMode() === "prod") {
result = await (0, commonFunctions_1.publicClientRead)({
functionName: "isBetInsured",
args: [betId],
contractType: commonFunctions_1.ContractType.Policy,
});
}
else {
result = await (0, commonFunctions_1.publicClientRead)({
functionName: "isBetInsured",
args: [betId, type],
contractType: commonFunctions_1.ContractType.Policy,
});
}
return {
success: true,
isBooked: Boolean(result),
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getWithdrawAfter({ depositId }) {
try {
const response = await (0, commonFunctions_1.publicClientRead)({
args: [depositId],
functionName: "getWithdrawAfter",
contractType: commonFunctions_1.ContractType.InsurancePool,
});
return { success: true, withdrawAfter: response };
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getBetLimits({ betType }) {
try {
let response;
// TODO: Remove condition once we deploy single on prod
if (configStore_1.configStore.getEnvMode() === "prod") {
if (betType === "Single") {
return {
success: false,
error: "Oops! Single bets aren't allowed in production. Please try a different combo bet.",
};
}
response = await (0, commonFunctions_1.publicClientRead)({
args: [],
functionName: "comboBetLimits",
contractType: commonFunctions_1.ContractType.Combo,
});
}
else {
response = await (0, commonFunctions_1.publicClientRead)({
args: [],
functionName: "betLimits",
contractType: betType === commonFunctions_1.ContractType.Combo
? commonFunctions_1.ContractType.Combo
: commonFunctions_1.ContractType.Single,
});
}
return {
success: true,
minOdds: (0, commonFunctions_1.formatNumber)(response[0], constantVariables_1.ODDS_SCALE),
maxOdds: (0, commonFunctions_1.formatNumber)(response[1], constantVariables_1.ODDS_SCALE),
minAmount: (0, commonFunctions_1.formatNumber)(response[2], constantVariables_1.USDT_DECIMAL),
maxAmount: (0, commonFunctions_1.formatNumber)(response[3], constantVariables_1.USDT_DECIMAL),
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getMaxSubBetLimit() {
try {
const maxSubBetLimitRes = await (0, commonFunctions_1.publicClientRead)({
args: [],
functionName: "maxSubBetLimit",
contractType: commonFunctions_1.ContractType.Combo,
});
return { success: true, maxSubBetLimit: maxSubBetLimitRes };
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async isEarlyWithdrawalEnabled() {
try {
const response = await (0, commonFunctions_1.publicClientRead)({
args: [],
functionName: "isEarlyWithdrawalEnabled",
contractType: commonFunctions_1.ContractType.InsurancePool,
});
return { success: true, isEarlyWithdrawalEnabled: response };
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async checkMLRBeforeBuyCover({ betAmount }) {
try {
const mlrValidations = await (0, mlrFunctions_1.checkMLRBeforeBuyCover)(Number(betAmount));
return mlrValidations;
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getMinDeposit() {
try {
const response = await (0, commonFunctions_1.publicClientReadIns)({ functionName: "minDepo" });
return {
success: true,
minDeposit: (0, commonFunctions_1.formatNumber)(response, constantVariables_1.USDT_DECIMAL),
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getMaxDeposit() {
try {
const response = await (0, commonFunctions_1.publicClientReadIns)({ functionName: "maxDepo" });
return {
success: true,
maxDeposit: (0, commonFunctions_1.formatNumber)(response, constantVariables_1.USDT_DECIMAL),
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getReserve() {
try {
const response = await (0, commonFunctions_1.publicClientReadIns)({
functionName: "getReserve",
});
return {
success: true,
reserveAmount: (0, commonFunctions_1.formatNumber)(response, constantVariables_1.USDT_DECIMAL),
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getMaxPoolCap() {
try {
const response = await (0, commonFunctions_1.publicClientReadIns)({
functionName: "maxPoolCap",
});
return {
success: true,
maxPoolCap: (0, commonFunctions_1.formatNumber)(response, constantVariables_1.USDT_DECIMAL),
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async earlyWithdrawalFee() {
try {
const response = await (0, commonFunctions_1.publicClientRead)({
args: [],
functionName: "earlyWithdrawalFee",
contractType: commonFunctions_1.ContractType.InsurancePool,
});
return {
success: true,
earlyWithdrawalFee: (0, commonFunctions_1.formatNumber)(response, constantVariables_1.ODDS_SCALE),
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getTokenBalance({ walletClient }) {
try {
const response = await (0, commonFunctions_1.publicClientRead)({
args: [walletClient.account.address],
functionName: "balanceOf",
contractType: commonFunctions_1.ContractType.Token,
});
return { success: true, balance: response };
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getDecimalPrecise() {
try {
const response = await (0, commonFunctions_1.publicClientRead)({
args: [],
functionName: "decimals",
contractType: commonFunctions_1.ContractType.Token,
});
return { success: true, decimalPrecise: response };
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getApprovalAmount({ walletClient }) {
try {
const response = await (0, commonFunctions_1.publicClientRead)({
args: [
walletClient?.account?.address,
(0, serverConstants_1.getEnvConstant)("INSURANCE_POOL_ADDRESS"),
],
functionName: "allowance",
contractType: commonFunctions_1.ContractType.Token,
});
return { success: true, allowance: (0, commonFunctions_1.formatNumber)(response, constantVariables_1.USDT_DECIMAL) };
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async getBalanceOfDeposit({ depositId }) {
try {
const response = await (0, commonFunctions_1.publicClientReadIns)({
args: [depositId],
functionName: "nodeWithdrawView",
});
return {
success: true,
balance: (0, commonFunctions_1.formatNumber)(response, constantVariables_1.USDT_DECIMAL),
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async removeLiquidity(params) {
try {
const { depositId, percent, walletClient } = params;
const finalPercent = percent * constantVariables_1.PERCENTAGE_MULTIPLIER;
const publicClient = (0, commonFunctions_1.getPublicClient)();
const depositRes = await this.getBalanceOfDeposit({
depositId: depositId,
});
const depositBal = depositRes?.balance || 0;
const mlrValidations = await (0, mlrFunctions_1.checkMLRBeforeRemoval)(percent, depositBal);
if (!mlrValidations.success) {
return mlrValidations;
}
const args = [BigInt(depositId), BigInt(finalPercent)];
const gasEstimateRes = await (0, commonFunctions_1.publicEstimateGasIns)({
functionName: "removeLiquidity",
args: args,
walletClient: walletClient,
});
if (!gasEstimateRes?.success) {
return gasEstimateRes;
}
// Execute transaction
const hash = await walletClient.writeContract({
address: (0, serverConstants_1.getEnvConstant)("INSURANCE_POOL_ADDRESS"),
abi: abis_1.ABIs.InsurancePoolAbi,
functionName: "removeLiquidity",
args: [BigInt(depositId), BigInt(finalPercent)],
account: walletClient.account,
chain: this.POLYGON_CHAIN,
gas: gasEstimateRes.gas,
});
const transactionReceipt = await publicClient.waitForTransactionReceipt({
hash,
});
return {
success: true,
transactionData: transactionReceipt,
transactionHash: hash,
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "removeLiquidity");
}
}
async getCover({ coverId }) {
try {
const result = await (0, commonFunctions_1.publicClientRead)({
functionName: "getCover",
args: [coverId],
contractType: commonFunctions_1.ContractType.Policy,
});
return { success: true, cover: result };
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async isPaused() {
try {
const result = await (0, commonFunctions_1.publicClientReadIns)({ functionName: "paused" });
return { success: true, isPause: result };
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "other");
}
}
async settleClaim({ coverId, walletClient, }) {
try {
const publicClient = (0, commonFunctions_1.getPublicClient)();
if (coverId === 0) {
return {
success: false,
error: "No cover available for this cover Id",
};
}
// Now call settleClaim
const hash = await walletClient.writeContract({
address: (0, serverConstants_1.getEnvConstant)("INSURANCE_POOL_ADDRESS"),
abi: abis_1.ABIs.InsurancePoolAbi,
functionName: "settleClaim",
args: [coverId],
account: walletClient.account,
chain: this.POLYGON_CHAIN,
});
const transactionReceipt = await publicClient.waitForTransactionReceipt({
hash,
});
return {
success: true,
transactionHash: hash,
transactionData: transactionReceipt,
};
}
catch (error) {
return (0, errorHandlerUtils_1.handleError)(error, "settleClaim");
}
}
}
exports.Kohin = Kohin;