Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniqueness check on pool whitelisting #261

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions contracts/deployer/MasterDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pragma solidity >=0.8.0;

import "../interfaces/IPool.sol";
import "../interfaces/IPoolFactory.sol";
import "../utils/TridentOwnable.sol";

Expand All @@ -16,11 +17,17 @@ contract MasterDeployer is TridentOwnable {
uint256 public barFee;
address public immutable barFeeTo;
address public immutable bento;
address[] public factoryList;

uint256 internal constant MAX_FEE = 10000; // @dev 100%.

mapping(address => bool) public pools;
mapping(address => bool) public whitelistedFactories;
mapping(address => Type) public factories;

struct Type {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can find a more meaningful name, FactoryInfo ? or something else

bool whitelisted;
bytes32 identifier;
}

constructor(
uint256 _barFee,
Expand All @@ -37,19 +44,24 @@ contract MasterDeployer is TridentOwnable {
}

function deployPool(address _factory, bytes calldata _deployData) external returns (address pool) {
require(whitelistedFactories[_factory], "FACTORY_NOT_WHITELISTED");
require(factories[_factory].whitelisted, "FACTORY_NOT_WHITELISTED");
pool = IPoolFactory(_factory).deployPool(_deployData);
pools[pool] = true;
emit DeployPool(_factory, pool, _deployData);
}

function addToWhitelist(address _factory) external onlyOwner {
whitelistedFactories[_factory] = true;
bytes32 identifier = IPool(_factory).poolIdentifier();
for (uint256 i = 0; i < factoryList.length; i++) {
require(identifier != factories[factoryList[i]].identifier, "FACTORY_NOT_UNIQUE");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to unit test this behaviour ?

}
factories[_factory] = Type(true, identifier);
factoryList.push(_factory);
emit AddToWhitelist(_factory);
}

function removeFromWhitelist(address _factory) external onlyOwner {
whitelistedFactories[_factory] = false;
factories[_factory].whitelisted = false;
emit RemoveFromWhitelist(_factory);
}

Expand Down
6 changes: 4 additions & 2 deletions contracts/pool/ConstantProductPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import "./PoolDeployer.sol";
/// @notice Contract for deploying Trident exchange Constant Product Pool with configurations.
/// @author Mudit Gupta.
contract ConstantProductPoolFactory is PoolDeployer {
bytes32 public constant poolIdentifier = "Trident:ConstantProduct";

constructor(address _masterDeployer) PoolDeployer(_masterDeployer) {}

function deployPool(bytes memory _deployData) external returns (address pool) {
Expand All @@ -17,14 +19,14 @@ contract ConstantProductPoolFactory is PoolDeployer {
(tokenA, tokenB) = (tokenB, tokenA);
}

// @dev Strips any extra data.
// Strips any extra data.
_deployData = abi.encode(tokenA, tokenB, swapFee, twapSupport);

address[] memory tokens = new address[](2);
tokens[0] = tokenA;
tokens[1] = tokenB;

// @dev Salt is not actually needed since `_deployData` is part of creationCode and already contains the salt.
// Salt is not actually needed since `_deployData` is part of creationCode and already contains the salt.
bytes32 salt = keccak256(_deployData);
pool = address(new ConstantProductPool{salt: salt}(_deployData, masterDeployer));
_registerPool(pool, tokens, salt);
Expand Down
6 changes: 4 additions & 2 deletions contracts/pool/HybridPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import "./PoolDeployer.sol";
/// @notice Contract for deploying Trident exchange Hybrid Pool with configurations.
/// @author Mudit Gupta.
contract HybridPoolFactory is PoolDeployer {
bytes32 public constant poolIdentifier = "Trident:HybridPool";

constructor(address _masterDeployer) PoolDeployer(_masterDeployer) {}

function deployPool(bytes memory _deployData) external returns (address pool) {
Expand All @@ -17,13 +19,13 @@ contract HybridPoolFactory is PoolDeployer {
(tokenA, tokenB) = (tokenB, tokenA);
}

// @dev Strips any extra data.
// Strips any extra data.
_deployData = abi.encode(tokenA, tokenB, swapFee, a);
address[] memory tokens = new address[](2);
tokens[0] = tokenA;
tokens[1] = tokenB;

// @dev Salt is not actually needed since `_deployData` is part of creationCode and already contains the salt.
// Salt is not actually needed since `_deployData` is part of creationCode and already contains the salt.
bytes32 salt = keccak256(_deployData);
pool = address(new HybridPool{salt: salt}(_deployData, masterDeployer));
_registerPool(pool, tokens, salt);
Expand Down
6 changes: 4 additions & 2 deletions contracts/pool/IndexPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import "./PoolDeployer.sol";
/// @notice Contract for deploying Trident exchange Index Pool with configurations.
/// @author Mudit Gupta
contract IndexPoolFactory is PoolDeployer {
bytes32 public constant poolIdentifier = "Trident:Index";

constructor(address _masterDeployer) PoolDeployer(_masterDeployer) {}

function deployPool(bytes memory _deployData) external returns (address pool) {
(address[] memory tokens, uint136[] memory weights, uint256 swapFee) = abi.decode(_deployData, (address[], uint136[], uint256));

// @dev Strips any extra data.
// Strips any extra data.
_deployData = abi.encode(tokens, weights, swapFee);

// @dev Salt is not actually needed since `_deployData` is part of creationCode and already contains the salt.
// Salt is not actually needed since `_deployData` is part of creationCode and already contains the salt.
bytes32 salt = keccak256(_deployData);
pool = address(new IndexPool{salt: salt}(_deployData, masterDeployer));
_registerPool(pool, tokens, salt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import "../PoolDeployer.sol";
/// @notice Contract for deploying Trident exchange Concentrated Liquidity Pool with configurations.
/// @author Mudit Gupta.
contract ConcentratedLiquidityPoolFactory is PoolDeployer {
bytes32 public constant poolIdentifier = "Trident:ConcentratedLiquidity";

constructor(address _masterDeployer) PoolDeployer(_masterDeployer) {}

function deployPool(bytes memory _deployData) external returns (address pool) {
Expand All @@ -18,14 +20,14 @@ contract ConcentratedLiquidityPoolFactory is PoolDeployer {
if (tokenA > tokenB) {
(tokenA, tokenB) = (tokenB, tokenA);
}
// @dev Strips any extra data.
// Strips any extra data.
_deployData = abi.encode(tokenA, tokenB, swapFee, price, tickSpacing);

address[] memory tokens = new address[](2);
tokens[0] = tokenA;
tokens[1] = tokenB;

// @dev Salt is not actually needed since `_deployData` is part of creationCode and already contains the salt.
// Salt is not actually needed since `_deployData` is part of creationCode and already contains the salt.
bytes32 salt = keccak256(_deployData);
pool = address(new ConcentratedLiquidityPool{salt: salt}(_deployData, IMasterDeployer(masterDeployer)));
_registerPool(pool, tokens, salt);
Expand Down