-
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 support for defaults #44
Changes from all commits
167ec9d
a26cd4f
c30b410
68a6f88
a8e7dcb
75b81fc
1fdd33b
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ pragma solidity ^0.8.16; | |
|
||
import "./interfaces/ILoan.sol"; | ||
import "./interfaces/IPool.sol"; | ||
import "./interfaces/IServiceConfiguration.sol"; | ||
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
@@ -19,6 +20,7 @@ contract Pool is IPool, ERC20 { | |
|
||
IPoolLifeCycleState private _poolLifeCycleState; | ||
address private _manager; | ||
IServiceConfiguration private _serviceConfiguration; | ||
IERC20 private _liquidityAsset; | ||
IPoolConfigurableSettings private _poolSettings; | ||
FirstLossVault private _firstLossVault; | ||
|
@@ -94,19 +96,22 @@ contract Pool is IPool, ERC20 { | |
* @param liquidityAsset asset held by the poo | ||
* @param poolManager manager of the pool | ||
* @param poolSettings configurable settings for the pool | ||
* @param serviceConfiguration address of global service configuration | ||
* @param tokenName Name used for issued pool tokens | ||
* @param tokenSymbol Symbol used for issued pool tokens | ||
*/ | ||
constructor( | ||
address liquidityAsset, | ||
address poolManager, | ||
address serviceConfiguration, | ||
IPoolConfigurableSettings memory poolSettings, | ||
string memory tokenName, | ||
string memory tokenSymbol | ||
) ERC20(tokenName, tokenSymbol) { | ||
_liquidityAsset = IERC20(liquidityAsset); | ||
_poolSettings = poolSettings; | ||
_manager = poolManager; | ||
_serviceConfiguration = IServiceConfiguration(serviceConfiguration); | ||
_firstLossVault = new FirstLossVault(address(this), liquidityAsset); | ||
_setPoolLifeCycleState(IPoolLifeCycleState.Initialized); | ||
} | ||
|
@@ -221,13 +226,31 @@ contract Pool is IPool, ERC20 { | |
|
||
_liquidityAsset.safeApprove(address(loan), loan.principal()); | ||
loan.fund(); | ||
_accountings.activeLoanPrincipals += loan.principal(); | ||
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 might be overwritten by the loan funding work, but the accounting in the default overflows without it, so I added it in |
||
} | ||
|
||
/** | ||
* @dev Called by the pool manager, marks a loan as in default, updating pool accounting and allowing loan | ||
* collateral to be claimed. | ||
* @inheritdoc IPool | ||
*/ | ||
function markLoanAsInDefault(address) external onlyManager {} | ||
function defaultLoan(address loan) | ||
external | ||
onlyManager | ||
atState(IPoolLifeCycleState.Active) | ||
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 definitely correct, but I was torn whether we want it to be enforced, or leave it to the PM's discretion if something gets into a weird state (only way that it could would be a bug, but still). |
||
{ | ||
require(loan != address(0), "Pool: 0 address"); | ||
require( | ||
PoolLib.isPoolLoan( | ||
loan, | ||
address(_serviceConfiguration), | ||
address(this) | ||
), | ||
"Pool: invalid loan" | ||
); | ||
|
||
ILoan(loan).markDefaulted(); | ||
_accountings.activeLoanPrincipals -= ILoan(loan).principal(); | ||
emit LoanDefaulted(loan); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
Withdrawal Request Methods | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,11 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration { | |
|
||
mapping(address => bool) public isLiquidityAsset; | ||
|
||
/** | ||
* @dev Holds a reference to valid LoanFactories | ||
*/ | ||
mapping(address => bool) public isLoanFactory; | ||
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. See other comment re: LoanFactory mapping |
||
|
||
/** | ||
* @dev Emitted when an address is changed. | ||
*/ | ||
|
@@ -36,6 +41,11 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration { | |
*/ | ||
event ProtocolPaused(bool paused); | ||
|
||
/** | ||
* @dev Emitted when a loan factory is set | ||
*/ | ||
event LoanFactorySet(address indexed factory, bool isValid); | ||
|
||
/** | ||
* @dev Constructor for the contract, which sets up the default roles and | ||
* owners. | ||
|
@@ -78,4 +88,16 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration { | |
function isOperator(address addr) external view returns (bool) { | ||
return hasRole(OPERATOR_ROLE, addr); | ||
} | ||
|
||
/** | ||
* @inheritdoc IServiceConfiguration | ||
*/ | ||
function setLoanFactory(address addr, bool isValid) | ||
external | ||
override | ||
onlyOperator | ||
{ | ||
isLoanFactory[addr] = isValid; | ||
emit LoanFactorySet(addr, isValid); | ||
} | ||
} |
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.
calling this one out -- I can see an argument for this to instead live on the ServiceConfiguration, perhaps in a larger mapping keyed off of the loanFactory address.
This would map
loanFactoryAddress => createdLoanAddress => bool
, or something similar.This might be slightly more testable, but perhaps overloads the Config contract. Curious if anyone has thoughts!