Skip to content

Commit

Permalink
Add liquidtyPoolFactory file and add migration test
Browse files Browse the repository at this point in the history
  • Loading branch information
AStox committed Nov 14, 2023
1 parent 149494f commit c21366e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/PoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract PoolManager is Auth {
uint8 internal constant MAX_DECIMALS = 18;

EscrowLike public immutable escrow;
LiquidityPoolFactoryLike public immutable liquidityPoolFactory;
LiquidityPoolFactoryLike public liquidityPoolFactory;
TrancheTokenFactoryLike public immutable trancheTokenFactory;

GatewayLike public gateway;
Expand Down Expand Up @@ -151,6 +151,7 @@ contract PoolManager is Auth {
if (what == "gateway") gateway = GatewayLike(data);
else if (what == "investmentManager") investmentManager = InvestmentManagerLike(data);
else if (what == "restrictionManagerFactory") restrictionManagerFactory = RestrictionManagerFactoryLike(data);
else if (what == "liquidityPoolFactory") liquidityPoolFactory = LiquidityPoolFactoryLike(data);
else revert("PoolManager/file-unrecognized-param");
emit File(what, data);
}
Expand Down
28 changes: 28 additions & 0 deletions test/PoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ contract PoolManagerTest is TestSetup {
poolManager.file("restrictionManagerFactory", newRestrictionManagerFactory);
assertEq(address(poolManager.restrictionManagerFactory()), newRestrictionManagerFactory);

address newLiquidityPoolFactory = makeAddr("newLiquidityPoolFactory");
poolManager.file("liquidityPoolFactory", newLiquidityPoolFactory);
assertEq(address(poolManager.liquidityPoolFactory()), newLiquidityPoolFactory);

address newEscrow = makeAddr("newEscrow");
vm.expectRevert("PoolManager/file-unrecognized-param");
poolManager.file("escrow", newEscrow);
Expand Down Expand Up @@ -549,6 +553,30 @@ contract PoolManagerTest is TestSetup {
poolManager.removeLiquidityPool(poolId, trancheId, address(erc20));
}

function testLiquidityPoolMigration() public {
address oldLiquidityPool_ = deploySimplePool();

LiquidityPool oldLiquidityPool = LiquidityPool(oldLiquidityPool_);
uint64 poolId = oldLiquidityPool.poolId();
bytes16 trancheId = oldLiquidityPool.trancheId();
address currency = address(oldLiquidityPool.asset());

LiquidityPoolFactory newLiquidityPoolFactory = new LiquidityPoolFactory(address(root));

// rewire factory contracts
newLiquidityPoolFactory.rely(address(poolManager));
poolManager.file("liquidityPoolFactory", address(newLiquidityPoolFactory));

// Remove old liquidity pool
root.relyContract(address(poolManager), address(this));
poolManager.removeLiquidityPool(poolId, trancheId, currency);
assertEq(poolManager.getLiquidityPool(poolId, trancheId, currency), address(0));

// Deploy new liquidity pool
address newLiquidityPool = poolManager.deployLiquidityPool(poolId, trancheId, currency);
assertEq(poolManager.getLiquidityPool(poolId, trancheId, currency), newLiquidityPool);
}

// helpers
function hasDuplicates(bytes16[4] calldata array) internal pure returns (bool) {
uint256 length = array.length;
Expand Down

0 comments on commit c21366e

Please sign in to comment.