mirror of https://github.com/crytic/slither
parent
9e482a4f92
commit
b9962c0d96
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,286 @@ |
||||
pragma solidity ^0.4.18; |
||||
|
||||
// File: contracts/EtherDeltaI.sol |
||||
|
||||
contract EtherDeltaI { |
||||
|
||||
uint public feeMake; //percentage times (1 ether) |
||||
uint public feeTake; //percentage times (1 ether) |
||||
|
||||
mapping (address => mapping (address => uint)) public tokens; //mapping of token addresses to mapping of account balances (token=0 means Ether) |
||||
mapping (address => mapping (bytes32 => bool)) public orders; //mapping of user accounts to mapping of order hashes to booleans (true = submitted by user, equivalent to offchain signature) |
||||
mapping (address => mapping (bytes32 => uint)) public orderFills; //mapping of user accounts to mapping of order hashes to uints (amount of order that has been filled) |
||||
|
||||
function deposit() payable; |
||||
|
||||
function withdraw(uint amount); |
||||
|
||||
function depositToken(address token, uint amount); |
||||
|
||||
function withdrawToken(address token, uint amount); |
||||
|
||||
function balanceOf(address token, address user) constant returns (uint); |
||||
|
||||
function order(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce); |
||||
|
||||
function trade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount); |
||||
|
||||
function testTrade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount, address sender) constant returns(bool); |
||||
|
||||
function availableVolume(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s) constant returns(uint); |
||||
|
||||
function amountFilled(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s) constant returns(uint); |
||||
|
||||
function cancelOrder(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, uint8 v, bytes32 r, bytes32 s); |
||||
|
||||
} |
||||
|
||||
// File: contracts/KindMath.sol |
||||
|
||||
/** |
||||
* @title KindMath |
||||
* @dev Math operations with safety checks that fail |
||||
*/ |
||||
library KindMath { |
||||
function mul(uint256 a, uint256 b) internal pure returns (uint256) { |
||||
uint256 c = a * b; |
||||
require(a == 0 || c / a == b); |
||||
return c; |
||||
} |
||||
|
||||
function div(uint256 a, uint256 b) internal pure returns (uint256) { |
||||
// assert(b > 0); // Solidity automatically throws when dividing by 0 |
||||
uint256 c = a / b; |
||||
// assert(a == b * c + a % b); // There is no case in which this doesn't hold |
||||
return c; |
||||
} |
||||
|
||||
function sub(uint256 a, uint256 b) internal pure returns (uint256) { |
||||
require(b <= a); |
||||
return a - b; |
||||
} |
||||
|
||||
function add(uint256 a, uint256 b) internal pure returns (uint256) { |
||||
uint256 c = a + b; |
||||
require(c >= a); |
||||
return c; |
||||
} |
||||
} |
||||
|
||||
// File: contracts/KeyValueStorage.sol |
||||
|
||||
contract KeyValueStorage { |
||||
|
||||
mapping(address => mapping(bytes32 => uint256)) _uintStorage; |
||||
mapping(address => mapping(bytes32 => address)) _addressStorage; |
||||
mapping(address => mapping(bytes32 => bool)) _boolStorage; |
||||
mapping(address => mapping(bytes32 => bytes32)) _bytes32Storage; |
||||
|
||||
/**** Get Methods ***********/ |
||||
|
||||
function getAddress(bytes32 key) public view returns (address) { |
||||
return _addressStorage[msg.sender][key]; |
||||
} |
||||
|
||||
function getUint(bytes32 key) public view returns (uint) { |
||||
return _uintStorage[msg.sender][key]; |
||||
} |
||||
|
||||
function getBool(bytes32 key) public view returns (bool) { |
||||
return _boolStorage[msg.sender][key]; |
||||
} |
||||
|
||||
function getBytes32(bytes32 key) public view returns (bytes32) { |
||||
return _bytes32Storage[msg.sender][key]; |
||||
} |
||||
|
||||
/**** Set Methods ***********/ |
||||
|
||||
function setAddress(bytes32 key, address value) public { |
||||
_addressStorage[msg.sender][key] = value; |
||||
} |
||||
|
||||
function setUint(bytes32 key, uint value) public { |
||||
_uintStorage[msg.sender][key] = value; |
||||
} |
||||
|
||||
function setBool(bytes32 key, bool value) public { |
||||
_boolStorage[msg.sender][key] = value; |
||||
} |
||||
|
||||
function setBytes32(bytes32 key, bytes32 value) public { |
||||
_bytes32Storage[msg.sender][key] = value; |
||||
} |
||||
|
||||
/**** Delete Methods ***********/ |
||||
|
||||
function deleteAddress(bytes32 key) public { |
||||
delete _addressStorage[msg.sender][key]; |
||||
} |
||||
|
||||
function deleteUint(bytes32 key) public { |
||||
delete _uintStorage[msg.sender][key]; |
||||
} |
||||
|
||||
function deleteBool(bytes32 key) public { |
||||
delete _boolStorage[msg.sender][key]; |
||||
} |
||||
|
||||
function deleteBytes32(bytes32 key) public { |
||||
delete _bytes32Storage[msg.sender][key]; |
||||
} |
||||
|
||||
} |
||||
|
||||
// File: contracts/StorageStateful.sol |
||||
|
||||
contract StorageStateful { |
||||
KeyValueStorage public keyValueStorage; |
||||
} |
||||
|
||||
// File: contracts/StorageConsumer.sol |
||||
|
||||
contract StorageConsumer is StorageStateful { |
||||
function StorageConsumer(address _storageAddress) public { |
||||
require(_storageAddress != address(0)); |
||||
keyValueStorage = KeyValueStorage(_storageAddress); |
||||
} |
||||
} |
||||
|
||||
// File: contracts/TokenI.sol |
||||
|
||||
contract Token { |
||||
/// @return total amount of tokens |
||||
function totalSupply() public returns (uint256); |
||||
|
||||
/// @param _owner The address from which the balance will be retrieved |
||||
/// @return The balance |
||||
function balanceOf(address _owner) public returns (uint256); |
||||
|
||||
/// @notice send `_value` token to `_to` from `msg.sender` |
||||
/// @param _to The address of the recipient |
||||
/// @param _value The amount of token to be transferred |
||||
/// @return Whether the transfer was successful or not |
||||
function transfer(address _to, uint256 _value) public returns (bool); |
||||
|
||||
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` |
||||
/// @param _from The address of the sender |
||||
/// @param _to The address of the recipient |
||||
/// @param _value The amount of token to be transferred |
||||
/// @return Whether the transfer was successful or not |
||||
function transferFrom(address _from, address _to, uint256 _value) public returns (bool); |
||||
|
||||
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens |
||||
/// @param _spender The address of the account able to transfer the tokens |
||||
/// @param _value The amount of wei to be approved for transfer |
||||
/// @return Whether the approval was successful or not |
||||
function approve(address _spender, uint256 _value) public returns (bool); |
||||
|
||||
/// @param _owner The address of the account owning tokens |
||||
/// @param _spender The address of the account able to transfer the tokens |
||||
/// @return Amount of remaining tokens allowed to spent |
||||
function allowance(address _owner, address _spender) public returns (uint256); |
||||
|
||||
event Transfer(address indexed _from, address indexed _to, uint256 _value); |
||||
event Approval(address indexed _owner, address indexed _spender, uint256 _value); |
||||
|
||||
uint256 public decimals; |
||||
string public name; |
||||
} |
||||
|
||||
// File: contracts/EnclavesDEXProxy.sol |
||||
|
||||
contract EnclavesDEXProxy is StorageConsumer { |
||||
using KindMath for uint256; |
||||
|
||||
address public admin; //the admin address |
||||
address public feeAccount; //the account that will receive fees |
||||
|
||||
struct EtherDeltaInfo { |
||||
uint256 feeMake; |
||||
uint256 feeTake; |
||||
} |
||||
|
||||
EtherDeltaInfo public etherDeltaInfo; |
||||
|
||||
uint256 public feeTake; //percentage times 1 ether |
||||
uint256 public feeAmountThreshold; //gasPrice amount under which no fees are charged |
||||
|
||||
address public etherDelta; |
||||
|
||||
bool public useEIP712 = true; |
||||
bytes32 public tradeABIHash; |
||||
bytes32 public withdrawABIHash; |
||||
|
||||
bool freezeTrading; |
||||
bool depositTokenLock; |
||||
|
||||
mapping (address => mapping (uint256 => bool)) nonceCheck; |
||||
|
||||
mapping (address => mapping (address => uint256)) public tokens; //mapping of token addresses to mapping of account balances (token=0 means Ether) |
||||
mapping (address => mapping (bytes32 => bool)) public orders; //mapping of user accounts to mapping of order hashes to booleans (true = submitted by user, equivalent to offchain signature) |
||||
mapping (address => mapping (bytes32 => uint256)) public orderFills; //mapping of user accounts to mapping of order hashes to uints (amount of order that has been filled) |
||||
|
||||
address internal implementation; |
||||
address public proposedImplementation; |
||||
uint256 public proposedTimestamp; |
||||
|
||||
event Upgraded(address _implementation); |
||||
event UpgradedProposed(address _proposedImplementation, uint256 _proposedTimestamp); |
||||
|
||||
modifier onlyAdmin { |
||||
require(msg.sender == admin); |
||||
_; |
||||
} |
||||
|
||||
function EnclavesDEXProxy(address _storageAddress, address _implementation, address _admin, address _feeAccount, uint256 _feeTake, uint256 _feeAmountThreshold, address _etherDelta, bytes32 _tradeABIHash, bytes32 _withdrawABIHash) public |
||||
StorageConsumer(_storageAddress) |
||||
{ |
||||
require(_implementation != address(0)); |
||||
implementation = _implementation; |
||||
admin = _admin; |
||||
feeAccount = _feeAccount; |
||||
feeTake = _feeTake; |
||||
feeAmountThreshold = _feeAmountThreshold; |
||||
etherDelta = _etherDelta; |
||||
tradeABIHash = _tradeABIHash; |
||||
withdrawABIHash = _withdrawABIHash; |
||||
etherDeltaInfo.feeMake = EtherDeltaI(etherDelta).feeMake(); |
||||
etherDeltaInfo.feeTake = EtherDeltaI(etherDelta).feeTake(); |
||||
} |
||||
|
||||
function getImplementation() public view returns(address) { |
||||
return implementation; |
||||
} |
||||
|
||||
function proposeUpgrade(address _proposedImplementation) public onlyAdmin { |
||||
require(implementation != _proposedImplementation); |
||||
require(_proposedImplementation != address(0)); |
||||
proposedImplementation = _proposedImplementation; |
||||
proposedTimestamp = now + 2 weeks; |
||||
UpgradedProposed(proposedImplementation, now); |
||||
} |
||||
|
||||
function upgrade() public onlyAdmin { |
||||
require(proposedImplementation != address(0)); |
||||
require(proposedTimestamp < now); |
||||
implementation = proposedImplementation; |
||||
Upgraded(implementation); |
||||
} |
||||
|
||||
function () payable public { |
||||
bytes memory data = msg.data; |
||||
address impl = getImplementation(); |
||||
|
||||
assembly { |
||||
let result := delegatecall(gas, impl, add(data, 0x20), mload(data), 0, 0) |
||||
let size := returndatasize |
||||
let ptr := mload(0x40) |
||||
returndatacopy(ptr, 0, size) |
||||
switch result |
||||
case 0 { revert(ptr, size) } |
||||
default { return(ptr, size) } |
||||
} |
||||
} |
||||
|
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,454 @@ |
||||
pragma solidity ^0.4.18; |
||||
|
||||
/** |
||||
|
||||
Copyright (c) 2018 The Ocean. |
||||
|
||||
Licensed under the MIT License: https://opensource.org/licenses/MIT. |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining |
||||
a copy of this software and associated documentation files (the |
||||
"Software"), to deal in the Software without restriction, including |
||||
without limitation the rights to use, copy, modify, merge, publish, |
||||
distribute, sublicense, and/or sell copies of the Software, and to |
||||
permit persons to whom the Software is furnished to do so, subject to |
||||
the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
|
||||
**/ |
||||
|
||||
/** |
||||
* @title Ownable |
||||
* @dev The Ownable contract has an owner address, and provides basic authorization control |
||||
* functions, this simplifies the implementation of "user permissions". |
||||
*/ |
||||
contract Ownable { |
||||
address public owner; |
||||
|
||||
|
||||
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); |
||||
|
||||
|
||||
/** |
||||
* @dev The Ownable constructor sets the original `owner` of the contract to the sender |
||||
* account. |
||||
*/ |
||||
function Ownable() public { |
||||
owner = msg.sender; |
||||
} |
||||
|
||||
/** |
||||
* @dev Throws if called by any account other than the owner. |
||||
*/ |
||||
modifier onlyOwner() { |
||||
require(msg.sender == owner); |
||||
_; |
||||
} |
||||
|
||||
/** |
||||
* @dev Allows the current owner to transfer control of the contract to a newOwner. |
||||
* @param newOwner The address to transfer ownership to. |
||||
*/ |
||||
function transferOwnership(address newOwner) public onlyOwner { |
||||
require(newOwner != address(0)); |
||||
OwnershipTransferred(owner, newOwner); |
||||
owner = newOwner; |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* @title ERC20Basic |
||||
* @dev Simpler version of ERC20 interface |
||||
* @dev see https://github.com/ethereum/EIPs/issues/179 |
||||
*/ |
||||
contract ERC20Basic { |
||||
function totalSupply() public view returns (uint256); |
||||
function balanceOf(address who) public view returns (uint256); |
||||
function transfer(address to, uint256 value) public returns (bool); |
||||
event Transfer(address indexed from, address indexed to, uint256 value); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** |
||||
* @title SafeMath |
||||
* @dev Math operations with safety checks that throw on error |
||||
*/ |
||||
library SafeMath { |
||||
|
||||
/** |
||||
* @dev Multiplies two numbers, throws on overflow. |
||||
*/ |
||||
function mul(uint256 a, uint256 b) internal pure returns (uint256) { |
||||
if (a == 0) { |
||||
return 0; |
||||
} |
||||
uint256 c = a * b; |
||||
assert(c / a == b); |
||||
return c; |
||||
} |
||||
|
||||
/** |
||||
* @dev Integer division of two numbers, truncating the quotient. |
||||
*/ |
||||
function div(uint256 a, uint256 b) internal pure returns (uint256) { |
||||
// assert(b > 0); // Solidity automatically throws when dividing by 0 |
||||
uint256 c = a / b; |
||||
// assert(a == b * c + a % b); // There is no case in which this doesn't hold |
||||
return c; |
||||
} |
||||
|
||||
/** |
||||
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). |
||||
*/ |
||||
function sub(uint256 a, uint256 b) internal pure returns (uint256) { |
||||
assert(b <= a); |
||||
return a - b; |
||||
} |
||||
|
||||
/** |
||||
* @dev Adds two numbers, throws on overflow. |
||||
*/ |
||||
function add(uint256 a, uint256 b) internal pure returns (uint256) { |
||||
uint256 c = a + b; |
||||
assert(c >= a); |
||||
return c; |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* @title Basic token |
||||
* @dev Basic version of StandardToken, with no allowances. |
||||
*/ |
||||
contract BasicToken is ERC20Basic { |
||||
using SafeMath for uint256; |
||||
|
||||
mapping(address => uint256) balances; |
||||
|
||||
uint256 totalSupply_; |
||||
|
||||
/** |
||||
* @dev total number of tokens in existence |
||||
*/ |
||||
function totalSupply() public view returns (uint256) { |
||||
return totalSupply_; |
||||
} |
||||
|
||||
/** |
||||
* @dev transfer token for a specified address |
||||
* @param _to The address to transfer to. |
||||
* @param _value The amount to be transferred. |
||||
*/ |
||||
function transfer(address _to, uint256 _value) public returns (bool) { |
||||
require(_to != address(0)); |
||||
require(_value <= balances[msg.sender]); |
||||
|
||||
// SafeMath.sub will throw if there is not enough balance. |
||||
balances[msg.sender] = balances[msg.sender].sub(_value); |
||||
balances[_to] = balances[_to].add(_value); |
||||
Transfer(msg.sender, _to, _value); |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* @dev Gets the balance of the specified address. |
||||
* @param _owner The address to query the the balance of. |
||||
* @return An uint256 representing the amount owned by the passed address. |
||||
*/ |
||||
function balanceOf(address _owner) public view returns (uint256 balance) { |
||||
return balances[_owner]; |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** |
||||
* @title ERC20 interface |
||||
* @dev see https://github.com/ethereum/EIPs/issues/20 |
||||
*/ |
||||
contract ERC20 is ERC20Basic { |
||||
function allowance(address owner, address spender) public view returns (uint256); |
||||
function transferFrom(address from, address to, uint256 value) public returns (bool); |
||||
function approve(address spender, uint256 value) public returns (bool); |
||||
event Approval(address indexed owner, address indexed spender, uint256 value); |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* @title Standard ERC20 token |
||||
* |
||||
* @dev Implementation of the basic standard token. |
||||
* @dev https://github.com/ethereum/EIPs/issues/20 |
||||
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol |
||||
*/ |
||||
contract StandardToken is ERC20, BasicToken { |
||||
|
||||
mapping (address => mapping (address => uint256)) internal allowed; |
||||
|
||||
|
||||
/** |
||||
* @dev Transfer tokens from one address to another |
||||
* @param _from address The address which you want to send tokens from |
||||
* @param _to address The address which you want to transfer to |
||||
* @param _value uint256 the amount of tokens to be transferred |
||||
*/ |
||||
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { |
||||
require(_to != address(0)); |
||||
require(_value <= balances[_from]); |
||||
require(_value <= allowed[_from][msg.sender]); |
||||
|
||||
balances[_from] = balances[_from].sub(_value); |
||||
balances[_to] = balances[_to].add(_value); |
||||
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); |
||||
Transfer(_from, _to, _value); |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. |
||||
* |
||||
* Beware that changing an allowance with this method brings the risk that someone may use both the old |
||||
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this |
||||
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: |
||||
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 |
||||
* @param _spender The address which will spend the funds. |
||||
* @param _value The amount of tokens to be spent. |
||||
*/ |
||||
function approve(address _spender, uint256 _value) public returns (bool) { |
||||
allowed[msg.sender][_spender] = _value; |
||||
Approval(msg.sender, _spender, _value); |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* @dev Function to check the amount of tokens that an owner allowed to a spender. |
||||
* @param _owner address The address which owns the funds. |
||||
* @param _spender address The address which will spend the funds. |
||||
* @return A uint256 specifying the amount of tokens still available for the spender. |
||||
*/ |
||||
function allowance(address _owner, address _spender) public view returns (uint256) { |
||||
return allowed[_owner][_spender]; |
||||
} |
||||
|
||||
/** |
||||
* @dev Increase the amount of tokens that an owner allowed to a spender. |
||||
* |
||||
* approve should be called when allowed[_spender] == 0. To increment |
||||
* allowed value is better to use this function to avoid 2 calls (and wait until |
||||
* the first transaction is mined) |
||||
* From MonolithDAO Token.sol |
||||
* @param _spender The address which will spend the funds. |
||||
* @param _addedValue The amount of tokens to increase the allowance by. |
||||
*/ |
||||
function increaseApproval(address _spender, uint _addedValue) public returns (bool) { |
||||
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); |
||||
Approval(msg.sender, _spender, allowed[msg.sender][_spender]); |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* @dev Decrease the amount of tokens that an owner allowed to a spender. |
||||
* |
||||
* approve should be called when allowed[_spender] == 0. To decrement |
||||
* allowed value is better to use this function to avoid 2 calls (and wait until |
||||
* the first transaction is mined) |
||||
* From MonolithDAO Token.sol |
||||
* @param _spender The address which will spend the funds. |
||||
* @param _subtractedValue The amount of tokens to decrease the allowance by. |
||||
*/ |
||||
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { |
||||
uint oldValue = allowed[msg.sender][_spender]; |
||||
if (_subtractedValue > oldValue) { |
||||
allowed[msg.sender][_spender] = 0; |
||||
} else { |
||||
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); |
||||
} |
||||
Approval(msg.sender, _spender, allowed[msg.sender][_spender]); |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** |
||||
* @title Whitelist |
||||
* @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions. |
||||
* @dev This simplifies the implementation of "user permissions". |
||||
*/ |
||||
contract Whitelist is Ownable { |
||||
mapping(address => bool) public whitelist; |
||||
|
||||
event WhitelistedAddressAdded(address addr); |
||||
event WhitelistedAddressRemoved(address addr); |
||||
|
||||
/** |
||||
* @dev Throws if called by any account that's not whitelisted. |
||||
*/ |
||||
modifier onlyWhitelisted() { |
||||
require(whitelist[msg.sender]); |
||||
_; |
||||
} |
||||
|
||||
/** |
||||
* @dev add an address to the whitelist |
||||
* @param addr address |
||||
* @return true if the address was added to the whitelist, false if the address was already in the whitelist |
||||
*/ |
||||
function addAddressToWhitelist(address addr) onlyOwner public returns(bool success) { |
||||
if (!whitelist[addr]) { |
||||
whitelist[addr] = true; |
||||
WhitelistedAddressAdded(addr); |
||||
success = true; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @dev add addresses to the whitelist |
||||
* @param addrs addresses |
||||
* @return true if at least one address was added to the whitelist, |
||||
* false if all addresses were already in the whitelist |
||||
*/ |
||||
function addAddressesToWhitelist(address[] addrs) onlyOwner public returns(bool success) { |
||||
for (uint256 i = 0; i < addrs.length; i++) { |
||||
if (addAddressToWhitelist(addrs[i])) { |
||||
success = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @dev remove an address from the whitelist |
||||
* @param addr address |
||||
* @return true if the address was removed from the whitelist, |
||||
* false if the address wasn't in the whitelist in the first place |
||||
*/ |
||||
function removeAddressFromWhitelist(address addr) onlyOwner public returns(bool success) { |
||||
if (whitelist[addr]) { |
||||
whitelist[addr] = false; |
||||
WhitelistedAddressRemoved(addr); |
||||
success = true; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @dev remove addresses from the whitelist |
||||
* @param addrs addresses |
||||
* @return true if at least one address was removed from the whitelist, |
||||
* false if all addresses weren't in the whitelist in the first place |
||||
*/ |
||||
function removeAddressesFromWhitelist(address[] addrs) onlyOwner public returns(bool success) { |
||||
for (uint256 i = 0; i < addrs.length; i++) { |
||||
if (removeAddressFromWhitelist(addrs[i])) { |
||||
success = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
contract OceanTokenTransferManager is Ownable, Whitelist { |
||||
|
||||
/** |
||||
* @dev check if transferFrom is possible |
||||
* @param _from address The address which you want to send tokens from |
||||
* @param _to address The address which you want to transfer to |
||||
*/ |
||||
function canTransferFrom(address _from, address _to) public constant returns (bool success) { |
||||
if (whitelist[_from] == true || whitelist[_to] == true) { |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
contract OceanToken is StandardToken, Ownable { |
||||
event Airdrop(address indexed _to, uint256 _amount); |
||||
|
||||
string public constant name = 'The Ocean Token'; |
||||
string public constant symbol = 'OCEAN'; |
||||
uint8 public constant decimals = 18; |
||||
|
||||
OceanTokenTransferManager public transferManagerContract; |
||||
|
||||
/** |
||||
* @dev Airdrop the specified amount to the address |
||||
* @param _to The address that will receive the airdropped tokens. |
||||
* @param _requestedAmount The amount of tokens to airdrop. |
||||
* @return A boolean that indicates if the operation was successful. |
||||
*/ |
||||
function airdrop(address _to, uint256 _requestedAmount) onlyOwner public returns (bool) { |
||||
uint256 _amountToDrop = _requestedAmount; |
||||
|
||||
totalSupply_ = totalSupply_.add(_amountToDrop); |
||||
balances[_to] = balances[_to].add(_amountToDrop); |
||||
emit Airdrop(_to, _amountToDrop); |
||||
emit Transfer(address(0), _to, _amountToDrop); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* @dev Transfer tokens from one address to another |
||||
* @param _from address The address which you want to send tokens from |
||||
* @param _to address The address which you want to transfer to |
||||
* @param _value uint256 the amount of tokens to be transferred |
||||
*/ |
||||
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { |
||||
require(_to != address(0)); |
||||
require(_value <= balances[_from]); |
||||
require(_value <= allowed[_from][msg.sender]); |
||||
|
||||
// trading possible when at least one from list [_from, _to] is whitelisted |
||||
require(transferManagerContract.canTransferFrom(_from, _to)); |
||||
|
||||
balances[_from] = balances[_from].sub(_value); |
||||
balances[_to] = balances[_to].add(_value); |
||||
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); |
||||
emit Transfer(_from, _to, _value); |
||||
return true; |
||||
} |
||||
|
||||
function setTransferManagerContract(OceanTokenTransferManager _transferManagerContract) onlyOwner public { |
||||
transferManagerContract = _transferManagerContract; |
||||
} |
||||
} |
Loading…
Reference in new issue