Skip to content

Commit

Permalink
Emit subset hash on pool creation (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmcmichael authored Dec 14, 2023
1 parent d4d9602 commit 83de463
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/ERC20PoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ contract ERC20PoolFactory is PoolDeployer, IERC20PoolFactory {
deployedPools[ERC20_NON_SUBSET_HASH][collateral_][quote_] = pool_;
deployedPoolsList.push(pool_);

emit PoolCreated(pool_);
emit PoolCreated(pool_, ERC20_NON_SUBSET_HASH);

pool.initialize(interestRate_);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ERC721PoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract ERC721PoolFactory is PoolDeployer, IERC721PoolFactory {
deployedPools[subsetHash][collateral_][quote_] = pool_;
deployedPoolsList.push(pool_);

emit PoolCreated(pool_);
emit PoolCreated(pool_, subsetHash);

pool.initialize(tokenIds_, interestRate_);
}
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/pool/IPoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface IPoolFactory {
/**
* @notice Emitted when a new pool is created.
* @param pool_ The address of the new pool.
* @param subsetHash_ The subset hash for the pool lookup
*/
event PoolCreated(address pool_);
event PoolCreated(address pool_, bytes32 subsetHash_);
}
15 changes: 8 additions & 7 deletions tests/forge/unit/ERC20Pool/ERC20PoolFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IPoolFactory } from 'src/interfaces/pool/IPoolFactory.sol';

contract ERC20PoolFactoryTest is ERC20HelperContract {
address immutable poolAddress = 0x9Fd7552Da37D2D296CB4a84d507c35Dcc926220a;
bytes32 constant ERC20_NON_SUBSET_HASH = keccak256("ERC20_NON_SUBSET_HASH");

function setUp() external {
// deploy new pool factory for factory tests
Expand Down Expand Up @@ -94,7 +95,7 @@ contract ERC20PoolFactoryTest is ERC20HelperContract {
quote: address(_quote),
interestRate: 2 * 10**18
});

// check tracking of deployed pools
assertEq(_poolFactory.getDeployedPoolsList().length, 0);
}
Expand Down Expand Up @@ -144,7 +145,7 @@ contract ERC20PoolFactoryTest is ERC20HelperContract {
skip(333);

vm.expectEmit(true, true, false, true);
emit PoolCreated(poolAddress);
emit PoolCreated(poolAddress, ERC20_NON_SUBSET_HASH);
ERC20Pool pool = ERC20Pool(_poolFactory.deployPool(address(_collateral), address(_quote), 0.0543 * 10**18));

assertEq(address(pool), poolAddress);
Expand Down Expand Up @@ -175,7 +176,7 @@ contract ERC20PoolFactoryTest is ERC20HelperContract {
address compAddress = 0xc00e94Cb662C3520282E6f5717214004A7f26888;
address daiAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
vm.expectEmit(true, true, false, true);
emit PoolCreated(poolAddress);
emit PoolCreated(poolAddress, ERC20_NON_SUBSET_HASH);
ERC20Pool pool = ERC20Pool(_poolFactory.deployPool(compAddress, daiAddress, 0.0543 * 10**18));

assertEq(address(pool), poolAddress);
Expand All @@ -200,7 +201,7 @@ contract ERC20PoolFactoryTest is ERC20HelperContract {
address wbtcAddress = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599;
address daiAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
vm.expectEmit(true, true, false, true);
emit PoolCreated(poolAddress);
emit PoolCreated(poolAddress, ERC20_NON_SUBSET_HASH);
ERC20Pool pool = ERC20Pool(_poolFactory.deployPool(wbtcAddress, daiAddress, 0.0543 * 10**18));

assertEq(address(pool), poolAddress);
Expand All @@ -225,7 +226,7 @@ contract ERC20PoolFactoryTest is ERC20HelperContract {
address wbtcAddress = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599;
address usdcAddress = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
vm.expectEmit(true, true, false, true);
emit PoolCreated(poolAddress);
emit PoolCreated(poolAddress, ERC20_NON_SUBSET_HASH);
ERC20Pool pool = ERC20Pool(_poolFactory.deployPool(wbtcAddress, usdcAddress, 0.0543 * 10**18));

assertEq(address(pool), poolAddress);
Expand All @@ -250,7 +251,7 @@ contract ERC20PoolFactoryTest is ERC20HelperContract {
address compAddress = 0xc00e94Cb662C3520282E6f5717214004A7f26888;
address usdcAddress = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
vm.expectEmit(true, true, false, true);
emit PoolCreated(poolAddress);
emit PoolCreated(poolAddress, ERC20_NON_SUBSET_HASH);
ERC20Pool pool = ERC20Pool(_poolFactory.deployPool(compAddress, usdcAddress, 0.0543 * 10**18));

assertEq(address(pool), poolAddress);
Expand All @@ -271,7 +272,7 @@ contract ERC20PoolFactoryTest is ERC20HelperContract {

function testPoolAlreadyInitialized() external {
vm.expectEmit(true, true, false, true);
emit PoolCreated(poolAddress);
emit PoolCreated(poolAddress, ERC20_NON_SUBSET_HASH);
address pool = _poolFactory.deployPool(address(_collateral), address(_quote), 0.05 * 10**18);

vm.expectRevert(IPoolErrors.AlreadyInitialized.selector);
Expand Down
8 changes: 8 additions & 0 deletions tests/forge/unit/ERC721Pool/ERC721PoolFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ contract ERC721PoolFactoryTest is ERC721HelperContract {
_factory = new ERC721PoolFactory(_ajna);

// deploy NFT collection pool
vm.expectEmit(true, true, false, true);
emit PoolCreated(0x8a2be84c82956B6DdA0c4D647Ae9357d845a086B, _factory.getNFTSubsetHash(tokenIds));
_NFTCollectionPoolAddress = _factory.deployPool(address(_collateral), address(_quote), tokenIds, 0.05 * 10**18);
_NFTCollectionPool = ERC721Pool(_NFTCollectionPoolAddress);

Expand All @@ -43,6 +45,8 @@ contract ERC721PoolFactoryTest is ERC721HelperContract {
_tokenIdsSubsetOne[2] = 50;
_tokenIdsSubsetOne[3] = 61;

vm.expectEmit(true, true, false, true);
emit PoolCreated(0x18D11C8Cf8dc292E647F0b324d10637a3A63F678, _factory.getNFTSubsetHash(_tokenIdsSubsetOne));
_NFTSubsetOnePoolAddress = _factory.deployPool(address(_collateral), address(_quote), _tokenIdsSubsetOne, 0.05 * 10**18);
_NFTSubsetOnePool = ERC721Pool(_NFTSubsetOnePoolAddress);

Expand All @@ -56,6 +60,8 @@ contract ERC721PoolFactoryTest is ERC721HelperContract {
_tokenIdsSubsetTwo[5] = 61;
_tokenIdsSubsetTwo[6] = 180;

vm.expectEmit(true, true, false, true);
emit PoolCreated(0xf80F47F84F20d8aF58cC8e93634348491357323c, _factory.getNFTSubsetHash(_tokenIdsSubsetTwo));
_NFTSubsetTwoPoolAddress = _factory.deployPool(address(_collateral), address(_quote), _tokenIdsSubsetTwo, 0.05 * 10**18);
_NFTSubsetTwoPool = ERC721Pool(_NFTSubsetTwoPoolAddress);

Expand Down Expand Up @@ -304,6 +310,8 @@ contract ERC721PoolFactoryTest is ERC721HelperContract {
tokenIdsTestSubset[1] = 2;
tokenIdsTestSubset[2] = 3;

vm.expectEmit(true, true, false, true);
emit PoolCreated(0xA8FBA534d7ebefEBB270cDC4814A1A25916A94d3, _factory.getNFTSubsetHash(tokenIdsTestSubset));
address poolAddress = _factory.deployPool(address(_collateral), address(_quote), tokenIdsTestSubset, 0.05 * 10**18);

// check tracking of deployed pools
Expand Down
60 changes: 30 additions & 30 deletions tests/forge/utils/DSTestPlus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -417,23 +417,23 @@ abstract contract DSTestPlus is Test, IPoolEvents {
address to,
uint256 amount
) internal virtual {
// to be overidden by ERC20 helper
// to be overidden by ERC20 helper
}

function _assertQuoteTokenTransferEventRoundingDown(
address from,
address to,
uint256 amount
) internal virtual {
// to be overidden by ERC20 helper
// to be overidden by ERC20 helper
}

function _assertCollateralTokenTransferEvent(
address from,
address to,
uint256 amount
) internal virtual {
// to be overidden by ERC20 helper
// to be overidden by ERC20 helper
}

/*********************/
Expand Down Expand Up @@ -487,11 +487,11 @@ abstract contract DSTestPlus is Test, IPoolEvents {
assertEq(vars.borrowerThresholdPrice, state_.thresholdPrice);

(
uint256 kickTime,
uint256 collateral,
uint256 debtToCover,
bool isCollateralized,
uint256 price,
uint256 kickTime,
uint256 collateral,
uint256 debtToCover,
bool isCollateralized,
uint256 price,
uint256 neutralPrice,
,
,
Expand All @@ -506,22 +506,22 @@ abstract contract DSTestPlus is Test, IPoolEvents {
assertEq(collateral, borrowerCollateral);
assertEq(debtToCover, borrowerDebt);
assertEq(isCollateralized, _isCollateralized(
borrowerDebt,
borrowerCollateral,
_lup(),
borrowerDebt,
borrowerCollateral,
_lup(),
_pool.poolType())
);
assertEq(price, state_.auctionPrice);
}
}

function _assertPool(PoolParams memory state_) internal {
(
,
,
uint256 htp,
,
uint256 lup,
(
,
,
uint256 htp,
,
uint256 lup,
) = _poolUtils.poolPricesInfo(address(_pool));
(
uint256 poolSize,
Expand All @@ -530,9 +530,9 @@ abstract contract DSTestPlus is Test, IPoolEvents {
uint256 pendingInflator,
) = _poolUtils.poolLoansInfo(address(_pool));
(
uint256 poolMinDebtAmount,
,
uint256 poolActualUtilization,
uint256 poolMinDebtAmount,
,
uint256 poolActualUtilization,
uint256 poolTargetUtilization
) = _poolUtils.poolUtilizationInfo(address(_pool));

Expand Down Expand Up @@ -586,7 +586,7 @@ abstract contract DSTestPlus is Test, IPoolEvents {
) internal {
_assertBucketAssets(index, lpBalance, collateral, deposit, exchangeRate);

// validate bucket is healthy / LP consistent with assets
// validate bucket is healthy / LP consistent with assets
_validateBucketLp(index, lpBalance);
_validateBucketQuantities(index);
}
Expand Down Expand Up @@ -796,7 +796,7 @@ abstract contract DSTestPlus is Test, IPoolEvents {
vm.expectRevert(IPoolErrors.AuctionNotCleared.selector);
_pool.kickReserveAuction();
}

/**********************/
/*** Revert asserts ***/
/**********************/
Expand Down Expand Up @@ -1012,7 +1012,7 @@ abstract contract DSTestPlus is Test, IPoolEvents {
uint256,
uint256
) internal virtual {
// to be overidden by ERC20/ERC721DSTestPlus
// to be overidden by ERC20/ERC721DSTestPlus
}

function _assertBorrowBorrowerNotSenderRevert(
Expand All @@ -1021,31 +1021,31 @@ abstract contract DSTestPlus is Test, IPoolEvents {
uint256,
uint256
) internal virtual {
// to be overidden by ERC20/ERC721DSTestPlus
// to be overidden by ERC20/ERC721DSTestPlus
}

function _assertBorrowLimitIndexRevert(
address from,
uint256,
uint256
) internal virtual {
// to be overidden by ERC20/ERC721DSTestPlus
// to be overidden by ERC20/ERC721DSTestPlus
}

function _assertBorrowBorrowerUnderCollateralizedRevert(
address from,
uint256,
uint256
) internal virtual {
// to be overidden by ERC20/ERC721DSTestPlus
// to be overidden by ERC20/ERC721DSTestPlus
}

function _assertBorrowMinDebtRevert(
address from,
uint256,
uint256
) internal virtual {
// to be overidden by ERC20/ERC721DSTestPlus
// to be overidden by ERC20/ERC721DSTestPlus
}

function _assertFlashloanFeeRevertsForToken(
Expand Down Expand Up @@ -1346,7 +1346,7 @@ abstract contract DSTestPlus is Test, IPoolEvents {
address from,
uint256 maxAmount
) internal virtual {
// to be overidden by ERC20/ERC721DSTestPlus
// to be overidden by ERC20/ERC721DSTestPlus
}

function _assertTakeDebtUnderMinPoolDebtRevert(
Expand Down Expand Up @@ -1426,7 +1426,7 @@ abstract contract DSTestPlus is Test, IPoolEvents {
/********************/

// Pool deployer events
event PoolCreated(address pool_);
event PoolCreated(address pool_, bytes32 subsetHash_);


/************************/
Expand All @@ -1449,7 +1449,7 @@ abstract contract DSTestPlus is Test, IPoolEvents {
IPool pool = IPool(pool_);

uint256 lupIndex = pool.depositIndex(debtAmount_);
lup_ = _priceAt(lupIndex);
lup_ = _priceAt(lupIndex);
}

function setRandomSeed(uint256 seed) public {
Expand Down

0 comments on commit 83de463

Please sign in to comment.