Skip to content

Commit

Permalink
added minLoan to credit
Browse files Browse the repository at this point in the history
  • Loading branch information
lsqrl committed Dec 18, 2023
1 parent e08fa1a commit 8ae503e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/services/CreditService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import { Service } from "./Service.sol";
abstract contract CreditService is Service {
using SafeERC20 for IERC20;

uint256 public minLoan;

error LoanBelowMinimum();
error InvalidInput();

function open(Order calldata order) public virtual override unlocked {
Agreement memory agreement = order.agreement;
if (agreement.loans[0].amount < minLoan) 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
4 changes: 2 additions & 2 deletions src/services/credit/CallOption.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ contract CallOption is CreditService {
event IthilTokenAllocated(uint256 amount);
event IthilTokenSwept(uint256 amount);

error ZeroAmount();
error LockPeriodStillActive();
error MaxLockExceeded();
error MaxPurchaseExceeded();
Expand All @@ -61,6 +60,7 @@ contract CallOption is CreditService {
address _manager,
address _ithil,
uint256 _initialPrice,
uint256 _minLoan,
uint256 _halvingTime,
uint256 _tenorDuration,
uint256 _initialVesting,
Expand All @@ -83,6 +83,7 @@ contract CallOption is CreditService {
underlying = IERC20(_underlying);
ithil = IERC20(_ithil);
halvingTime = _halvingTime;
minLoan = _minLoan;
tenorDuration = _tenorDuration;
vestingTime = _initialVesting + block.timestamp;

Expand Down Expand Up @@ -114,7 +115,6 @@ contract CallOption is CreditService {

if (agreement.loans[0].token != address(underlying)) revert InvalidUnderlyingToken();
if (agreement.collaterals[1].token != address(ithil)) revert InvalidIthilToken();
if (agreement.loans[0].amount == 0) revert ZeroAmount();

uint256 price = _currentPrice();
// Apply reward based on lock
Expand Down
2 changes: 2 additions & 0 deletions src/services/credit/FixedYieldService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ 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/DebitCredit.test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ contract DebitCreditTest is Test, IERC721Receiver {

// first price is 0.2 USDC: we need to double it in the constructor
// because the smallest price can only be achieved by maximum lock time
callOptionService = new CallOption(address(manager), address(ithil), 4e5, 86400 * 30, 86400 * 30, 0, usdc);
callOptionService = new CallOption(address(manager), address(ithil), 4e5, 1, 86400 * 30, 86400 * 30, 0, usdc);
vm.stopPrank();
}

Expand Down
2 changes: 1 addition & 1 deletion test/services/SeniorCallOption.test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract CallOptionTest is BaseIntegrationServiceTest {
IERC20(loanTokens[0]).approve(address(manager), 1);
manager.create(loanTokens[0]);

service = new CallOption(address(manager), address(ithil), 4e17, 86400 * 30, 86400 * 30, 0, loanTokens[0]);
service = new CallOption(address(manager), address(ithil), 4e17, 1, 86400 * 30, 86400 * 30, 0, loanTokens[0]);

serviceAddress = address(service);
ithil.approve(serviceAddress, 1e25);
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), 1e16, 86400 * 30);
service = new FixedYieldService(address(manager), 1, 1e16, 86400 * 30);

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

0 comments on commit 8ae503e

Please sign in to comment.