diff --git a/src/base/PoolDeployer.sol b/src/base/PoolDeployer.sol index 2ae7459c6..7be189a28 100644 --- a/src/base/PoolDeployer.sol +++ b/src/base/PoolDeployer.sol @@ -36,8 +36,9 @@ abstract contract PoolDeployer { * @dev Used by both ERC20, and ERC721 pool factory types. */ modifier canDeploy(address collateral_, address quote_, uint256 interestRate_) { - if (collateral_ == address(0) || quote_ == address(0)) revert IPoolFactory.DeployWithZeroAddress(); - if (MIN_RATE > interestRate_ || interestRate_ > MAX_RATE) revert IPoolFactory.PoolInterestRateInvalid(); + if (collateral_ == quote_) revert IPoolFactory.DeployQuoteCollateralSameToken(); + if (collateral_ == address(0) || quote_ == address(0)) revert IPoolFactory.DeployWithZeroAddress(); + if (MIN_RATE > interestRate_ || interestRate_ > MAX_RATE) revert IPoolFactory.PoolInterestRateInvalid(); _; } diff --git a/src/interfaces/pool/IPoolFactory.sol b/src/interfaces/pool/IPoolFactory.sol index 993c4eeef..bcf64a367 100644 --- a/src/interfaces/pool/IPoolFactory.sol +++ b/src/interfaces/pool/IPoolFactory.sol @@ -11,6 +11,10 @@ interface IPoolFactory { /**************/ /*** Errors ***/ /**************/ + /** + * @notice Can't deploy if quote and collateral are the same token. + */ + error DeployQuoteCollateralSameToken(); /** * @notice Can't deploy with one of the args pointing to the 0x0 address. diff --git a/tests/forge/unit/ERC20Pool/ERC20PoolFactory.t.sol b/tests/forge/unit/ERC20Pool/ERC20PoolFactory.t.sol index 1181d6076..a4bcc5fe6 100644 --- a/tests/forge/unit/ERC20Pool/ERC20PoolFactory.t.sol +++ b/tests/forge/unit/ERC20Pool/ERC20PoolFactory.t.sol @@ -74,7 +74,8 @@ contract ERC20PoolFactoryTest is ERC20HelperContract { }); // should deploy different pool - address poolTwo = _poolFactory.deployPool(address(_collateral), address(_collateral), 0.05 * 10**18); + address compAddress = 0xc00e94Cb662C3520282E6f5717214004A7f26888; + address poolTwo = _poolFactory.deployPool(address(_collateral), compAddress, 0.05 * 10**18); assertFalse(poolOne == poolTwo); // check tracking of deployed pools @@ -240,4 +241,12 @@ contract ERC20PoolFactoryTest is ERC20HelperContract { ERC20Pool(pool).initialize(0.05 * 10**18); } + function testDeployERC20SameQuoteCollateral() external { + skip(333); + + address usdcAddress = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; + vm.expectRevert(IPoolFactory.DeployQuoteCollateralSameToken.selector); + _poolFactory.deployPool(usdcAddress, usdcAddress, 0.0543 * 1e18 ); + } + } diff --git a/tests/forge/unit/ERC721Pool/ERC721PoolFactory.t.sol b/tests/forge/unit/ERC721Pool/ERC721PoolFactory.t.sol index b4a12f555..71189fe7a 100644 --- a/tests/forge/unit/ERC721Pool/ERC721PoolFactory.t.sol +++ b/tests/forge/unit/ERC721Pool/ERC721PoolFactory.t.sol @@ -20,6 +20,7 @@ contract ERC721PoolFactoryTest is ERC721HelperContract { ERC721PoolFactory internal _factory; uint256[] internal _tokenIdsSubsetOne; uint256[] internal _tokenIdsSubsetTwo; + uint256[] internal tokenIds; function setUp() external { _startTime = block.timestamp; @@ -30,7 +31,6 @@ contract ERC721PoolFactoryTest is ERC721HelperContract { _factory = new ERC721PoolFactory(_ajna); // deploy NFT collection pool - uint256[] memory tokenIds; _NFTCollectionPoolAddress = _factory.deployPool(address(_collateral), address(_quote), tokenIds, 0.05 * 10**18); _NFTCollectionPool = ERC721Pool(_NFTCollectionPoolAddress); @@ -114,7 +114,7 @@ contract ERC721PoolFactoryTest is ERC721HelperContract { // should revert if trying to deploy with interest rate lower than accepted _assertDeployWithInvalidRateRevert({ poolFactory: address(_factory), - collateral: address(_quote), + collateral: address(new NFTCollateralToken()), quote: address(_quote), interestRate: 10**18 }); @@ -122,7 +122,7 @@ contract ERC721PoolFactoryTest is ERC721HelperContract { // should revert if trying to deploy with interest rate higher than accepted _assertDeployWithInvalidRateRevert({ poolFactory: address(_factory), - collateral: address(_quote), + collateral: address(new NFTCollateralToken()), quote: address(_quote), interestRate: 2 * 10**18 }); @@ -153,7 +153,6 @@ contract ERC721PoolFactoryTest is ERC721HelperContract { } function testDeployERC721PoolWithMinRate() external { - uint256[] memory tokenIds = new uint256[](0); _factory.deployPool( address(new NFTCollateralToken()), address(new TokenWithNDecimals("Quote", "Q1", 18)), @@ -167,7 +166,6 @@ contract ERC721PoolFactoryTest is ERC721HelperContract { } function testDeployERC721PoolWithMaxRate() external { - uint256[] memory tokenIds = new uint256[](0); _factory.deployPool( address(new NFTCollateralToken()), address(new TokenWithNDecimals("Quote", "Q1", 18)), @@ -318,4 +316,18 @@ contract ERC721PoolFactoryTest is ERC721HelperContract { assertFalse(_NFTSubsetOnePool.tokenIdsAllowed(10)); } + function testDeployERC721SameQuoteCollateral() external { + skip(333); + + address NFTCollectionAddress = address(new NFTCollateralToken()); + + vm.expectRevert(IPoolFactory.DeployQuoteCollateralSameToken.selector); + _factory.deployPool( + address(NFTCollectionAddress), + address(NFTCollectionAddress), + tokenIds, + 0.5 * 10**18 + ); + } + }