From 568c97f3a481dcb9f8bab4fe263db242e09fd428 Mon Sep 17 00:00:00 2001 From: Admazzola Date: Thu, 11 May 2023 10:49:59 -0400 Subject: [PATCH] compiles --- .../contracts/contracts/CollateralManager.sol | 26 +++++++++++-------- packages/contracts/contracts/TellerV2.sol | 13 +++++++++- .../contracts/contracts/TellerV2Storage.sol | 8 +++++- .../interfaces/ICollateralManager.sol | 4 +-- .../contracts/interfaces/ITellerV2.sol | 5 ++++ .../contracts/mock/TellerV2SolMock.sol | 9 +++++++ .../tests/TellerV2/TellerV2_Override.sol | 10 +++---- .../tests/TellerV2/TellerV2_bids.sol | 2 +- 8 files changed, 55 insertions(+), 22 deletions(-) diff --git a/packages/contracts/contracts/CollateralManager.sol b/packages/contracts/contracts/CollateralManager.sol index 3cec6e97f..5dd9d88fe 100644 --- a/packages/contracts/contracts/CollateralManager.sol +++ b/packages/contracts/contracts/CollateralManager.sol @@ -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 */ diff --git a/packages/contracts/contracts/TellerV2.sol b/packages/contracts/contracts/TellerV2.sol index 4720cc1ca..7a8cf3bfd 100644 --- a/packages/contracts/contracts/TellerV2.sol +++ b/packages/contracts/contracts/TellerV2.sol @@ -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); } @@ -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. diff --git a/packages/contracts/contracts/TellerV2Storage.sol b/packages/contracts/contracts/TellerV2Storage.sol index 0f7a58308..8a144cd9c 100644 --- a/packages/contracts/contracts/TellerV2Storage.sol +++ b/packages/contracts/contracts/TellerV2Storage.sol @@ -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 {} diff --git a/packages/contracts/contracts/interfaces/ICollateralManager.sol b/packages/contracts/contracts/interfaces/ICollateralManager.sol index b0705af5c..ee9116332 100644 --- a/packages/contracts/contracts/interfaces/ICollateralManager.sol +++ b/packages/contracts/contracts/interfaces/ICollateralManager.sol @@ -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; } diff --git a/packages/contracts/contracts/interfaces/ITellerV2.sol b/packages/contracts/contracts/interfaces/ITellerV2.sol index 0fa8a3823..fa37bef2d 100644 --- a/packages/contracts/contracts/interfaces/ITellerV2.sol +++ b/packages/contracts/contracts/interfaces/ITellerV2.sol @@ -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 diff --git a/packages/contracts/contracts/mock/TellerV2SolMock.sol b/packages/contracts/contracts/mock/TellerV2SolMock.sol index 8938bfe43..29f089b4d 100644 --- a/packages/contracts/contracts/mock/TellerV2SolMock.sol +++ b/packages/contracts/contracts/mock/TellerV2SolMock.sol @@ -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 diff --git a/packages/contracts/tests/TellerV2/TellerV2_Override.sol b/packages/contracts/tests/TellerV2/TellerV2_Override.sol index 77bd9157f..922773a78 100644 --- a/packages/contracts/tests/TellerV2/TellerV2_Override.sol +++ b/packages/contracts/tests/TellerV2/TellerV2_Override.sol @@ -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 ); } @@ -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; } diff --git a/packages/contracts/tests/TellerV2/TellerV2_bids.sol b/packages/contracts/tests/TellerV2/TellerV2_bids.sol index f7e7ec732..075da9c5b 100644 --- a/packages/contracts/tests/TellerV2/TellerV2_bids.sol +++ b/packages/contracts/tests/TellerV2/TellerV2_bids.sol @@ -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