From ebe030775656611d1a04084a2491c6476815153b Mon Sep 17 00:00:00 2001 From: ams9198 <111915188+ams9198@users.noreply.github.com> Date: Tue, 25 Oct 2022 09:29:19 -0400 Subject: [PATCH] VAL-36 Allow setting pool capacity (#54) --- contracts/Pool.sol | 12 ++++++------ contracts/interfaces/IPool.sol | 4 ++-- test/Pool.test.ts | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/contracts/Pool.sol b/contracts/Pool.sol index 4cda810f..82b1ea6e 100644 --- a/contracts/Pool.sol +++ b/contracts/Pool.sol @@ -296,13 +296,13 @@ contract Pool is IPool, ERC20 { } /** - * @dev Updates the pool capacity. Can only be called by the Pool Manager. + * @inheritdoc IPool */ - function updatePoolCapacity(uint256) - external - onlyManager - returns (uint256) - {} + function updatePoolCapacity(uint256 newCapacity) external onlyManager { + require(newCapacity >= totalAssets(), "Pool: invalid capacity"); + _poolSettings.maxCapacity = newCapacity; + emit PoolSettingsUpdated(); + } /** * @dev Updates the pool end date. Can only be called by the Pool Manager. diff --git a/contracts/interfaces/IPool.sol b/contracts/interfaces/IPool.sol index 280b1f1a..ee68de09 100644 --- a/contracts/interfaces/IPool.sol +++ b/contracts/interfaces/IPool.sol @@ -86,7 +86,7 @@ interface IPool is IERC4626 { /** * @dev Emitted when pool settings are updated. */ - event PoolSettingsUpdated(IPoolConfigurableSettings settings); + event PoolSettingsUpdated(); /** * @dev Emitted when first loss capital is used to cover loan defaults @@ -155,7 +155,7 @@ interface IPool is IERC4626 { /** * @dev Updates the pool capacity. Can only be called by the Pool Manager. */ - function updatePoolCapacity(uint256) external returns (uint256); + function updatePoolCapacity(uint256) external; /** * @dev Updates the pool end date. Can only be called by the Pool Manager. diff --git a/test/Pool.test.ts b/test/Pool.test.ts index b0f475c1..619cea87 100644 --- a/test/Pool.test.ts +++ b/test/Pool.test.ts @@ -452,6 +452,33 @@ describe("Pool", () => { }); }); + describe("updatePoolCapacity()", () => { + it("prevents setting capacity to less than current pool size", async () => { + const { pool, otherAccount, poolManager, liquidityAsset } = + await loadFixture(loadPoolFixture); + + await activatePool(pool, poolManager, liquidityAsset); + await depositToPool(pool, otherAccount, liquidityAsset, 100); + await expect( + pool.connect(poolManager).updatePoolCapacity(1) + ).to.be.revertedWith("Pool: invalid capacity"); + }); + + it("allows setting pool capacity", async () => { + const { pool, otherAccount, poolManager, liquidityAsset } = + await loadFixture(loadPoolFixture); + + await activatePool(pool, poolManager, liquidityAsset); + await depositToPool(pool, otherAccount, liquidityAsset, 100); + await expect(pool.connect(poolManager).updatePoolCapacity(101)).to.emit( + pool, + "PoolSettingsUpdated" + ); + + expect((await pool.settings()).maxCapacity).to.equal(101); + }); + }); + describe("Permissions", () => { describe("updatePoolCapacity()", () => { it("reverts if not called by Pool Manager", async () => {