@vechain/vebetterdao-contracts
Version:
Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.
54 lines (53 loc) • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.setWhitelistedFunctions = void 0;
const hardhat_1 = require("hardhat");
/**
* Set the whitelisted functions from config
* Performs the following steps for each contract:
* 1. Get the function signatures from the contract factory
* 2. Set the whitelisted functions in the governor contract
*
* @param contractAddresses - Addresses of the deployed contracts
* @param config - Contracts configuration
* @param governor - B3TRGovernor contract instance
* @param admin - Admin signer
*
* @note - For ambiguous functions (functions with same name), the function signature is used to differentiate them
* e.g., instead of using "setVoterRewards", we use "setVoterRewards(address)" in the config
*/
const setWhitelistedFunctions = async (contractAddresses, config, governor, admin, libraries, logOutput = false) => {
if (logOutput)
console.log("================ Setting whitelisted functions in B3TRGovernor contract");
const { B3TR_GOVERNOR_WHITELISTED_METHODS } = config;
for (const [contract, functions] of Object.entries(B3TR_GOVERNOR_WHITELISTED_METHODS)) {
// Check if the contract address exists
const contractAddress = contractAddresses[contract];
if (!contractAddress) {
if (logOutput)
console.log(`Skipping ${contract} as it does not exist in contract addresses`);
continue; // Skip this contract if address does not exist
}
// Check if the current contract requires linking with any libraries
const contractLibraries = libraries[contract];
// Getting the contract factory with or without libraries as needed
const contractFactory = contractLibraries
? await hardhat_1.ethers.getContractFactory(contract, { libraries: contractLibraries })
: await hardhat_1.ethers.getContractFactory(contract);
const whitelistFunctionSelectors = [];
for (const func of functions) {
const sig = contractFactory.interface.getFunction(func)?.selector;
if (sig)
whitelistFunctionSelectors.push(sig);
}
if (whitelistFunctionSelectors.length !== 0) {
await governor
.connect(admin)
.setWhitelistFunctions(contractAddresses[contract], whitelistFunctionSelectors, true)
.then(async (tx) => await tx.wait());
if (logOutput)
console.log(`Whitelisted functions set for ${contract} in B3TRGovernor contract`);
}
}
};
exports.setWhitelistedFunctions = setWhitelistedFunctions;