forked from MyBitFoundation/MyBit-Network.tech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EscrowReserve.sol
53 lines (49 loc) · 2.79 KB
/
EscrowReserve.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
pragma solidity ^0.4.24;
import "../interfaces/EscrowReserveInterface.sol";
import "../interfaces/BurnableERC20.sol";
interface Events {
function transaction(string _message, address _from, address _to, uint _amount, address _token) external;
}
interface DB {
function addressStorage(bytes32 _key) external view returns (address);
function uintStorage(bytes32 _key) external view returns (uint);
function setUint(bytes32 _key, uint _value) external;
function deleteUint(bytes32 _key) external;
function setBool(bytes32 _key, bool _value) external;
function boolStorage(bytes32 _key) external view returns (bool);
}
contract EscrowReserve is EscrowReserveInterface{
DB private database;
Events private events;
constructor(address _database, address _events) public {
database = DB(_database);
events = Events(_events);
}
function issueERC20(address _receiver, uint256 _amount, address _tokenAddress) external returns (bool){
require(msg.sender == database.addressStorage(keccak256(abi.encodePacked("contract", "AssetManagerEscrow"))));
BurnableERC20 erc20 = BurnableERC20(_tokenAddress);
require(erc20.balanceOf(this) >= _amount);
require(erc20.transfer(_receiver, _amount));
events.transaction("ERC20 withdrawn from escrow reserve", address(this), _receiver, _amount, _tokenAddress);
return true;
}
function requestERC20(address _payer, uint256 _amount, address _tokenAddress) external returns (bool){
require(msg.sender == database.addressStorage(keccak256(abi.encodePacked("contract", "AssetManagerEscrow"))) ||
msg.sender == database.addressStorage(keccak256(abi.encodePacked("contract", "CrowdsaleGeneratorETH"))) ||
msg.sender == database.addressStorage(keccak256(abi.encodePacked("contract", "CrowdsaleGeneratorERC20"))));
require(BurnableERC20(_tokenAddress).transferFrom(_payer, address(this), _amount));
events.transaction("ERC20 received by escrow reserve", _payer, address(this), _amount, _tokenAddress);
}
function approveERC20(address _receiver, uint256 _amount, address _tokenAddress) external returns (bool){
require(msg.sender == database.addressStorage(keccak256(abi.encodePacked("contract", "AssetManagerEscrow"))));
BurnableERC20(_tokenAddress).approve(_receiver, _amount); //always returns true
events.transaction("ERC20 approval given by escrow reserve", address(this), _receiver, _amount, _tokenAddress);
return true;
}
function burnERC20(uint256 _amount, address _tokenAddress) external returns (bool){
require(msg.sender == database.addressStorage(keccak256(abi.encodePacked("contract", "AssetManagerEscrow"))));
require(BurnableERC20(_tokenAddress).burn(_amount));
events.transaction("ERC20 burnt by escrow reserve", address(this), address(0), _amount, _tokenAddress);
return true;
}
}