Skip to content

Commit

Permalink
Merge pull request #251 from Ithil-protocol/min-loan-mapping
Browse files Browse the repository at this point in the history
minLoan is now a mapping for credit services
  • Loading branch information
lsqrl authored Jan 18, 2024
2 parents 5f7a6ba + 63b76bd commit 8a76c65
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/services/CreditService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ import { Service } from "./Service.sol";
abstract contract CreditService is Service {
using SafeERC20 for IERC20;

uint256 public minLoan;
mapping(address => uint256) public minLoan;

event MinLoanWasUpdated(address indexed token, uint256 amount);

error LoanBelowMinimum();
error InvalidInput();

function setMinLoan(address token, uint256 amount) external onlyGuardian {
if (amount == 0) revert InvalidParams();
if (token == address(0)) revert InvalidParams();
minLoan[token] = amount;

emit MinLoanWasUpdated(token, amount);
}

function open(Order calldata order) public virtual override unlocked {
Agreement memory agreement = order.agreement;
if (agreement.loans[0].amount < minLoan) revert LoanBelowMinimum();
if (agreement.loans[0].amount < minLoan[agreement.loans[0].token]) revert LoanBelowMinimum();
// Transfers deposit the loan to the relevant vault
// every token corresponds to a collateral token (the vault's address)
// therefore, the length of the collateral array must be at least the length of the loan array
Expand Down
2 changes: 1 addition & 1 deletion src/services/credit/CallOption.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract CallOption is CreditService {
underlying = IERC20(_underlying);
ithil = IERC20(_ithil);
halvingTime = _halvingTime;
minLoan = _minLoan;
minLoan[_underlying] = _minLoan;
tenorDuration = _tenorDuration;
vestingTime = _initialVesting + block.timestamp;

Expand Down
2 changes: 0 additions & 2 deletions src/services/credit/FixedYieldService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ contract FixedYieldService is CreditService {

constructor(
address _manager,
uint256 _minLoan,
uint256 _yield,
uint256 _deadline
) Service("Fixed Yield Service", "FIXED-YIELD-SERVICE", _manager, _deadline) {
if (_manager == address(0)) revert InvalidParams();
minLoan = _minLoan;
yield = _yield;
}

Expand Down
2 changes: 1 addition & 1 deletion test/services/SeniorFixedYieldService.test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract FixedYieldServiceTest is BaseIntegrationServiceTest {

constructor() BaseIntegrationServiceTest(rpcUrl, blockNumber) {
vm.prank(admin);
service = new FixedYieldService(address(manager), 1, 1e16, 86400 * 30);
service = new FixedYieldService(address(manager), 1e16, 86400 * 30);

loanLength = 1;
loanTokens = new address[](loanLength);
Expand Down

0 comments on commit 8a76c65

Please sign in to comment.