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

VAL-67 Add support for adjusting the pool end date #68

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Changes from all 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
10 changes: 4 additions & 6 deletions contracts/Pool.sol
Original file line number Diff line number Diff line change
@@ -305,13 +305,11 @@ contract Pool is IPool, ERC20 {
}

/**
* @dev Updates the pool end date. Can only be called by the Pool Manager.
* @inheritdoc IPool
*/
function updatePoolEndDate(uint256)
external
onlyManager
returns (uint256)
{}
function updatePoolEndDate(uint256 endDate) external onlyManager {
PoolLib.executeUpdateEndDate(endDate, _poolSettings);
}

/**
* @dev Called by the pool manager, this transfers liquidity from the pool to a given loan.
2 changes: 1 addition & 1 deletion contracts/interfaces/IPool.sol
Original file line number Diff line number Diff line change
@@ -173,7 +173,7 @@ interface IPool is IERC4626 {
/**
* @dev Updates the pool end date. Can only be called by the Pool Manager.
*/
function updatePoolEndDate(uint256) external returns (uint256);
function updatePoolEndDate(uint256) external;

/**
* @dev Returns the withdrawal fee for a given withdrawal amount at the current block.
31 changes: 26 additions & 5 deletions contracts/libraries/PoolLib.sol
Original file line number Diff line number Diff line change
@@ -60,6 +60,16 @@ library PoolLib {
uint256 outstandingLosses
);

/**
* @dev See IPool for event definition
*/
event LoanDefaulted(address indexed loan);

/**
* @dev Emitted when pool settings are updated.
*/
event PoolSettingsUpdated();

/**
* @dev Determines whether an address corresponds to a pool loan
* @param loan address of loan
@@ -80,11 +90,6 @@ library PoolLib {
ILoan(loan).pool() == pool;
}

/**
* @dev See IPool for event definition
*/
event LoanDefaulted(address indexed loan);

/**
* @dev Divide two numbers and round the result up
*/
@@ -96,6 +101,22 @@ library PoolLib {
return (lhs + rhs - 1) / rhs;
}

/**
* @dev Updates the Pool End Date.
*/
function executeUpdateEndDate(
uint256 endDate,
IPoolConfigurableSettings storage settings
) external {
require(settings.endDate > endDate, "Pool: can't move end date up");
require(
endDate > block.timestamp,
"Pool: can't move end date into the past"
);
settings.endDate = endDate;
emit PoolSettingsUpdated();
}

/**
* @dev Transfers first loss to the vault.
* @param liquidityAsset Pool liquidity asset
33 changes: 33 additions & 0 deletions test/Pool.test.ts
Original file line number Diff line number Diff line change
@@ -701,6 +701,39 @@ describe("Pool", () => {
});
});

describe("updatePoolEndDate()", () => {
it("reverts if trying to move up end date", async () => {
const { pool, poolManager } = await loadFixture(loadPoolFixture);

const newEndDate = (await pool.settings()).endDate.add(1);

await expect(
pool.connect(poolManager).updatePoolEndDate(newEndDate)
).to.be.revertedWith("Pool: can't move end date up");
});

it("reverts if trying to set end date to be in the past", async () => {
const { pool, poolManager } = await loadFixture(loadPoolFixture);

const now = time.latest();

await expect(
pool.connect(poolManager).updatePoolEndDate(now)
).to.be.revertedWith("Pool: can't move end date into the past");
});

it("allows moving up the pool end date", async () => {
const { pool, poolManager } = await loadFixture(loadPoolFixture);

const newEndDate = (await pool.settings()).endDate.sub(1);

await expect(
pool.connect(poolManager).updatePoolEndDate(newEndDate)
).to.emit(pool, "PoolSettingsUpdated");
expect((await pool.settings()).endDate).to.equal(newEndDate);
});
});

describe("Permissions", () => {
describe("updatePoolCapacity()", () => {
it("reverts if not called by Pool Manager", async () => {