-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add initial withdrawWindow calculations #35
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,11 @@ contract Pool is IPool, ERC20 { | |
FirstLossVault private _firstLossVault; | ||
IPoolAccountings private _accountings; | ||
|
||
/** | ||
* @dev a timestamp of when the pool was first put in this state | ||
*/ | ||
uint256 private _poolLifeCycleStateTimestamp; | ||
|
||
/** | ||
* @dev Modifier that checks that the caller is the pool's manager. | ||
*/ | ||
|
@@ -84,9 +89,8 @@ contract Pool is IPool, ERC20 { | |
_liquidityAsset = IERC20(liquidityAsset); | ||
_poolSettings = poolSettings; | ||
_manager = poolManager; | ||
_poolLifeCycleState = IPoolLifeCycleState.Initialized; | ||
|
||
_firstLossVault = new FirstLossVault(address(this), liquidityAsset); | ||
_setPoolLifeCycleState(IPoolLifeCycleState.Initialized); | ||
} | ||
|
||
/** | ||
|
@@ -136,13 +140,16 @@ contract Pool is IPool, ERC20 { | |
onlyManager | ||
atInitializedOrActiveState | ||
{ | ||
_poolLifeCycleState = PoolLib.executeFirstLossContribution( | ||
address(_liquidityAsset), | ||
amount, | ||
address(_firstLossVault), | ||
_poolLifeCycleState, | ||
_poolSettings.firstLossInitialMinimum | ||
); | ||
IPoolLifeCycleState poolLifeCycleState = PoolLib | ||
.executeFirstLossContribution( | ||
address(_liquidityAsset), | ||
amount, | ||
address(_firstLossVault), | ||
_poolLifeCycleState, | ||
_poolSettings.firstLossInitialMinimum | ||
); | ||
|
||
_setPoolLifeCycleState(poolLifeCycleState); | ||
} | ||
|
||
/** | ||
|
@@ -201,7 +208,37 @@ contract Pool is IPool, ERC20 { | |
function markLoanAsInDefault(address) external onlyManager {} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
ERC-4246 Methods | ||
Withdrawal Request Methods | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
function currentWithdrawWindowIndex() external view returns (uint256) { | ||
if (_poolLifeCycleState != IPoolLifeCycleState.Active) { | ||
return 0; | ||
} | ||
|
||
return | ||
(block.timestamp - _poolLifeCycleStateTimestamp) / | ||
_poolSettings.withdrawWindowDurationSeconds; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is user-configurable. Is it possible it's set to |
||
} | ||
|
||
function nextWithdrawWindowIndex() external view returns (uint256) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be used externally by lenders or frontends to time their claims? So they would take this value, and multiply it by the duration then + startTime basically? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we'd have another method to do that method directly, and this will become private since it's really an implementation detail. |
||
return 0; | ||
} | ||
|
||
/** | ||
* @dev Set the pool lifecycle state. If the state changes, this method | ||
* will also update the _poolLifeCycleStateTimestamp variable | ||
*/ | ||
function _setPoolLifeCycleState(IPoolLifeCycleState state) internal { | ||
if (_poolLifeCycleState != state) { | ||
_poolLifeCycleStateTimestamp = block.timestamp; | ||
} | ||
|
||
_poolLifeCycleState = state; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR really, but I wonder if this function should be the only one responsible for emitting the PoolLifeCycleTransition event (I think the PoolLib emits it right now, which felt strange to me). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats a great point -- we should absolutely move it. Will do that. |
||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
ERC-4626 Methods | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"env": { | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"@typescript-eslint/no-explicit-any": "off" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ethers } from "hardhat"; | ||
|
||
/** | ||
* Deploy a Mock ERC20 token | ||
*/ | ||
export async function deployMockERC20() { | ||
const MockERC20 = await ethers.getContractFactory("MockERC20"); | ||
const mockERC20 = await MockERC20.deploy("Test Coin", "TC"); | ||
await mockERC20.deployed(); | ||
|
||
return { | ||
mockERC20 | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there any unintended consequences of this if the pool is not active, but actually matured or faulted?