UNPKG

@byzantine/operator-sdk

Version:

SDK for integrating operators with Byzantine Finance ecosystem

68 lines (67 loc) 2.91 kB
"use strict"; /** * OperatorVaultOptInService * * Client for interacting with the Symbiotic Vault Opt-In service * This service allows operators to opt into specific vaults they want to receive stake from */ Object.defineProperty(exports, "__esModule", { value: true }); exports.OperatorVaultOptInService = void 0; const ethers_1 = require("ethers"); const networks_1 = require("../../constants/networks"); const VaultOptInServiceABI_1 = require("../../constants/symbiotic/VaultOptInServiceABI"); const utils_1 = require("../../utils"); class OperatorVaultOptInService { constructor(provider, signer, chainId) { this.provider = provider; this.signer = signer; this.chainId = chainId; const networkConfig = (0, networks_1.getNetworkConfig)(this.chainId); const contractAddress = networkConfig.operatorVaultOptInService; if (!contractAddress || contractAddress === ethers_1.ethers.ZeroAddress) { throw new Error(`Vault Opt-In Service not configured for chain ${this.chainId}`); } // Initialize contract with ABI and address this.contract = new ethers_1.ethers.Contract(contractAddress, VaultOptInServiceABI_1.VaultOptInServiceABI, this.signer || this.provider); } /** * Opt-in to a specific vault * Allows an operator to receive stake from a vault * * @param vaultAddress - The address of the vault to opt into * @returns Transaction response */ async optIn(vaultAddress) { if (!ethers_1.ethers.isAddress(vaultAddress)) { throw new Error(`Invalid vault address: ${vaultAddress}`); } return (0, utils_1.executeContractMethod)(this.contract, "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 optOut(vaultAddress) { if (!ethers_1.ethers.isAddress(vaultAddress)) { throw new Error(`Invalid vault address: ${vaultAddress}`); } return (0, utils_1.executeContractMethod)(this.contract, "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 isOptedIn(operatorAddress, vaultAddress) { if (!ethers_1.ethers.isAddress(operatorAddress) || !ethers_1.ethers.isAddress(vaultAddress)) { throw new Error("Invalid address provided"); } return (0, utils_1.callContractMethod)(this.contract, "isOptedIn", operatorAddress, vaultAddress); } } exports.OperatorVaultOptInService = OperatorVaultOptInService;