Skip to content

Commit

Permalink
fix: revert to correct pool creation flow
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
gabririgo committed Jun 21, 2022
1 parent f311d83 commit 2c72b91
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions contracts/protocol/proxies/RigoblockPoolProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -198,7 +199,7 @@ contract RigoblockPoolProxyFactory is Owned, IRigoblockPoolProxyFactory {
return (
dragoDao = data.dragoDao,
version = VERSION,
nextDragoId = getNextId()
nextDragoId = nextPoolId()
);
}

Expand Down Expand Up @@ -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(
Expand All @@ -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(); }
}
}

0 comments on commit 2c72b91

Please sign in to comment.