UNPKG

@byzantine/vault-sdk

Version:

Byzantine Vault SDK for creating and managing vaults on Ethereum for restaking strategies

144 lines (143 loc) 6.59 kB
"use strict"; // Get the ratio of a supervault // getDistributionRatio() // Get who is the balancer manager (does that exist?) // Get status of the rebalance (does it make sense?) // Get the underlying vaults // getUnderlyingVaults() // // Change the ratio of a supervault (only for the balancer manager?) // updateDistributionRatio(uint256 _symRatio) // Change the role manager (only for the role owner, does it exists?) // setBalancerManager(address newBalancerManager) // Force the rebalance of the supervault // rebalance() Object.defineProperty(exports, "__esModule", { value: true }); exports.getDistributionRatio = getDistributionRatio; exports.isBalancerManager = isBalancerManager; exports.getRebalanceStatus = getRebalanceStatus; exports.getUnderlyingVaults = getUnderlyingVaults; exports.updateDistributionRatio = updateDistributionRatio; exports.setBalancerManager = setBalancerManager; exports.forceRebalance = forceRebalance; const utils_1 = require("../../utils"); // The role ID for the balancer manager (if applicable) // Note: This is a placeholder and needs to be confirmed const ROLE_ID_BALANCER_MANAGER = "0x0000000000000000000000000000000000000000000000000000000000000000"; /** * Get the distribution ratio of the supervault * @param supervaultContract - The supervault contract instance * @returns The current distribution ratio */ async function getDistributionRatio(supervaultContract) { // This assumes there's a method to get the distribution ratio if (typeof supervaultContract.getDistributionRatio === "function") { return await (0, utils_1.callContractMethod)(supervaultContract, "getDistributionRatio"); } else { throw new Error("This supervault does not support distribution ratio query"); } } /** * Check if an address is the balancer manager * @param supervaultContract - The supervault contract instance * @param address - Address to check * @returns True if the address is the balancer manager */ async function isBalancerManager(supervaultContract, address) { // This is a placeholder implementation // Need to verify if the role exists and what its ID is try { return await (0, utils_1.callContractMethod)(supervaultContract, "hasRole", ROLE_ID_BALANCER_MANAGER, address); } catch (error) { throw new Error("Balancer manager role check not supported by this contract"); } } /** * Get the current rebalance status of the supervault * @param supervaultContract - The supervault contract instance * @returns The rebalance status information (implementation dependent) */ async function getRebalanceStatus(supervaultContract) { // This is a placeholder implementation // The actual method and return type depends on the implementation if (typeof supervaultContract.getRebalanceStatus === "function") { return await (0, utils_1.callContractMethod)(supervaultContract, "getRebalanceStatus"); } else { throw new Error("This supervault does not support rebalance status query"); } } /** * Get the underlying vaults of the supervault * @param supervaultContract - The supervault contract instance * @returns Array of underlying vault addresses */ async function getUnderlyingVaults(supervaultContract) { // This assumes there's a method to get the underlying vaults if (typeof supervaultContract.getUnderlyingVaults === "function") { return await (0, utils_1.callContractMethod)(supervaultContract, "getUnderlyingVaults"); } else { throw new Error("This supervault does not support underlying vaults query"); } } /** * Update the distribution ratio of the supervault * @param signer - Ethereum signer (must be the balancer manager) * @param supervaultContract - The supervault contract connected to signer * @param ratio - New distribution ratio * @returns Transaction response */ async function updateDistributionRatio(signer, supervaultContract, ratio) { // This assumes there's a method to update the distribution ratio // and that the signer has the correct permissions if (typeof supervaultContract.updateDistributionRatio === "function") { return await (0, utils_1.executeContractMethod)(supervaultContract, "updateDistributionRatio", ratio); } else { throw new Error("This supervault does not support distribution ratio updates"); } } /** * Set a new balancer manager * @param signer - Ethereum signer (must be the role admin) * @param supervaultContract - The supervault contract connected to signer * @param newManagerAddress - Address of the new balancer manager * @returns Transaction response */ async function setBalancerManager(signer, supervaultContract, newManagerAddress) { // This is a placeholder implementation // Need to verify if this functionality exists if (typeof supervaultContract.setBalancerManager === "function") { return await (0, utils_1.executeContractMethod)(supervaultContract, "setBalancerManager", newManagerAddress); } else { // Alternative: try using role-based access control if available try { const adminRole = await (0, utils_1.callContractMethod)(supervaultContract, "getRoleAdmin", ROLE_ID_BALANCER_MANAGER); const signerAddress = await signer.getAddress(); // Verify the signer has the admin role const isAdmin = await (0, utils_1.callContractMethod)(supervaultContract, "hasRole", adminRole, signerAddress); if (!isAdmin) { throw new Error("Signer does not have the admin role required to transfer balancer manager role"); } // Grant the role to the new manager return await (0, utils_1.executeContractMethod)(supervaultContract, "grantRole", ROLE_ID_BALANCER_MANAGER, newManagerAddress); } catch (error) { throw new Error("This supervault does not support changing the balancer manager"); } } } /** * Force a rebalance of the supervault * @param signer - Ethereum signer (permissions vary by implementation) * @param supervaultContract - The supervault contract connected to signer * @returns Transaction response */ async function forceRebalance(signer, supervaultContract) { // This assumes there's a method to force a rebalance if (typeof supervaultContract.rebalance === "function") { return await (0, utils_1.executeContractMethod)(supervaultContract, "rebalance"); } else { throw new Error("This supervault does not support forced rebalancing"); } }