// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.10; import "./CEther.sol"; /** * @title Compound's Maximillion Contract * @author Compound */ contract Maximillion { /** * @notice The default cEther market to repay in */ CEther public cEther; /** * @notice Construct a Maximillion to repay max in a CEther market */ constructor(CEther cEther_) public { cEther = cEther_; } /** * @notice msg.sender sends Ether to repay an account's borrow in the cEther market * @dev The provided Ether is applied towards the borrow balance, any excess is refunded * @param borrower The address of the borrower account to repay on behalf of */ function repayBehalf(address borrower) public payable { repayBehalfExplicit(borrower, cEther); } /** * @notice msg.sender sends Ether to repay an account's borrow in a cEther market * @dev The provided Ether is applied towards the borrow balance, any excess is refunded * @param borrower The address of the borrower account to repay on behalf of * @param cEther_ The address of the cEther contract to repay in */ function repayBehalfExplicit(address borrower, CEther cEther_) public payable { uint received = msg.value; uint borrows = cEther_.borrowBalanceCurrent(borrower); if (received > borrows) { cEther_.repayBorrowBehalf{value: borrows}(borrower); payable(msg.sender).transfer(received - borrows); } else { cEther_.repayBorrowBehalf{value: received}(borrower); } } }