forked from Synthetixio/synthetix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollateralEth.sol
77 lines (60 loc) · 2.35 KB
/
CollateralEth.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pragma solidity ^0.5.16;
pragma experimental ABIEncoderV2;
// Inheritance
import "./Collateral.sol";
import "openzeppelin-solidity-2.3.0/contracts/utils/ReentrancyGuard.sol";
import "./interfaces/ICollateralEth.sol";
// Internal references
import "./CollateralState.sol";
// This contract handles the payable aspects of eth loans.
contract CollateralEth is Collateral, ICollateralEth, ReentrancyGuard {
mapping(address => uint) public pendingWithdrawals;
constructor(
CollateralState _state,
address _owner,
ICollateralManager _manager,
address _resolver,
bytes32 _collateralKey,
uint _minCratio,
uint _minCollateral
) public Collateral(_state, _owner, _manager, _resolver, _collateralKey, _minCratio, _minCollateral) {}
function open(uint amount, bytes32 currency) external payable {
openInternal(msg.value, amount, currency, false);
}
function close(uint id) external {
uint collateral = closeInternal(msg.sender, id);
pendingWithdrawals[msg.sender] = pendingWithdrawals[msg.sender].add(collateral);
}
function deposit(address borrower, uint id) external payable {
depositInternal(borrower, id, msg.value);
}
function withdraw(uint id, uint withdrawAmount) external {
uint amount = withdrawInternal(id, withdrawAmount);
pendingWithdrawals[msg.sender] = pendingWithdrawals[msg.sender].add(amount);
}
function repay(
address account,
uint id,
uint amount
) external {
repayInternal(account, msg.sender, id, amount);
}
function draw(uint id, uint amount) external {
drawInternal(id, amount);
}
function liquidate(
address borrower,
uint id,
uint amount
) external {
uint collateralLiquidated = liquidateInternal(borrower, id, amount);
pendingWithdrawals[msg.sender] = pendingWithdrawals[msg.sender].add(collateralLiquidated);
}
function claim(uint amount) external nonReentrant {
// If they try to withdraw more than their total balance, it will fail on the safe sub.
pendingWithdrawals[msg.sender] = pendingWithdrawals[msg.sender].sub(amount);
// solhint-disable avoid-low-level-calls
(bool success, ) = msg.sender.call.value(amount)("");
require(success, "Transfer failed");
}
}