UNPKG

@byzantine/operator-sdk

Version:

SDK for integrating operators with Byzantine Finance ecosystem

69 lines (68 loc) 3 kB
"use strict"; /** * OperatorNetworkOptInService * * Client for interacting with the Symbiotic Network Opt-In service * This service allows operators to opt into specific networks they want to validate */ Object.defineProperty(exports, "__esModule", { value: true }); exports.OperatorNetworkOptInService = void 0; const ethers_1 = require("ethers"); const networks_1 = require("../../constants/networks"); const NetworkOptInServiceABI_1 = require("../../constants/symbiotic/NetworkOptInServiceABI"); const utils_1 = require("../../utils"); class OperatorNetworkOptInService { constructor(provider, signer, chainId) { this.provider = provider; this.signer = signer; this.chainId = chainId; const networkConfig = (0, networks_1.getNetworkConfig)(this.chainId); const contractAddress = networkConfig.operatorNetworkOptInService; if (!contractAddress || contractAddress === ethers_1.ethers.ZeroAddress) { throw new Error(`Network Opt-In Service not configured for chain ${this.chainId}`); } // Initialize contract with ABI and address this.contract = new ethers_1.ethers.Contract(contractAddress, NetworkOptInServiceABI_1.NetworkOptInServiceABI, this.signer || this.provider); } /** * Opt-in to a specific network * Allows an operator to indicate intention to validate for a network * * @param networkAddress - The address of the network to opt into * @returns Transaction response */ async optIn(networkAddress) { if (!ethers_1.ethers.isAddress(networkAddress)) { throw new Error(`Invalid network address: ${networkAddress}`); } return (0, utils_1.executeContractMethod)(this.contract, "optIn", networkAddress); } /** * Opt-out from a specific network * Allows an operator to stop validating for a network * * @param networkAddress - The address of the network to opt out from * @returns Transaction response */ async optOut(networkAddress) { if (!ethers_1.ethers.isAddress(networkAddress)) { throw new Error(`Invalid network address: ${networkAddress}`); } return (0, utils_1.executeContractMethod)(this.contract, "optOut", networkAddress); } /** * Check if an operator is opted-in to a specific network * * @param operatorAddress - The address of the operator to check * @param networkAddress - The address of the network to check * @returns Boolean indicating if the operator is opted in */ async isOptedIn(operatorAddress, networkAddress) { if (!ethers_1.ethers.isAddress(operatorAddress) || !ethers_1.ethers.isAddress(networkAddress)) { throw new Error("Invalid address provided"); } return (0, utils_1.callContractMethod)(this.contract, "isOptedIn", operatorAddress, networkAddress); } } exports.OperatorNetworkOptInService = OperatorNetworkOptInService;