UNPKG

@byzantine/vault-sdk

Version:

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

97 lines (96 loc) 4.26 kB
"use strict"; // Get fee of a vault // Get who is the fee manager (s?) // Get the available fees of a vault (how? waht exactly?) // // Change the fee of a vault (only for the fee manager) (is it possible?) // Claim the fees of tha vault (how?) // Change the fee manager (only for the role owner) Object.defineProperty(exports, "__esModule", { value: true }); exports.getCuratorFee = getCuratorFee; exports.isFeeManager = isFeeManager; exports.getUnclaimedFees = getUnclaimedFees; exports.setVaultFeePercentage = setVaultFeePercentage; exports.claimVaultFees = claimVaultFees; exports.transferFeeManagerRole = transferFeeManagerRole; const utils_1 = require("../../utils"); // The role ID for the fee manager (curator fee claimer) // Note: This might need to be updated with the actual role ID const ROLE_ID_FEE_MANAGER = "0x6270edb7c868f86fda4adedba75108201087268ea345934db8bad688e1feb91b"; /** * Get the current fee percentage of the vault * @param vaultContract - The vault contract instance * @returns The current fee percentage (in basis points, e.g. 100 = 1%) */ async function getCuratorFee(vaultContract) { // This function assumes there's a method to get the curator fee // The actual method name might differ depending on the implementation if (typeof vaultContract.curatorFee === "function") { return await (0, utils_1.callContractMethod)(vaultContract, "curatorFee"); } else { throw new Error("This vault does not support direct fee access"); } } /** * Check if an address is the fee manager * @param vaultContract - The vault contract instance * @param address - Address to check * @returns True if the address is the fee manager */ async function isFeeManager(vaultContract, address) { return await (0, utils_1.callContractMethod)(vaultContract, "hasRole", ROLE_ID_FEE_MANAGER, address); } /** * Get the available unclaimed fees for the vault * @param vaultContract - The vault contract instance * @returns The amount of unclaimed fees */ async function getUnclaimedFees(vaultContract) { // The implementation depends on the specific contract design // This is a placeholder that needs to be updated with actual implementation if (typeof vaultContract.getUnclaimedFees === "function") { return await (0, utils_1.callContractMethod)(vaultContract, "getUnclaimedFees"); } else { throw new Error("This vault does not support unclaimed fees query"); } } /** * Set the fee percentage for the vault * @param signer - Ethereum signer (must be the fee manager) * @param vaultContract - The vault contract connected to signer * @param newFee - New fee (in basis points, e.g. 100 = 1%) * @returns Transaction response */ async function setVaultFeePercentage(vaultContract, newFee) { return await (0, utils_1.executeContractMethod)(vaultContract, "setCuratorFee", newFee); } /** * Claim the accumulated fees from the vault * @param signer - Ethereum signer (must be the fee claimer) * @param vaultContract - The vault contract connected to signer * @returns Transaction response */ async function claimVaultFees(vaultContract) { return await (0, utils_1.executeContractMethod)(vaultContract, "claimCuratorFee (0x22224b37)"); } /** * Transfer the fee manager role to a new address * @param signer - Ethereum signer (must be the role admin) * @param vaultContract - The vault contract connected to signer * @param newManagerAddress - Address of the new fee manager * @returns Transaction response */ async function transferFeeManagerRole(signer, vaultContract, newManagerAddress) { const signerAddress = await signer.getAddress(); // Get the admin role for fee manager const adminRole = await (0, utils_1.callContractMethod)(vaultContract, "getRoleAdmin", ROLE_ID_FEE_MANAGER); // Verify the signer has the admin role const isAdmin = await (0, utils_1.callContractMethod)(vaultContract, "hasRole", adminRole, signerAddress); if (!isAdmin) { throw new Error("Signer does not have the admin role required to transfer fee manager role"); } // Grant the role to the new manager return await (0, utils_1.executeContractMethod)(vaultContract, "grantRole", ROLE_ID_FEE_MANAGER, newManagerAddress); }