From 163c0870d2c00ecb9262f8273100cf245d017f9f Mon Sep 17 00:00:00 2001 From: Nenad Misic Date: Mon, 24 Jul 2023 22:42:08 +0200 Subject: [PATCH] Refactor `SubDao` (#219) * Inherit ISubDao * Fix mismatch between impl. and interface in SubDao * Add missing validation in initializeSubDao * Use Validator where possible in SubDao * Rename registerContract -> registerContracts * Add back owner check in updateConfig --- .../normalized_endowment/subdao/ISubDao.sol | 3 +- .../normalized_endowment/subdao/SubDao.sol | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/contracts/normalized_endowment/subdao/ISubDao.sol b/contracts/normalized_endowment/subdao/ISubDao.sol index f6ee0bd70..9515d4cce 100644 --- a/contracts/normalized_endowment/subdao/ISubDao.sol +++ b/contracts/normalized_endowment/subdao/ISubDao.sol @@ -22,13 +22,12 @@ interface ISubDao { ) external; function createPoll( - address proposer, uint256 depositamount, string memory title, string memory description, string memory link, SubDaoStorage.ExecuteData memory executeMsgs - ) external; + ) external returns (uint256); function endPoll(uint256 pollid) external; diff --git a/contracts/normalized_endowment/subdao/SubDao.sol b/contracts/normalized_endowment/subdao/SubDao.sol index cf4c2a578..63acdccd8 100644 --- a/contracts/normalized_endowment/subdao/SubDao.sol +++ b/contracts/normalized_endowment/subdao/SubDao.sol @@ -14,10 +14,11 @@ import {SubDaoTokenMessage} from "./../subdao-token/message.sol"; import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import {ISubDaoEmitter} from "./ISubDaoEmitter.sol"; +import {ISubDao} from "./ISubDao.sol"; import "./Token/ERC20.sol"; import "./storage.sol"; -contract SubDao is Storage, ReentrancyGuard, Initializable { +contract SubDao is ISubDao, Storage, ReentrancyGuard, Initializable { address emitterAddress; address accountAddress; @@ -31,7 +32,7 @@ contract SubDao is Storage, ReentrancyGuard, Initializable { SubDaoMessages.InstantiateMsg memory details, address _emitterAddress ) public initializer { - require(Validator.addressChecker(_emitterAddress), "InvalidEmitterAddress"); + require(Validator.addressChecker(_emitterAddress), "Invalid emitter address"); require(Validator.addressChecker(details.registrarContract), "Invalid registrarContract"); require(Validator.addressChecker(details.owner), "Invalid owner"); @@ -121,7 +122,10 @@ contract SubDao is Storage, ReentrancyGuard, Initializable { details.token.token == SubDaoLib.TokenType.VeBonding && details.endowType == LibAccounts.EndowmentType.Charity ) { - require(registrar_config.haloToken != address(0), "Registrar's HALO token address is empty"); + require( + Validator.addressChecker(registrar_config.haloToken), + "Registrar's HALO token address is empty" + ); SubDaoTokenMessage.InstantiateMsg memory temp = SubDaoTokenMessage.InstantiateMsg({ name: details.token.data.veBondingName, @@ -163,19 +167,18 @@ contract SubDao is Storage, ReentrancyGuard, Initializable { } /** - * @notice function used to register the contract address - * @dev Register the contract address - * @param vetoken The address of the ve token contract - * @param swapfactory The address of the swap factory contract + * @notice function used to register the ve bonding token and swap factory contract addresses + * @param veToken The address of the ve bonding token contract + * @param swapFactory The address of the swap factory contract */ - function registerContract(address vetoken, address swapfactory) external { + function registerContracts(address veToken, address swapFactory) external { require(config.owner == msg.sender, "Unauthorized"); - require(vetoken != address(0), "Invalid input"); - require(swapfactory != address(0), "Invalid input"); + require(Validator.addressChecker(veToken), "Invalid veToken"); + require(Validator.addressChecker(swapFactory), "Invalid swapFactory"); - config.veToken = vetoken; - config.swapFactory = swapfactory; + config.veToken = veToken; + config.swapFactory = swapFactory; ISubDaoEmitter(emitterAddress).updateSubDaoConfig(); } @@ -203,7 +206,7 @@ contract SubDao is Storage, ReentrancyGuard, Initializable { ) external { require(config.owner == msg.sender, "Unauthorized"); - if (owner != address(0)) { + if (Validator.addressChecker(owner)) { config.owner = owner; }