Skip to content

Commit

Permalink
compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ethereumdegen committed May 11, 2023
1 parent a2cff6b commit 568c97f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 22 deletions.
26 changes: 15 additions & 11 deletions packages/contracts/contracts/CollateralManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,24 @@ contract CollateralManager is OwnableUpgradeable, ICollateralManager {
* @notice Sends the deposited collateral to a liquidator of a bid.
* @notice Can only be called by the protocol.
* @param _bidId The id of the liquidated bid.
* @param _liquidatorAddress The address of the liquidator to send the collateral to.
* @param _recipientAddress The address of the recipient for the assets
*/
function liquidateCollateral(uint256 _bidId, address _liquidatorAddress)
function liquidateCollateral(uint256 _bidId, address _recipientAddress)
external
onlyTellerV2
{
if (isBidCollateralBacked(_bidId)) {
BidState bidState = tellerV2.getBidState(_bidId);
require(
bidState == BidState.LIQUIDATED,
"Loan has not been liquidated"
);
_withdraw(_bidId, _liquidatorAddress);
}

address _liquidatorAddress = tellerV2.getLoanLiquidator(_bidId);
require(msg.sender == _liquidatorAddress, "Not Authorized");


BidState bidState = tellerV2.getBidState(_bidId);
require(
bidState == BidState.LIQUIDATED,
"Loan has not been liquidated"
);

_withdraw(_bidId, _recipientAddress);

}

/* Internal Functions */
Expand Down
13 changes: 12 additions & 1 deletion packages/contracts/contracts/TellerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,9 @@ contract TellerV2 is

// If loan is backed by collateral, withdraw and send to the liquidator
address liquidator = _msgSenderForMarket(bid.marketplaceId);
collateralManager.liquidateCollateral(_bidId, liquidator);

bidLiquidator[_bidId] = liquidator;


emit LoanLiquidated(_bidId, liquidator);
}
Expand Down Expand Up @@ -1020,6 +1022,15 @@ contract TellerV2 is
{
borrower_ = bids[_bidId].borrower;
}


function getLoanLiquidator(uint256 _bidId)
external
view
returns (address liquidator_)
{
liquidator_ = bidLiquidator[_bidId];
}

/**
* @notice Returns the lender address for a given bid. If the stored lender address is the `LenderManager` NFT address, return the `ownerOf` for the bid ID.
Expand Down
8 changes: 7 additions & 1 deletion packages/contracts/contracts/TellerV2Storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,10 @@ abstract contract TellerV2Storage_G4 is TellerV2Storage_G3 {
mapping(uint256 => PaymentCycleType) public bidPaymentCycleType;
}

abstract contract TellerV2Storage is TellerV2Storage_G4 {}
abstract contract TellerV2Storage_G5 is TellerV2Storage_G4 {

mapping(uint256 => address) public bidLiquidator;

}

abstract contract TellerV2Storage is TellerV2Storage_G5 {}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ interface ICollateralManager {
* @notice Sends the deposited collateral to a liquidator of a bid.
* @notice Can only be called by the protocol.
* @param _bidId The id of the liquidated bid.
* @param _liquidatorAddress The address of the liquidator to send the collateral to.
* @param _recipientAddress The address of the recipient of the assets
*/
function liquidateCollateral(uint256 _bidId, address _liquidatorAddress)
function liquidateCollateral(uint256 _bidId, address _recipientAddress)
external;
}
5 changes: 5 additions & 0 deletions packages/contracts/contracts/interfaces/ITellerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ interface ITellerV2 {
view
returns (address lender_);

function getLoanLiquidator(uint256 _bidId)
external
view
returns (address liquidator_);

function getLoanLendingToken(uint256 _bidId)
external
view
Expand Down
9 changes: 9 additions & 0 deletions packages/contracts/contracts/mock/TellerV2SolMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ contract TellerV2SolMock is ITellerV2, TellerV2Storage {
return bids[_bidId].loanDetails;
}


function getLoanLiquidator(uint256 _bidId)
external
view
returns (address liquidator_)
{
liquidator_ = address(0);
}

function getBorrowerActiveLoanIds(address _borrower)
public
view
Expand Down
10 changes: 4 additions & 6 deletions packages/contracts/tests/TellerV2/TellerV2_Override.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,13 @@ contract TellerV2_Override is TellerV2 {
function _repayLoanSuper(
uint256 _bidId,
Payment memory _payment,
uint256 _owedAmount,
bool _shouldWithdrawCollateral
uint256 _owedAmount

) public {
super._repayLoan(
_bidId,
_payment,
_owedAmount,
_shouldWithdrawCollateral
_owedAmount
);
}

Expand Down Expand Up @@ -163,8 +162,7 @@ contract TellerV2_Override is TellerV2 {
function _repayLoan(
uint256 _bidId,
Payment memory _payment,
uint256 _owedAmount,
bool _shouldWithdrawCollateral
uint256 _owedAmount
) internal override {
repayLoanWasCalled = true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/tests/TellerV2/TellerV2_bids.sol
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ contract TellerV2_bids_test is Testable {

lendingToken.approve(address(tellerV2), 1e20);

tellerV2._repayLoanSuper(bidId, payment, 100, false);
tellerV2._repayLoanSuper(bidId, payment, 100);
}

//NEED TO TEST MORE BRANCHES OF TEST_REPAY_LOAN_INTERNAL
Expand Down

0 comments on commit 568c97f

Please sign in to comment.