UNPKG

@byzantine/vault-sdk

Version:

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

96 lines (95 loc) 4.7 kB
"use strict"; // Get list of the whitelisted address of the vault (for later, with the graph) // Get if a specific address is whitelisted // canDeposit(address addr) // Get if the vault is private/public // isPrivateVault() // Get the whitelist manager Object.defineProperty(exports, "__esModule", { value: true }); exports.isAddressWhitelisted = isAddressWhitelisted; exports.isVaultPrivate = isVaultPrivate; exports.isWhitelistManager = isWhitelistManager; exports.setAddressesWhitelistStatus = setAddressesWhitelistStatus; exports.setVaultPrivateStatus = setVaultPrivateStatus; exports.transferWhitelistManagerRole = transferWhitelistManagerRole; const utils_1 = require("../../utils"); // Role identifier constants const ROLE_ID_WHITELIST_MANAGER = "0x2ca4bff3f985a19d8e4391cdb6bb4ba90be6978dbd55d28447c299e24c9c0617"; /** * Check if an address is whitelisted to deposit in the vault * @param vaultContract - The vault contract instance * @param address - Address to check * @returns True if the address is whitelisted */ async function isAddressWhitelisted(vaultContract, address) { return await (0, utils_1.callContractMethod)(vaultContract, "canDeposit", address); } /** * Check if the vault is private * @param vaultContract - The vault contract instance * @returns True if the vault is private */ async function isVaultPrivate(vaultContract) { return await (0, utils_1.callContractMethod)(vaultContract, "isPrivateVault"); } /** * Check if an address is the whitelist manager * @param vaultContract - The vault contract instance * @param address - Address to check * @returns True if the address is the whitelist manager */ async function isWhitelistManager(vaultContract, address) { return await (0, utils_1.callContractMethod)(vaultContract, "hasRole", ROLE_ID_WHITELIST_MANAGER, address); } /** * Set whitelist status for multiple addresses * @param signer - Ethereum signer (must be the whitelist manager) * @param vaultContract - The vault contract connected to signer * @param addresses - Array of addresses to whitelist or remove from whitelist * @param canDeposit - Whether the addresses can deposit (true) or not (false) * @returns Transaction response */ async function setAddressesWhitelistStatus(signer, vaultContract, addresses, canDeposit) { const signerAddress = await signer.getAddress(); // Verify the signer has the whitelist manager role const isManager = await (0, utils_1.callContractMethod)(vaultContract, "hasRole", ROLE_ID_WHITELIST_MANAGER, signerAddress); if (!isManager) { throw new Error("Signer does not have the whitelist manager role"); } // Set whitelist status for the provided addresses return await (0, utils_1.executeContractMethod)(vaultContract, "setCanDeposit", addresses, canDeposit); } /** * Set the private status of the vault * @param signer - Ethereum signer (must be the whitelist manager) * @param vaultContract - The vault contract connected to signer * @param isPrivate - Whether the vault should be private (true) or public (false) * @returns Transaction response */ async function setVaultPrivateStatus(signer, vaultContract, isPrivate) { const signerAddress = await signer.getAddress(); // Verify the signer has the whitelist manager role const isManager = await (0, utils_1.callContractMethod)(vaultContract, "hasRole", ROLE_ID_WHITELIST_MANAGER, signerAddress); if (!isManager) { throw new Error("Signer does not have the whitelist manager role"); } // Set private status return await (0, utils_1.executeContractMethod)(vaultContract, "setIsPrivateVault", isPrivate); } /** * Transfer the whitelist 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 whitelist manager * @returns Transaction response */ async function transferWhitelistManagerRole(signer, vaultContract, newManagerAddress) { const signerAddress = await signer.getAddress(); // Get the admin role for whitelist manager const adminRole = await (0, utils_1.callContractMethod)(vaultContract, "getRoleAdmin", ROLE_ID_WHITELIST_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 whitelist manager role"); } // Grant the role to the new manager return await (0, utils_1.executeContractMethod)(vaultContract, "grantRole", ROLE_ID_WHITELIST_MANAGER, newManagerAddress); }