Skip to content

Commit

Permalink
Added repay function to WildcatMarket
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenceday committed Oct 24, 2023
1 parent 2b8a3e0 commit 9f44603
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/interfaces/IMarketEventsAndErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ interface IMarketEventsAndErrors {

error DepositToClosedMarket();

error RepayToClosedMarket();

error BorrowFromClosedMarket();

error CloseMarketWithUnpaidWithdrawals();
Expand All @@ -92,6 +94,8 @@ interface IMarketEventsAndErrors {

event Borrow(uint256 assetAmount);

event MarketRepayment(uint256 assetAmount, uint256 timestamp);

event MarketClosed(uint256 timestamp);

event FeesCollected(uint256 assets);
Expand Down
20 changes: 20 additions & 0 deletions src/market/WildcatMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ contract WildcatMarket is
emit Borrow(amount);
}

/**
* @dev Transfers funds from the caller to the market.
*
* Any payments made through this function are considered
* repayments from the borrower. Do *not* use this function
* if you are a lender or an unrelated third party.
*
* Reverts if the market is closed.
*/
function repay(uint256 amount) external nonReentrant {
MarketState memory state = _getUpdatedState();
if (state.isClosed) {
revert RepayToClosedMarket();
}

asset.safeTransferFrom(msg.sender, address(this), amount);

emit MarketRepayment(amount, block.timestamp);
}

/**
* @dev Sets the market APR to 0% and marks market as closed.
*
Expand Down

0 comments on commit 9f44603

Please sign in to comment.