2018-10-24 17:12:07 +00:00
|
|
|
// withdraw the extra assets other than global balance (in case anyone donated for free) and then no need for seperate brokerage calculation
|
2018-10-25 19:42:48 +00:00
|
|
|
// IMPORTANT CHECK - decimals() - how the balance of tokens with less than 18 decimals are stored. Factor it.
|
2018-10-25 12:27:42 +00:00
|
|
|
// update the balance along with "transferAssets" functions and also check the for onlyAllowedResolver
|
2018-10-26 16:16:23 +00:00
|
|
|
// transfer assets to different address (create 2 different mappings) - 48 hour time to transfer all - send email for this
|
2018-10-24 17:12:07 +00:00
|
|
|
|
|
|
|
pragma solidity ^0.4.24;
|
|
|
|
|
2018-10-28 04:41:05 +00:00
|
|
|
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
|
|
|
|
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
|
|
|
|
|
2018-10-24 17:12:07 +00:00
|
|
|
interface AddressRegistry {
|
2018-10-25 04:52:53 +00:00
|
|
|
function getAddr(string name) external returns(address);
|
2018-10-25 12:27:42 +00:00
|
|
|
function isApprovedResolver(address user) external returns(bool);
|
2018-10-24 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 04:52:53 +00:00
|
|
|
|
2018-10-24 17:12:07 +00:00
|
|
|
contract Registry {
|
2018-10-25 04:52:53 +00:00
|
|
|
|
2018-10-24 17:12:07 +00:00
|
|
|
address public registryAddress;
|
2018-10-28 12:05:51 +00:00
|
|
|
AddressRegistry addrReg = AddressRegistry(registryAddress);
|
2018-10-25 12:27:42 +00:00
|
|
|
|
|
|
|
modifier onlyAllowedResolver(address user) {
|
2018-10-24 17:12:07 +00:00
|
|
|
require(
|
2018-10-28 12:05:51 +00:00
|
|
|
addrReg.isApprovedResolver(user),
|
2018-10-24 17:12:07 +00:00
|
|
|
"Permission Denied"
|
|
|
|
);
|
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
2018-10-25 12:27:42 +00:00
|
|
|
function getAddress(string name) internal view returns(address addr) {
|
2018-10-28 12:05:51 +00:00
|
|
|
addr = addrReg.getAddr(name);
|
2018-10-25 12:27:42 +00:00
|
|
|
require(addr != address(0), "Invalid Address");
|
2018-10-24 17:12:07 +00:00
|
|
|
}
|
2018-10-28 05:28:10 +00:00
|
|
|
|
2018-10-24 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 04:52:53 +00:00
|
|
|
|
2018-10-25 12:27:42 +00:00
|
|
|
contract AssetDB is Registry {
|
2018-10-24 17:12:07 +00:00
|
|
|
|
2018-10-28 04:41:05 +00:00
|
|
|
using SafeMath for uint;
|
|
|
|
using SafeMath for uint256;
|
|
|
|
|
2018-10-25 04:52:53 +00:00
|
|
|
mapping(address => mapping(address => uint)) balances;
|
2018-10-28 05:28:10 +00:00
|
|
|
address eth = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
2018-10-24 17:12:07 +00:00
|
|
|
|
|
|
|
function getBalance(
|
2018-10-25 04:52:53 +00:00
|
|
|
address assetHolder,
|
2018-10-25 18:44:53 +00:00
|
|
|
address tokenAddr
|
2018-10-25 04:52:53 +00:00
|
|
|
) public view returns (uint256 balance)
|
|
|
|
{
|
2018-10-25 18:44:53 +00:00
|
|
|
balance = balances[assetHolder][tokenAddr];
|
2018-10-24 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 18:44:53 +00:00
|
|
|
function deposit(address tknAddr, uint amount) public payable {
|
|
|
|
if (msg.value > 0) {
|
2018-10-28 04:41:05 +00:00
|
|
|
balances[msg.sender][eth] = balances[msg.sender][eth].add(msg.value);
|
2018-10-25 18:44:53 +00:00
|
|
|
} else {
|
2018-10-28 04:41:05 +00:00
|
|
|
IERC20 tokenFunctions = IERC20(tknAddr);
|
2018-10-25 18:44:53 +00:00
|
|
|
tokenFunctions.transferFrom(msg.sender, address(this), amount);
|
2018-10-28 04:41:05 +00:00
|
|
|
balances[msg.sender][tknAddr] = balances[msg.sender][tknAddr].add(amount);
|
2018-10-25 18:44:53 +00:00
|
|
|
}
|
2018-10-24 17:12:07 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 19:42:48 +00:00
|
|
|
function withdraw(address tknAddr, uint amount) public {
|
|
|
|
require(balances[msg.sender][tknAddr] >= amount, "Insufficient Balance");
|
2018-10-28 04:41:05 +00:00
|
|
|
balances[msg.sender][tknAddr] = balances[msg.sender][tknAddr].sub(amount);
|
2018-10-25 19:42:48 +00:00
|
|
|
if (tknAddr == eth) {
|
|
|
|
msg.sender.transfer(amount);
|
2018-10-24 17:12:07 +00:00
|
|
|
} else {
|
2018-10-28 04:41:05 +00:00
|
|
|
IERC20 tokenFunctions = IERC20(tknAddr);
|
2018-10-25 19:42:48 +00:00
|
|
|
tokenFunctions.transfer(msg.sender, amount);
|
2018-10-24 17:12:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 04:52:53 +00:00
|
|
|
function updateBalance(
|
2018-10-24 17:12:07 +00:00
|
|
|
address tokenAddr,
|
2018-10-25 19:42:48 +00:00
|
|
|
uint amount,
|
2018-10-26 16:16:23 +00:00
|
|
|
bool credit,
|
2018-10-25 18:44:53 +00:00
|
|
|
address user
|
|
|
|
) public onlyAllowedResolver(user)
|
2018-10-25 04:52:53 +00:00
|
|
|
{
|
2018-10-26 16:16:23 +00:00
|
|
|
if (credit) {
|
2018-10-28 04:41:05 +00:00
|
|
|
balances[user][tokenAddr] = balances[user][tokenAddr].add(amount);
|
2018-10-24 17:12:07 +00:00
|
|
|
} else {
|
2018-10-28 04:41:05 +00:00
|
|
|
balances[user][tokenAddr] = balances[user][tokenAddr].sub(amount);
|
2018-10-24 17:12:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 16:16:23 +00:00
|
|
|
function transferAssets(
|
2018-10-25 18:44:53 +00:00
|
|
|
address tokenAddress,
|
|
|
|
uint amount,
|
2018-10-25 19:42:48 +00:00
|
|
|
address sendTo,
|
|
|
|
address user
|
|
|
|
) public onlyAllowedResolver(user)
|
2018-10-25 18:44:53 +00:00
|
|
|
{
|
|
|
|
if (tokenAddress == eth) {
|
|
|
|
sendTo.transfer(amount);
|
|
|
|
} else {
|
2018-10-28 04:41:05 +00:00
|
|
|
IERC20 tokenFunctions = IERC20(tokenAddress);
|
2018-10-25 18:44:53 +00:00
|
|
|
tokenFunctions.transfer(sendTo, amount);
|
|
|
|
}
|
2018-10-28 04:41:05 +00:00
|
|
|
balances[user][tokenAddress] = balances[user][tokenAddress].sub(amount);
|
2018-10-25 18:44:53 +00:00
|
|
|
}
|
2018-10-24 17:12:07 +00:00
|
|
|
|
2018-10-25 04:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
contract MoatAsset is AssetDB {
|
|
|
|
|
2018-10-24 17:12:07 +00:00
|
|
|
constructor(address rAddr) public {
|
|
|
|
registryAddress = rAddr;
|
|
|
|
}
|
|
|
|
|
2018-10-25 19:42:48 +00:00
|
|
|
function () public payable {}
|
2018-10-25 04:52:53 +00:00
|
|
|
|
2018-10-28 05:28:10 +00:00
|
|
|
}
|