-
Notifications
You must be signed in to change notification settings - Fork 16
/
Maximillion.sol
47 lines (42 loc) · 1.53 KB
/
Maximillion.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
pragma solidity 0.6.12;
import "./PEther.sol";
/**
* @title Compound's Maximillion Contract
* @author Compound
*/
contract Maximillion {
/**
* @notice The default cEther market to repay in
*/
PEther public pEther;
/**
* @notice Construct a Maximillion to repay max in a CEther market
*/
constructor(PEther pEther_) public {
pEther = pEther_;
}
/**
* @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, pEther);
}
/**
* @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 pEther_ The address of the cEther contract to repay in
*/
function repayBehalfExplicit(address borrower, PEther pEther_) public payable {
uint received = msg.value;
uint borrows = pEther_.borrowBalanceCurrent(borrower);
if (received > borrows) {
pEther_.repayBorrowBehalf.value(borrows)(borrower);
msg.sender.transfer(received - borrows);
} else {
pEther_.repayBorrowBehalf.value(received)(borrower);
}
}
}