UNPKG

soren-sdk

Version:

SDK for interacting with Soren CTF Adapter contracts

53 lines 2.66 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getExpectedPayouts = exports.isReady = exports.getQuestion = exports.initialize = exports.getSorenCtfAdapter = void 0; const ethers_1 = require("ethers"); const sorenCTFAdapterABI_json_1 = __importDefault(require("../abi/sorenCTFAdapterABI.json")); const getSorenCtfAdapter = async (signer, sorenCTFAdapterAddress) => { return new ethers_1.ethers.Contract(sorenCTFAdapterAddress, sorenCTFAdapterABI_json_1.default, signer); }; exports.getSorenCtfAdapter = getSorenCtfAdapter; const initialize = async (params) => { console.log("Initializing Soren CTF Adapter with params:", params); const { ancillaryData, rewardTokenAddress, reward, proposalBond, liveness, signer, ctfAdapterAddress } = params; const sorenCtfContractInstance = await (0, exports.getSorenCtfAdapter)(signer, ctfAdapterAddress); const tx = await sorenCtfContractInstance.initialize(ancillaryData, rewardTokenAddress, reward, proposalBond, liveness); const reciept = await tx.wait(); if (reciept.status !== 1) { throw new Error("Transaction failed"); } return reciept; }; exports.initialize = initialize; const resolveMarket = async (params) => { const { questionId, signer, ctfAdapterAddress } = params; const ctfInstance = await (0, exports.getSorenCtfAdapter)(signer, ctfAdapterAddress); const tx = await ctfInstance.resolve(questionId); const receipt = await tx.wait(); return receipt; }; // Additional helper functions for interacting with the Soren CTF Adapter contract const getQuestion = async (questionId, signer, ctfAdapterAddress) => { const ctfInstance = await (0, exports.getSorenCtfAdapter)(signer, ctfAdapterAddress); return await ctfInstance.getQuestion(questionId); }; exports.getQuestion = getQuestion; const isReady = async (questionId, signer, ctfAdapterAddress) => { const ctfInstance = await (0, exports.getSorenCtfAdapter)(signer, ctfAdapterAddress); return await ctfInstance.ready(questionId); }; exports.isReady = isReady; const getExpectedPayouts = async (questionId, signer, ctfAdapterAddress) => { const ctfInstance = await (0, exports.getSorenCtfAdapter)(signer, ctfAdapterAddress); return await ctfInstance.getExpectedPayouts(questionId); }; exports.getExpectedPayouts = getExpectedPayouts; module.exports = { getSorenCtfAdapter: exports.getSorenCtfAdapter, resolveMarket, initialize: exports.initialize, }; //# sourceMappingURL=helpers.js.map