lender could be forced to withdraw collateral even if he/she would rather wait for liquidation during default
lender could be forced to withdraw collateral even if he/she would rather wait for liquidation during default\\nCollateralManager.withdraw would pass if the loan is defaulted (the borrower does not pay interest in time); in that case, anyone can trigger an withdrawal on behalf of the lender before the liquidation delay period passes.\\nwithdraw logic from CollateralManager.\\n```\\n     * @notice Withdraws deposited collateral from the created escrow of a bid that has been successfully repaid.\\n     * @param _bidId The id of the bid to withdraw collateral for.\\n     */\\n    function withdraw(uint256 _bidId) external {\\n        BidState bidState = tellerV2.getBidState(_bidId);\\n        console2.log("WITHDRAW %d", uint256(bidState));\\n        if (bidState == BidState.PAID) {\\n            _withdraw(_bidId, tellerV2.getLoanBorrower(_bidId));\\n        } else if (tellerV2.isLoanDefaulted(_bidId)) {  audit\\n            _withdraw(_bidId, tellerV2.getLoanLender(_bidId));\\n            emit CollateralClaimed(_bidId);\\n        } else {\\n            revert("collateral cannot be withdrawn");\\n        }\\n    }\\n```\\n
check that the caller is the lender\\n```\\n    function withdraw(uint256 _bidId) external {\\n        BidState bidState = tellerV2.getBidState(_bidId);\\n        console2.log("WITHDRAW %d", uint256(bidState));\\n        if (bidState == BidState.PAID) {\\n            _withdraw(_bidId, tellerV2.getLoanBorrower(_bidId));\\n        } else if (tellerV2.isLoanDefaulted(_bidId)) {\\n+++        uint256 _marketplaceId = bidState.marketplaceId; \\n+++        address sender = _msgSenderForMarket(_marketplaceId); \\n+++        address lender = tellerV2.getLoanLender(_bidId); \\n+++        require(sender == lender, "sender must be the lender"); \\n            _withdraw(_bidId, lender);\\n            emit CollateralClaimed(_bidId);\\n        } else {\\n            revert("collateral cannot be withdrawn");\\n        }\\n    }\\n```\\n
anyone can force lender to take up collateral during liquidation delay and liquidation could be something that never happen. This does not match the intention based on the spec which implies that lender has an option: `3) When the loan is fully repaid, the borrower can withdraw the collateral. If the loan becomes defaulted instead, then the lender has a 24 hour grace period to claim the collateral (losing the principal)`
```\\n     * @notice Withdraws deposited collateral from the created escrow of a bid that has been successfully repaid.\\n     * @param _bidId The id of the bid to withdraw collateral for.\\n     */\\n    function withdraw(uint256 _bidId) external {\\n        BidState bidState = tellerV2.getBidState(_bidId);\\n        console2.log("WITHDRAW %d", uint256(bidState));\\n        if (bidState == BidState.PAID) {\\n            _withdraw(_bidId, tellerV2.getLoanBorrower(_bidId));\\n        } else if (tellerV2.isLoanDefaulted(_bidId)) {  audit\\n            _withdraw(_bidId, tellerV2.getLoanLender(_bidId));\\n            emit CollateralClaimed(_bidId);\\n        } else {\\n            revert("collateral cannot be withdrawn");\\n        }\\n    }\\n```\\n