From 2c72b9125ba0c6804f861971c41566abbc491a6f Mon Sep 17 00:00:00 2001 From: gab Date: Tue, 21 Jun 2022 16:15:17 +0200 Subject: [PATCH] fix: revert to correct pool creation flow - we first create the pool address, then we register the new address and its associate Id and meta in registry - moved one log from internal method to external for gas savings and correct logic - amended view method name, returns the Id of the next pool --- .../proxies/RigoblockPoolProxyFactory.sol | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/contracts/protocol/proxies/RigoblockPoolProxyFactory.sol b/contracts/protocol/proxies/RigoblockPoolProxyFactory.sol index eaf1989d..315d4afc 100644 --- a/contracts/protocol/proxies/RigoblockPoolProxyFactory.sol +++ b/contracts/protocol/proxies/RigoblockPoolProxyFactory.sol @@ -82,18 +82,19 @@ contract RigoblockPoolProxyFactory is Owned, IRigoblockPoolProxyFactory { whenFeePaid returns (address) { - uint256 regFee = data.registry.getFee(); - try data.registry.register{ value : regFee } ( + createDragoInternal(_name, _symbol, msg.sender); + try data.registry.register{ value : data.registry.getFee() } ( libraryData.newAddress, _name, _symbol, msg.sender - ) returns (uint256 poolId) { - createDragoInternal(_name, _symbol, msg.sender, poolId); + ) returns (uint256 poolId) + { + emit DragoCreated(_name, _symbol, libraryData.newAddress, owner, poolId); + return libraryData.newAddress; } catch Error(string memory) { revert("REGISTRY_POOL_FACTORY_CREATION_ERROR"); } - return libraryData.newAddress; } // TODO: this method should be moved to the implementation/beacon, or drago should query dao from factory, not in storage @@ -198,7 +199,7 @@ contract RigoblockPoolProxyFactory is Owned, IRigoblockPoolProxyFactory { return ( dragoDao = data.dragoDao, version = VERSION, - nextDragoId = getNextId() + nextDragoId = nextPoolId() ); } @@ -230,12 +231,11 @@ contract RigoblockPoolProxyFactory is Owned, IRigoblockPoolProxyFactory { /// @param _name String of the name /// @param _symbol String of the symbol /// @param _owner Address of the owner - /// @param _poolId Number of the new drago Id function createDragoInternal( string memory _name, string memory _symbol, - address _owner, - uint256 _poolId) + address _owner + ) internal { require( @@ -245,23 +245,21 @@ contract RigoblockPoolProxyFactory is Owned, IRigoblockPoolProxyFactory { _name, _symbol, _owner, - _poolId, data.authority ) ) != address(0), "PROXY_FACTORY_LIBRARY_DEPLOY_ERROR" ); data.dragos[_owner].push(libraryData.newAddress); - emit DragoCreated(_name, _symbol, libraryData.newAddress, _owner, _poolId); } /// @dev Returns the next Id for a drago /// @return nextDragoId Number of the next Id from the registry - function getNextId() + function nextPoolId() internal view returns (uint256 nextDragoId) { - nextDragoId = data.registry.dragoCount(); + unchecked{ nextDragoId = data.registry.nextPoolId(); } } }