-
Notifications
You must be signed in to change notification settings - Fork 133
/
Mailbox.sol
51 lines (43 loc) · 1.67 KB
/
Mailbox.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
pragma solidity 0.4.20;
import 'libraries/DelegationTarget.sol';
import 'libraries/Ownable.sol';
import 'libraries/token/ERC20Basic.sol';
import 'libraries/Initializable.sol';
import 'reporting/IMailbox.sol';
import 'reporting/IMarket.sol';
import 'trading/ICash.sol';
contract Mailbox is DelegationTarget, Ownable, Initializable, IMailbox {
IMarket private market;
function initialize(address _owner, IMarket _market) public onlyInGoodTimes beforeInitialized returns (bool) {
endInitialization();
owner = _owner;
market = _market;
return true;
}
//As a delegation target we cannot override the fallback, so we provide a specific method to deposit ETH
function depositEther() public payable onlyInGoodTimes returns (bool) {
return true;
}
function withdrawEther() public onlyOwner returns (bool) {
// Withdraw any Cash balance
ICash _cash = ICash(controller.lookup("Cash"));
uint256 _tokenBalance = _cash.balanceOf(this);
if (_tokenBalance > 0) {
_cash.withdrawEtherTo(owner, _tokenBalance);
}
// Withdraw any ETH balance
if (this.balance > 0) {
owner.transfer(this.balance);
}
return true;
}
function withdrawTokens(ERC20Basic _token) public onlyOwner returns (bool) {
uint256 _balance = _token.balanceOf(this);
require(_token.transfer(owner, _balance));
return true;
}
function onTransferOwnership(address _owner, address _newOwner) internal returns (bool) {
controller.getAugur().logMarketMailboxTransferred(market.getUniverse(), market, _owner, _newOwner);
return true;
}
}