UNPKG

@byzantine/operator-sdk

Version:

SDK for integrating operators with Byzantine Finance ecosystem

249 lines (248 loc) 9.67 kB
"use strict"; // @ts-check Object.defineProperty(exports, "__esModule", { value: true }); exports.ByzOperatorClient = void 0; const networks_1 = require("../constants/networks"); // Import Symbiotic clients const symbiotic_1 = require("./symbiotic"); // Import Native clients const native_1 = require("./native"); class ByzOperatorClient { constructor(options) { this.chainId = options.chainId; if (!(0, networks_1.isChainSupported)(this.chainId)) { throw new Error(`Chain ID ${this.chainId} is not supported`); } this.provider = options.provider; this.signer = options.signer; if (!this.signer) { throw new Error("Signer is required for operator client"); } // Initialize Symbiotic clients this.symOperatorRegistry = new symbiotic_1.OperatorRegistry(this.provider, this.signer, this.chainId); this.symNetworkOptInService = new symbiotic_1.OperatorNetworkOptInService(this.provider, this.signer, this.chainId); this.symVaultOptInService = new symbiotic_1.OperatorVaultOptInService(this.provider, this.signer, this.chainId); // Initialize Native clients this.nativeOperatorRegistry = new native_1.NativeOperatorRegistry(this.provider, this.signer, this.chainId); } //========================================================================= // SYMBIOTIC PROTOCOL FUNCTIONS //========================================================================= /** * Register as an operator in the Symbiotic ecosystem * This is the first step in the operator integration process * * @returns Transaction response */ async registerOperator() { return this.symOperatorRegistry.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 this.symOperatorRegistry.isOperator(operatorAddress); } /** * Get the total number of registered operators * * @returns The total number of operators */ async getTotalOperators() { return this.symOperatorRegistry.getTotalOperators(); } /** * 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 this.symOperatorRegistry.getOperatorAtIndex(index); } /** * Opt-in to a specific network * Allows an operator to indicate intention to validate for a network * This should be done after registering as an operator * * @param networkAddress - The address of the network to opt into * @returns Transaction response */ async optInNetwork(networkAddress) { return this.symNetworkOptInService.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 optOutNetwork(networkAddress) { return this.symNetworkOptInService.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 isOptedInNetwork(operatorAddress, networkAddress) { return this.symNetworkOptInService.isOptedIn(operatorAddress, networkAddress); } /** * Opt-in to a specific vault * Allows an operator to receive stake from a vault * This should be done after registering as an operator * * @param vaultAddress - The address of the vault to opt into * @returns Transaction response */ async optInVault(vaultAddress) { return this.symVaultOptInService.optIn(vaultAddress); } /** * Opt-out from a specific vault * Allows an operator to stop receiving stake from a vault * * @param vaultAddress - The address of the vault to opt out from * @returns Transaction response */ async optOutVault(vaultAddress) { return this.symVaultOptInService.optOut(vaultAddress); } /** * Check if an operator is opted-in to a specific vault * * @param operatorAddress - The address of the operator to check * @param vaultAddress - The address of the vault to check * @returns Boolean indicating if the operator is opted in */ async isOptedInVault(operatorAddress, vaultAddress) { return this.symVaultOptInService.isOptedIn(operatorAddress, vaultAddress); } //========================================================================= // EIGENLAYER PROTOCOL FUNCTIONS (Coming soon) //========================================================================= //========================================================================= // NATIVE STAKING PROTOCOL FUNCTIONS //========================================================================= /** * Register as an operator in the Native ecosystem * * @param name - Unique name for the operator * @param admin - Address that will administer the operator (default: signer's address) * @param operatorFee - Fee percentage as uint16 (default: 1000 = 10%) * @param managers - Array of manager addresses (default: empty array) * @returns Transaction response with operator index (bytes32) */ async registerNativeOperator(name, admin, operatorFee = 1000, managers = []) { // Use signer's address as admin if not specified if (!admin) { admin = await this.signer.getAddress(); } return this.nativeOperatorRegistry.registerOperator(name, admin, operatorFee, managers); } /** * Unregister an operator in the Native ecosystem * * @param operatorIndex - The bytes32 index of the operator * @returns Transaction response */ async unregisterNativeOperator(operatorIndex) { return this.nativeOperatorRegistry.unregisterOperator(operatorIndex); } /** * Check if an operator name is already registered * * @param name - The name to check * @returns Boolean indicating if the operator is registered */ async isNativeOperatorRegistered(name) { return this.nativeOperatorRegistry.isOperatorRegistered(name); } /** * Get the operator ID from a name * * @param name - The operator name * @returns Bytes32 ID of the operator */ async getNativeOperatorId(name) { return this.nativeOperatorRegistry.getOperatorId(name); } /** * Get the admin address of an operator * * @param operatorIndex - The bytes32 index of the operator * @returns Admin address */ async getNativeOperatorAdmin(operatorIndex) { return this.nativeOperatorRegistry.getOperatorAdmin(operatorIndex); } /** * Get the fee percentage of an operator * * @param operatorIndex - The bytes32 index of the operator * @returns Fee percentage as uint16 */ async getNativeOperatorFee(operatorIndex) { return this.nativeOperatorRegistry.getOperatorFee(operatorIndex); } /** * Check if an address is a manager of an operator * * @param operatorIndex - The bytes32 index of the operator * @param address - The address to check * @returns Boolean indicating if the address is a manager */ async isNativeOperatorManager(operatorIndex, address) { return this.nativeOperatorRegistry.isManagerOfOperator(operatorIndex, address); } /** * Set manager status for an operator * * @param operatorIndex - The bytes32 index of the operator * @param managers - Array of manager addresses * @param isManager - Boolean indicating if the addresses should be managers * @returns Transaction response */ async setNativeOperatorManager(operatorIndex, managers, isManager) { return this.nativeOperatorRegistry.setOperatorManager(operatorIndex, managers, isManager); } /** * Transfer the admin role for an operator * * @param operatorIndex - The bytes32 index of the operator * @param newAdmin - Address of the new admin * @returns Transaction response */ async transferNativeAdminRole(operatorIndex, newAdmin) { return this.nativeOperatorRegistry.transferAdminRole(operatorIndex, newAdmin); } /** * Update an operator's fee * * @param operatorIndex - The bytes32 index of the operator * @param operatorFee - New fee percentage (as uint16) * @returns Transaction response */ async updateNativeOperatorFee(operatorIndex, operatorFee) { return this.nativeOperatorRegistry.updateOperatorFee(operatorIndex, operatorFee); } //========================================================================= // UTILITY FUNCTIONS //========================================================================= /** * Get the network configuration for the current chain * * @returns Network configuration */ getNetworkConfig() { return (0, networks_1.getNetworkConfig)(this.chainId); } } exports.ByzOperatorClient = ByzOperatorClient;