forked from abondarevrn/contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaxmillion.sol
52 lines (47 loc) · 1.67 KB
/
Maxmillion.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
pragma solidity >=0.5.8;
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
* @return The initial borrows before the repay
*/
function repayBehalf(address borrower) public payable {
return 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
* @return The initial borrows before the repay
*/
function repayBehalfExplicit(address borrower, CEther cEther_)
public
payable
{
uint256 received = msg.value;
uint256 borrows = cEther_.borrowBalanceCurrent(borrower);
if (received > borrows) {
cEther_.repayBorrowBehalf.value(borrows)(borrower);
msg.sender.transfer(received - borrows);
} else {
cEther_.repayBorrowBehalf.value(received)(borrower);
}
}
}