UNPKG

@byzantine/operator-sdk

Version:

SDK for integrating operators with Byzantine Finance ecosystem

65 lines (64 loc) 2.5 kB
"use strict"; /** * OperatorRegistry * * Client for interacting with the Operator Registry contract * This service allows operators to register in the Symbiotic ecosystem */ Object.defineProperty(exports, "__esModule", { value: true }); exports.OperatorRegistry = void 0; const ethers_1 = require("ethers"); const networks_1 = require("../../constants/networks"); const OperatorRegistryABI_1 = require("../../constants/symbiotic/OperatorRegistryABI"); const utils_1 = require("../../utils"); class OperatorRegistry { constructor(provider, signer, chainId) { this.provider = provider; this.signer = signer; this.chainId = chainId; const networkConfig = (0, networks_1.getNetworkConfig)(this.chainId); const contractAddress = networkConfig.operatorRegistry; if (!contractAddress || contractAddress === ethers_1.ethers.ZeroAddress) { throw new Error(`Symbiotic Operator Registry not configured for chain ${this.chainId}`); } // Initialize contract with ABI and address this.contract = new ethers_1.ethers.Contract(contractAddress, OperatorRegistryABI_1.SymbioticOperatorRegistryABI, this.signer || this.provider); } /** * Register as an operator in the Symbiotic ecosystem * This is the first step in the operator integration process * * @returns Transaction response */ async registerOperator() { return (0, utils_1.executeContractMethod)(this.contract, "registerOperator"); } /** * Check if an address is registered as an operator * * @param operatorAddress - The address to check * @returns Boolean indicating if the address is registered as an operator */ async isOperator(operatorAddress) { return (0, utils_1.callContractMethod)(this.contract, "isEntity", operatorAddress); } /** * Get the total number of registered operators * * @returns The total number of operators */ async getTotalOperators() { const totalBigInt = await (0, utils_1.callContractMethod)(this.contract, "totalEntities"); return Number(totalBigInt); } /** * Get the operator address at a specific index * * @param index - The index of the operator to retrieve * @returns The operator address */ async getOperatorAtIndex(index) { return (0, utils_1.callContractMethod)(this.contract, "entity", index); } } exports.OperatorRegistry = OperatorRegistry;