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

Restrict Deployment of Matching Quote and Collateral tokens #735

Merged
merged 3 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions src/base/PoolDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
_;
}

Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/pool/IPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 10 additions & 1 deletion tests/forge/unit/ERC20Pool/ERC20PoolFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
}

}
22 changes: 17 additions & 5 deletions tests/forge/unit/ERC721Pool/ERC721PoolFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -115,15 +115,15 @@ contract ERC721PoolFactoryTest is ERC721HelperContract {
_assertDeployWithInvalidRateRevert({
poolFactory: address(_factory),
collateral: address(_quote),
quote: address(_quote),
quote: address(new NFTCollateralToken()),
EdNoepel marked this conversation as resolved.
Show resolved Hide resolved
interestRate: 10**18
});

// should revert if trying to deploy with interest rate higher than accepted
_assertDeployWithInvalidRateRevert({
poolFactory: address(_factory),
collateral: address(_quote),
quote: address(_quote),
quote: address(new NFTCollateralToken()),
interestRate: 2 * 10**18
});

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

}