contract_name
stringlengths
1
61
file_path
stringlengths
5
50.4k
contract_address
stringlengths
42
42
language
stringclasses
1 value
class_name
stringlengths
1
61
class_code
stringlengths
4
330k
class_documentation
stringlengths
0
29.1k
class_documentation_type
stringclasses
6 values
func_name
stringlengths
0
62
func_code
stringlengths
1
303k
func_documentation
stringlengths
2
14.9k
func_documentation_type
stringclasses
4 values
compiler_version
stringlengths
15
42
license_type
stringclasses
14 values
swarm_source
stringlengths
0
71
meta
dict
__index_level_0__
int64
0
60.4k
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StandardToken
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; } }
approve
function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _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. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1485, 1675 ] }
707
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StandardToken
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; } }
allowance
function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; }
/** * @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. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1999, 2130 ] }
708
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StandardToken
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; } }
increaseApproval
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 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. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 2596, 2860 ] }
709
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StandardToken
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; } }
decreaseApproval
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; }
/** * @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. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 3331, 3741 ] }
710
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
MintableToken
contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; modifier canMint() { require(!mintingFinished); _; } /** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { totalSupply_ = totalSupply_.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; MintFinished(); return true; } }
mint
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { totalSupply_ = totalSupply_.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; }
/** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 483, 756 ] }
711
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
MintableToken
contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished(); bool public mintingFinished = false; modifier canMint() { require(!mintingFinished); _; } /** * @dev Function to mint tokens * @param _to The address that will receive the minted tokens. * @param _amount The amount of tokens to mint. * @return A boolean that indicates if the operation was successful. */ function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { totalSupply_ = totalSupply_.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; } /** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */ function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; MintFinished(); return true; } }
finishMinting
function finishMinting() onlyOwner canMint public returns (bool) { mintingFinished = true; MintFinished(); return true; }
/** * @dev Function to stop minting new tokens. * @return True if the operation was successful. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 873, 1015 ] }
712
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
DisbursementHandler
contract DisbursementHandler is Ownable { struct Disbursement { uint256 timestamp; uint256 tokens; } event LogSetup(address indexed vestor, uint256 tokens, uint256 timestamp); event LogChangeTimestamp(address indexed vestor, uint256 index, uint256 timestamp); event LogWithdraw(address indexed to, uint256 value); ERC20 public token; mapping(address => Disbursement[]) public disbursements; mapping(address => uint256) public withdrawnTokens; function DisbursementHandler(address _token) public { token = ERC20(_token); } /// @dev Called by the sale contract to create a disbursement. /// @param vestor The address of the beneficiary. /// @param tokens Amount of tokens to be locked. /// @param timestamp Funds will be locked until this timestamp. function setupDisbursement( address vestor, uint256 tokens, uint256 timestamp ) public onlyOwner { require(block.timestamp < timestamp); disbursements[vestor].push(Disbursement(timestamp, tokens)); LogSetup(vestor, timestamp, tokens); } /// @dev Change an existing disbursement. /// @param vestor The address of the beneficiary. /// @param timestamp Funds will be locked until this timestamp. /// @param index Index of the DisbursementVesting in the vesting array. function changeTimestamp( address vestor, uint256 index, uint256 timestamp ) public onlyOwner { require(block.timestamp < timestamp); require(index < disbursements[vestor].length); disbursements[vestor][index].timestamp = timestamp; LogChangeTimestamp(vestor, index, timestamp); } /// @dev Transfers tokens to a given address /// @param to Address of token receiver /// @param value Number of tokens to transfer function withdraw(address to, uint256 value) public { uint256 maxTokens = calcMaxWithdraw(); uint256 withdrawAmount = value < maxTokens ? value : maxTokens; withdrawnTokens[msg.sender] = SafeMath.add(withdrawnTokens[msg.sender], withdrawAmount); token.transfer(to, withdrawAmount); LogWithdraw(to, value); } /// @dev Calculates the maximum amount of vested tokens /// @return Number of vested tokens to withdraw function calcMaxWithdraw() public constant returns (uint256) { uint256 maxTokens = 0; Disbursement[] storage temp = disbursements[msg.sender]; for (uint256 i = 0; i < temp.length; i++) { if (block.timestamp > temp[i].timestamp) { maxTokens = SafeMath.add(maxTokens, temp[i].tokens); } } maxTokens = SafeMath.sub(maxTokens, withdrawnTokens[msg.sender]); return maxTokens; } }
setupDisbursement
function setupDisbursement( address vestor, uint256 tokens, uint256 timestamp ) public onlyOwner { require(block.timestamp < timestamp); disbursements[vestor].push(Disbursement(timestamp, tokens)); LogSetup(vestor, timestamp, tokens); }
/// @dev Called by the sale contract to create a disbursement. /// @param vestor The address of the beneficiary. /// @param tokens Amount of tokens to be locked. /// @param timestamp Funds will be locked until this timestamp.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 856, 1184 ] }
713
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
DisbursementHandler
contract DisbursementHandler is Ownable { struct Disbursement { uint256 timestamp; uint256 tokens; } event LogSetup(address indexed vestor, uint256 tokens, uint256 timestamp); event LogChangeTimestamp(address indexed vestor, uint256 index, uint256 timestamp); event LogWithdraw(address indexed to, uint256 value); ERC20 public token; mapping(address => Disbursement[]) public disbursements; mapping(address => uint256) public withdrawnTokens; function DisbursementHandler(address _token) public { token = ERC20(_token); } /// @dev Called by the sale contract to create a disbursement. /// @param vestor The address of the beneficiary. /// @param tokens Amount of tokens to be locked. /// @param timestamp Funds will be locked until this timestamp. function setupDisbursement( address vestor, uint256 tokens, uint256 timestamp ) public onlyOwner { require(block.timestamp < timestamp); disbursements[vestor].push(Disbursement(timestamp, tokens)); LogSetup(vestor, timestamp, tokens); } /// @dev Change an existing disbursement. /// @param vestor The address of the beneficiary. /// @param timestamp Funds will be locked until this timestamp. /// @param index Index of the DisbursementVesting in the vesting array. function changeTimestamp( address vestor, uint256 index, uint256 timestamp ) public onlyOwner { require(block.timestamp < timestamp); require(index < disbursements[vestor].length); disbursements[vestor][index].timestamp = timestamp; LogChangeTimestamp(vestor, index, timestamp); } /// @dev Transfers tokens to a given address /// @param to Address of token receiver /// @param value Number of tokens to transfer function withdraw(address to, uint256 value) public { uint256 maxTokens = calcMaxWithdraw(); uint256 withdrawAmount = value < maxTokens ? value : maxTokens; withdrawnTokens[msg.sender] = SafeMath.add(withdrawnTokens[msg.sender], withdrawAmount); token.transfer(to, withdrawAmount); LogWithdraw(to, value); } /// @dev Calculates the maximum amount of vested tokens /// @return Number of vested tokens to withdraw function calcMaxWithdraw() public constant returns (uint256) { uint256 maxTokens = 0; Disbursement[] storage temp = disbursements[msg.sender]; for (uint256 i = 0; i < temp.length; i++) { if (block.timestamp > temp[i].timestamp) { maxTokens = SafeMath.add(maxTokens, temp[i].tokens); } } maxTokens = SafeMath.sub(maxTokens, withdrawnTokens[msg.sender]); return maxTokens; } }
changeTimestamp
function changeTimestamp( address vestor, uint256 index, uint256 timestamp ) public onlyOwner { require(block.timestamp < timestamp); require(index < disbursements[vestor].length); disbursements[vestor][index].timestamp = timestamp; LogChangeTimestamp(vestor, index, timestamp); }
/// @dev Change an existing disbursement. /// @param vestor The address of the beneficiary. /// @param timestamp Funds will be locked until this timestamp. /// @param index Index of the DisbursementVesting in the vesting array.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1435, 1816 ] }
714
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
DisbursementHandler
contract DisbursementHandler is Ownable { struct Disbursement { uint256 timestamp; uint256 tokens; } event LogSetup(address indexed vestor, uint256 tokens, uint256 timestamp); event LogChangeTimestamp(address indexed vestor, uint256 index, uint256 timestamp); event LogWithdraw(address indexed to, uint256 value); ERC20 public token; mapping(address => Disbursement[]) public disbursements; mapping(address => uint256) public withdrawnTokens; function DisbursementHandler(address _token) public { token = ERC20(_token); } /// @dev Called by the sale contract to create a disbursement. /// @param vestor The address of the beneficiary. /// @param tokens Amount of tokens to be locked. /// @param timestamp Funds will be locked until this timestamp. function setupDisbursement( address vestor, uint256 tokens, uint256 timestamp ) public onlyOwner { require(block.timestamp < timestamp); disbursements[vestor].push(Disbursement(timestamp, tokens)); LogSetup(vestor, timestamp, tokens); } /// @dev Change an existing disbursement. /// @param vestor The address of the beneficiary. /// @param timestamp Funds will be locked until this timestamp. /// @param index Index of the DisbursementVesting in the vesting array. function changeTimestamp( address vestor, uint256 index, uint256 timestamp ) public onlyOwner { require(block.timestamp < timestamp); require(index < disbursements[vestor].length); disbursements[vestor][index].timestamp = timestamp; LogChangeTimestamp(vestor, index, timestamp); } /// @dev Transfers tokens to a given address /// @param to Address of token receiver /// @param value Number of tokens to transfer function withdraw(address to, uint256 value) public { uint256 maxTokens = calcMaxWithdraw(); uint256 withdrawAmount = value < maxTokens ? value : maxTokens; withdrawnTokens[msg.sender] = SafeMath.add(withdrawnTokens[msg.sender], withdrawAmount); token.transfer(to, withdrawAmount); LogWithdraw(to, value); } /// @dev Calculates the maximum amount of vested tokens /// @return Number of vested tokens to withdraw function calcMaxWithdraw() public constant returns (uint256) { uint256 maxTokens = 0; Disbursement[] storage temp = disbursements[msg.sender]; for (uint256 i = 0; i < temp.length; i++) { if (block.timestamp > temp[i].timestamp) { maxTokens = SafeMath.add(maxTokens, temp[i].tokens); } } maxTokens = SafeMath.sub(maxTokens, withdrawnTokens[msg.sender]); return maxTokens; } }
withdraw
function withdraw(address to, uint256 value) public { uint256 maxTokens = calcMaxWithdraw(); uint256 withdrawAmount = value < maxTokens ? value : maxTokens; withdrawnTokens[msg.sender] = SafeMath.add(withdrawnTokens[msg.sender], withdrawAmount); token.transfer(to, withdrawAmount); LogWithdraw(to, value); }
/// @dev Transfers tokens to a given address /// @param to Address of token receiver /// @param value Number of tokens to transfer
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1965, 2341 ] }
715
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
DisbursementHandler
contract DisbursementHandler is Ownable { struct Disbursement { uint256 timestamp; uint256 tokens; } event LogSetup(address indexed vestor, uint256 tokens, uint256 timestamp); event LogChangeTimestamp(address indexed vestor, uint256 index, uint256 timestamp); event LogWithdraw(address indexed to, uint256 value); ERC20 public token; mapping(address => Disbursement[]) public disbursements; mapping(address => uint256) public withdrawnTokens; function DisbursementHandler(address _token) public { token = ERC20(_token); } /// @dev Called by the sale contract to create a disbursement. /// @param vestor The address of the beneficiary. /// @param tokens Amount of tokens to be locked. /// @param timestamp Funds will be locked until this timestamp. function setupDisbursement( address vestor, uint256 tokens, uint256 timestamp ) public onlyOwner { require(block.timestamp < timestamp); disbursements[vestor].push(Disbursement(timestamp, tokens)); LogSetup(vestor, timestamp, tokens); } /// @dev Change an existing disbursement. /// @param vestor The address of the beneficiary. /// @param timestamp Funds will be locked until this timestamp. /// @param index Index of the DisbursementVesting in the vesting array. function changeTimestamp( address vestor, uint256 index, uint256 timestamp ) public onlyOwner { require(block.timestamp < timestamp); require(index < disbursements[vestor].length); disbursements[vestor][index].timestamp = timestamp; LogChangeTimestamp(vestor, index, timestamp); } /// @dev Transfers tokens to a given address /// @param to Address of token receiver /// @param value Number of tokens to transfer function withdraw(address to, uint256 value) public { uint256 maxTokens = calcMaxWithdraw(); uint256 withdrawAmount = value < maxTokens ? value : maxTokens; withdrawnTokens[msg.sender] = SafeMath.add(withdrawnTokens[msg.sender], withdrawAmount); token.transfer(to, withdrawAmount); LogWithdraw(to, value); } /// @dev Calculates the maximum amount of vested tokens /// @return Number of vested tokens to withdraw function calcMaxWithdraw() public constant returns (uint256) { uint256 maxTokens = 0; Disbursement[] storage temp = disbursements[msg.sender]; for (uint256 i = 0; i < temp.length; i++) { if (block.timestamp > temp[i].timestamp) { maxTokens = SafeMath.add(maxTokens, temp[i].tokens); } } maxTokens = SafeMath.sub(maxTokens, withdrawnTokens[msg.sender]); return maxTokens; } }
calcMaxWithdraw
function calcMaxWithdraw() public constant returns (uint256) { uint256 maxTokens = 0; Disbursement[] storage temp = disbursements[msg.sender]; for (uint256 i = 0; i < temp.length; i++) { if (block.timestamp > temp[i].timestamp) { maxTokens = SafeMath.add(maxTokens, temp[i].tokens); } } maxTokens = SafeMath.sub(maxTokens, withdrawnTokens[msg.sender]); return maxTokens; }
/// @dev Calculates the maximum amount of vested tokens /// @return Number of vested tokens to withdraw
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 2458, 2969 ] }
716
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StateMachineLib
library StateMachineLib { struct Stage { // The id of the next stage bytes32 nextId; // The identifiers for the available functions in each stage mapping(bytes4 => bool) allowedFunctions; } struct State { // The current stage id bytes32 currentStageId; // A callback that is called when entering this stage function(bytes32) internal onTransition; // Checks if a stage id is valid mapping(bytes32 => bool) validStage; // Maps stage ids to their Stage structs mapping(bytes32 => Stage) stages; } /// @dev Creates and sets the initial stage. It has to be called before creating any transitions. /// @param stageId The id of the (new) stage to set as initial stage. function setInitialStage(State storage self, bytes32 stageId) internal { self.validStage[stageId] = true; self.currentStageId = stageId; } /// @dev Creates a transition from 'fromId' to 'toId'. If fromId already had a nextId, it deletes the now unreachable stage. /// @param fromId The id of the stage from which the transition begins. /// @param toId The id of the stage that will be reachable from "fromId". function createTransition(State storage self, bytes32 fromId, bytes32 toId) internal { require(self.validStage[fromId]); Stage storage from = self.stages[fromId]; // Invalidate the stage that won't be reachable any more if (from.nextId != 0) { self.validStage[from.nextId] = false; delete self.stages[from.nextId]; } from.nextId = toId; self.validStage[toId] = true; } /// @dev Goes to the next stage if posible (if the next stage is valid) function goToNextStage(State storage self) internal { Stage storage current = self.stages[self.currentStageId]; require(self.validStage[current.nextId]); self.currentStageId = current.nextId; self.onTransition(current.nextId); } /// @dev Checks if the a function is allowed in the current stage. /// @param selector A function selector (bytes4[keccak256(functionSignature)]) /// @return true If the function is allowed in the current stage function checkAllowedFunction(State storage self, bytes4 selector) internal constant returns(bool) { return self.stages[self.currentStageId].allowedFunctions[selector]; } /// @dev Allow a function in the given stage. /// @param stageId The id of the stage /// @param selector A function selector (bytes4[keccak256(functionSignature)]) function allowFunction(State storage self, bytes32 stageId, bytes4 selector) internal { require(self.validStage[stageId]); self.stages[stageId].allowedFunctions[selector] = true; } }
setInitialStage
function setInitialStage(State storage self, bytes32 stageId) internal { self.validStage[stageId] = true; self.currentStageId = stageId; }
/// @dev Creates and sets the initial stage. It has to be called before creating any transitions. /// @param stageId The id of the (new) stage to set as initial stage.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 816, 982 ] }
717
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StateMachineLib
library StateMachineLib { struct Stage { // The id of the next stage bytes32 nextId; // The identifiers for the available functions in each stage mapping(bytes4 => bool) allowedFunctions; } struct State { // The current stage id bytes32 currentStageId; // A callback that is called when entering this stage function(bytes32) internal onTransition; // Checks if a stage id is valid mapping(bytes32 => bool) validStage; // Maps stage ids to their Stage structs mapping(bytes32 => Stage) stages; } /// @dev Creates and sets the initial stage. It has to be called before creating any transitions. /// @param stageId The id of the (new) stage to set as initial stage. function setInitialStage(State storage self, bytes32 stageId) internal { self.validStage[stageId] = true; self.currentStageId = stageId; } /// @dev Creates a transition from 'fromId' to 'toId'. If fromId already had a nextId, it deletes the now unreachable stage. /// @param fromId The id of the stage from which the transition begins. /// @param toId The id of the stage that will be reachable from "fromId". function createTransition(State storage self, bytes32 fromId, bytes32 toId) internal { require(self.validStage[fromId]); Stage storage from = self.stages[fromId]; // Invalidate the stage that won't be reachable any more if (from.nextId != 0) { self.validStage[from.nextId] = false; delete self.stages[from.nextId]; } from.nextId = toId; self.validStage[toId] = true; } /// @dev Goes to the next stage if posible (if the next stage is valid) function goToNextStage(State storage self) internal { Stage storage current = self.stages[self.currentStageId]; require(self.validStage[current.nextId]); self.currentStageId = current.nextId; self.onTransition(current.nextId); } /// @dev Checks if the a function is allowed in the current stage. /// @param selector A function selector (bytes4[keccak256(functionSignature)]) /// @return true If the function is allowed in the current stage function checkAllowedFunction(State storage self, bytes4 selector) internal constant returns(bool) { return self.stages[self.currentStageId].allowedFunctions[selector]; } /// @dev Allow a function in the given stage. /// @param stageId The id of the stage /// @param selector A function selector (bytes4[keccak256(functionSignature)]) function allowFunction(State storage self, bytes32 stageId, bytes4 selector) internal { require(self.validStage[stageId]); self.stages[stageId].allowedFunctions[selector] = true; } }
createTransition
function createTransition(State storage self, bytes32 fromId, bytes32 toId) internal { require(self.validStage[fromId]); Stage storage from = self.stages[fromId]; // Invalidate the stage that won't be reachable any more if (from.nextId != 0) { self.validStage[from.nextId] = false; delete self.stages[from.nextId]; } from.nextId = toId; self.validStage[toId] = true; }
/// @dev Creates a transition from 'fromId' to 'toId'. If fromId already had a nextId, it deletes the now unreachable stage. /// @param fromId The id of the stage from which the transition begins. /// @param toId The id of the stage that will be reachable from "fromId".
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1271, 1744 ] }
718
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StateMachineLib
library StateMachineLib { struct Stage { // The id of the next stage bytes32 nextId; // The identifiers for the available functions in each stage mapping(bytes4 => bool) allowedFunctions; } struct State { // The current stage id bytes32 currentStageId; // A callback that is called when entering this stage function(bytes32) internal onTransition; // Checks if a stage id is valid mapping(bytes32 => bool) validStage; // Maps stage ids to their Stage structs mapping(bytes32 => Stage) stages; } /// @dev Creates and sets the initial stage. It has to be called before creating any transitions. /// @param stageId The id of the (new) stage to set as initial stage. function setInitialStage(State storage self, bytes32 stageId) internal { self.validStage[stageId] = true; self.currentStageId = stageId; } /// @dev Creates a transition from 'fromId' to 'toId'. If fromId already had a nextId, it deletes the now unreachable stage. /// @param fromId The id of the stage from which the transition begins. /// @param toId The id of the stage that will be reachable from "fromId". function createTransition(State storage self, bytes32 fromId, bytes32 toId) internal { require(self.validStage[fromId]); Stage storage from = self.stages[fromId]; // Invalidate the stage that won't be reachable any more if (from.nextId != 0) { self.validStage[from.nextId] = false; delete self.stages[from.nextId]; } from.nextId = toId; self.validStage[toId] = true; } /// @dev Goes to the next stage if posible (if the next stage is valid) function goToNextStage(State storage self) internal { Stage storage current = self.stages[self.currentStageId]; require(self.validStage[current.nextId]); self.currentStageId = current.nextId; self.onTransition(current.nextId); } /// @dev Checks if the a function is allowed in the current stage. /// @param selector A function selector (bytes4[keccak256(functionSignature)]) /// @return true If the function is allowed in the current stage function checkAllowedFunction(State storage self, bytes4 selector) internal constant returns(bool) { return self.stages[self.currentStageId].allowedFunctions[selector]; } /// @dev Allow a function in the given stage. /// @param stageId The id of the stage /// @param selector A function selector (bytes4[keccak256(functionSignature)]) function allowFunction(State storage self, bytes32 stageId, bytes4 selector) internal { require(self.validStage[stageId]); self.stages[stageId].allowedFunctions[selector] = true; } }
goToNextStage
function goToNextStage(State storage self) internal { Stage storage current = self.stages[self.currentStageId]; require(self.validStage[current.nextId]); self.currentStageId = current.nextId; self.onTransition(current.nextId); }
/// @dev Goes to the next stage if posible (if the next stage is valid)
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1824, 2104 ] }
719
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StateMachineLib
library StateMachineLib { struct Stage { // The id of the next stage bytes32 nextId; // The identifiers for the available functions in each stage mapping(bytes4 => bool) allowedFunctions; } struct State { // The current stage id bytes32 currentStageId; // A callback that is called when entering this stage function(bytes32) internal onTransition; // Checks if a stage id is valid mapping(bytes32 => bool) validStage; // Maps stage ids to their Stage structs mapping(bytes32 => Stage) stages; } /// @dev Creates and sets the initial stage. It has to be called before creating any transitions. /// @param stageId The id of the (new) stage to set as initial stage. function setInitialStage(State storage self, bytes32 stageId) internal { self.validStage[stageId] = true; self.currentStageId = stageId; } /// @dev Creates a transition from 'fromId' to 'toId'. If fromId already had a nextId, it deletes the now unreachable stage. /// @param fromId The id of the stage from which the transition begins. /// @param toId The id of the stage that will be reachable from "fromId". function createTransition(State storage self, bytes32 fromId, bytes32 toId) internal { require(self.validStage[fromId]); Stage storage from = self.stages[fromId]; // Invalidate the stage that won't be reachable any more if (from.nextId != 0) { self.validStage[from.nextId] = false; delete self.stages[from.nextId]; } from.nextId = toId; self.validStage[toId] = true; } /// @dev Goes to the next stage if posible (if the next stage is valid) function goToNextStage(State storage self) internal { Stage storage current = self.stages[self.currentStageId]; require(self.validStage[current.nextId]); self.currentStageId = current.nextId; self.onTransition(current.nextId); } /// @dev Checks if the a function is allowed in the current stage. /// @param selector A function selector (bytes4[keccak256(functionSignature)]) /// @return true If the function is allowed in the current stage function checkAllowedFunction(State storage self, bytes4 selector) internal constant returns(bool) { return self.stages[self.currentStageId].allowedFunctions[selector]; } /// @dev Allow a function in the given stage. /// @param stageId The id of the stage /// @param selector A function selector (bytes4[keccak256(functionSignature)]) function allowFunction(State storage self, bytes32 stageId, bytes4 selector) internal { require(self.validStage[stageId]); self.stages[stageId].allowedFunctions[selector] = true; } }
checkAllowedFunction
function checkAllowedFunction(State storage self, bytes4 selector) internal constant returns(bool) { return self.stages[self.currentStageId].allowedFunctions[selector]; }
/// @dev Checks if the a function is allowed in the current stage. /// @param selector A function selector (bytes4[keccak256(functionSignature)]) /// @return true If the function is allowed in the current stage
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 2333, 2522 ] }
720
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StateMachineLib
library StateMachineLib { struct Stage { // The id of the next stage bytes32 nextId; // The identifiers for the available functions in each stage mapping(bytes4 => bool) allowedFunctions; } struct State { // The current stage id bytes32 currentStageId; // A callback that is called when entering this stage function(bytes32) internal onTransition; // Checks if a stage id is valid mapping(bytes32 => bool) validStage; // Maps stage ids to their Stage structs mapping(bytes32 => Stage) stages; } /// @dev Creates and sets the initial stage. It has to be called before creating any transitions. /// @param stageId The id of the (new) stage to set as initial stage. function setInitialStage(State storage self, bytes32 stageId) internal { self.validStage[stageId] = true; self.currentStageId = stageId; } /// @dev Creates a transition from 'fromId' to 'toId'. If fromId already had a nextId, it deletes the now unreachable stage. /// @param fromId The id of the stage from which the transition begins. /// @param toId The id of the stage that will be reachable from "fromId". function createTransition(State storage self, bytes32 fromId, bytes32 toId) internal { require(self.validStage[fromId]); Stage storage from = self.stages[fromId]; // Invalidate the stage that won't be reachable any more if (from.nextId != 0) { self.validStage[from.nextId] = false; delete self.stages[from.nextId]; } from.nextId = toId; self.validStage[toId] = true; } /// @dev Goes to the next stage if posible (if the next stage is valid) function goToNextStage(State storage self) internal { Stage storage current = self.stages[self.currentStageId]; require(self.validStage[current.nextId]); self.currentStageId = current.nextId; self.onTransition(current.nextId); } /// @dev Checks if the a function is allowed in the current stage. /// @param selector A function selector (bytes4[keccak256(functionSignature)]) /// @return true If the function is allowed in the current stage function checkAllowedFunction(State storage self, bytes4 selector) internal constant returns(bool) { return self.stages[self.currentStageId].allowedFunctions[selector]; } /// @dev Allow a function in the given stage. /// @param stageId The id of the stage /// @param selector A function selector (bytes4[keccak256(functionSignature)]) function allowFunction(State storage self, bytes32 stageId, bytes4 selector) internal { require(self.validStage[stageId]); self.stages[stageId].allowedFunctions[selector] = true; } }
allowFunction
function allowFunction(State storage self, bytes32 stageId, bytes4 selector) internal { require(self.validStage[stageId]); self.stages[stageId].allowedFunctions[selector] = true; }
/// @dev Allow a function in the given stage. /// @param stageId The id of the stage /// @param selector A function selector (bytes4[keccak256(functionSignature)])
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 2704, 2912 ] }
721
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StateMachine
contract StateMachine { using StateMachineLib for StateMachineLib.State; event LogTransition(bytes32 indexed stageId, uint256 blockNumber); StateMachineLib.State internal state; /* This modifier performs the conditional transitions and checks that the function * to be executed is allowed in the current stage */ modifier checkAllowed { conditionalTransitions(); require(state.checkAllowedFunction(msg.sig)); _; } function StateMachine() public { // Register the startConditions function and the onTransition callback state.onTransition = onTransition; } /// @dev Gets the current stage id. /// @return The current stage id. function getCurrentStageId() public view returns(bytes32) { return state.currentStageId; } /// @dev Performs conditional transitions. Can be called by anyone. function conditionalTransitions() public { bytes32 nextId = state.stages[state.currentStageId].nextId; while (state.validStage[nextId]) { StateMachineLib.Stage storage next = state.stages[nextId]; // If the next stage's condition is true, go to next stage and continue if (startConditions(nextId)) { state.goToNextStage(); nextId = next.nextId; } else { break; } } } /// @dev Determines whether the conditions for transitioning to the given stage are met. /// @return true if the conditions are met for the given stageId. False by default (must override in child contracts). function startConditions(bytes32) internal constant returns(bool) { return false; } /// @dev Callback called when there is a stage transition. It should be overridden for additional functionality. function onTransition(bytes32 stageId) internal { LogTransition(stageId, block.number); } }
getCurrentStageId
function getCurrentStageId() public view returns(bytes32) { return state.currentStageId; }
/// @dev Gets the current stage id. /// @return The current stage id.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 744, 853 ] }
722
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StateMachine
contract StateMachine { using StateMachineLib for StateMachineLib.State; event LogTransition(bytes32 indexed stageId, uint256 blockNumber); StateMachineLib.State internal state; /* This modifier performs the conditional transitions and checks that the function * to be executed is allowed in the current stage */ modifier checkAllowed { conditionalTransitions(); require(state.checkAllowedFunction(msg.sig)); _; } function StateMachine() public { // Register the startConditions function and the onTransition callback state.onTransition = onTransition; } /// @dev Gets the current stage id. /// @return The current stage id. function getCurrentStageId() public view returns(bytes32) { return state.currentStageId; } /// @dev Performs conditional transitions. Can be called by anyone. function conditionalTransitions() public { bytes32 nextId = state.stages[state.currentStageId].nextId; while (state.validStage[nextId]) { StateMachineLib.Stage storage next = state.stages[nextId]; // If the next stage's condition is true, go to next stage and continue if (startConditions(nextId)) { state.goToNextStage(); nextId = next.nextId; } else { break; } } } /// @dev Determines whether the conditions for transitioning to the given stage are met. /// @return true if the conditions are met for the given stageId. False by default (must override in child contracts). function startConditions(bytes32) internal constant returns(bool) { return false; } /// @dev Callback called when there is a stage transition. It should be overridden for additional functionality. function onTransition(bytes32 stageId) internal { LogTransition(stageId, block.number); } }
conditionalTransitions
function conditionalTransitions() public { bytes32 nextId = state.stages[state.currentStageId].nextId; while (state.validStage[nextId]) { StateMachineLib.Stage storage next = state.stages[nextId]; // If the next stage's condition is true, go to next stage and continue if (startConditions(nextId)) { state.goToNextStage(); nextId = next.nextId; } else { break; } } }
/// @dev Performs conditional transitions. Can be called by anyone.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 929, 1452 ] }
723
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StateMachine
contract StateMachine { using StateMachineLib for StateMachineLib.State; event LogTransition(bytes32 indexed stageId, uint256 blockNumber); StateMachineLib.State internal state; /* This modifier performs the conditional transitions and checks that the function * to be executed is allowed in the current stage */ modifier checkAllowed { conditionalTransitions(); require(state.checkAllowedFunction(msg.sig)); _; } function StateMachine() public { // Register the startConditions function and the onTransition callback state.onTransition = onTransition; } /// @dev Gets the current stage id. /// @return The current stage id. function getCurrentStageId() public view returns(bytes32) { return state.currentStageId; } /// @dev Performs conditional transitions. Can be called by anyone. function conditionalTransitions() public { bytes32 nextId = state.stages[state.currentStageId].nextId; while (state.validStage[nextId]) { StateMachineLib.Stage storage next = state.stages[nextId]; // If the next stage's condition is true, go to next stage and continue if (startConditions(nextId)) { state.goToNextStage(); nextId = next.nextId; } else { break; } } } /// @dev Determines whether the conditions for transitioning to the given stage are met. /// @return true if the conditions are met for the given stageId. False by default (must override in child contracts). function startConditions(bytes32) internal constant returns(bool) { return false; } /// @dev Callback called when there is a stage transition. It should be overridden for additional functionality. function onTransition(bytes32 stageId) internal { LogTransition(stageId, block.number); } }
startConditions
function startConditions(bytes32) internal constant returns(bool) { return false; }
/// @dev Determines whether the conditions for transitioning to the given stage are met. /// @return true if the conditions are met for the given stageId. False by default (must override in child contracts).
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1673, 1775 ] }
724
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
StateMachine
contract StateMachine { using StateMachineLib for StateMachineLib.State; event LogTransition(bytes32 indexed stageId, uint256 blockNumber); StateMachineLib.State internal state; /* This modifier performs the conditional transitions and checks that the function * to be executed is allowed in the current stage */ modifier checkAllowed { conditionalTransitions(); require(state.checkAllowedFunction(msg.sig)); _; } function StateMachine() public { // Register the startConditions function and the onTransition callback state.onTransition = onTransition; } /// @dev Gets the current stage id. /// @return The current stage id. function getCurrentStageId() public view returns(bytes32) { return state.currentStageId; } /// @dev Performs conditional transitions. Can be called by anyone. function conditionalTransitions() public { bytes32 nextId = state.stages[state.currentStageId].nextId; while (state.validStage[nextId]) { StateMachineLib.Stage storage next = state.stages[nextId]; // If the next stage's condition is true, go to next stage and continue if (startConditions(nextId)) { state.goToNextStage(); nextId = next.nextId; } else { break; } } } /// @dev Determines whether the conditions for transitioning to the given stage are met. /// @return true if the conditions are met for the given stageId. False by default (must override in child contracts). function startConditions(bytes32) internal constant returns(bool) { return false; } /// @dev Callback called when there is a stage transition. It should be overridden for additional functionality. function onTransition(bytes32 stageId) internal { LogTransition(stageId, block.number); } }
onTransition
function onTransition(bytes32 stageId) internal { LogTransition(stageId, block.number); }
/// @dev Callback called when there is a stage transition. It should be overridden for additional functionality.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1896, 2004 ] }
725
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
TimedStateMachine
contract TimedStateMachine is StateMachine { event LogSetStageStartTime(bytes32 indexed stageId, uint256 startTime); // Stores the start timestamp for each stage (the value is 0 if the stage doesn't have a start timestamp). mapping(bytes32 => uint256) internal startTime; /// @dev This function overrides the startConditions function in the parent contract in order to enable automatic transitions that depend on the timestamp. function startConditions(bytes32 stageId) internal constant returns(bool) { // Get the startTime for stage uint256 start = startTime[stageId]; // If the startTime is set and has already passed, return true. return start != 0 && block.timestamp > start; } /// @dev Sets the starting timestamp for a stage. /// @param stageId The id of the stage for which we want to set the start timestamp. /// @param timestamp The start timestamp for the given stage. It should be bigger than the current one. function setStageStartTime(bytes32 stageId, uint256 timestamp) internal { require(state.validStage[stageId]); require(timestamp > block.timestamp); startTime[stageId] = timestamp; LogSetStageStartTime(stageId, timestamp); } /// @dev Returns the timestamp for the given stage id. /// @param stageId The id of the stage for which we want to set the start timestamp. function getStageStartTime(bytes32 stageId) public view returns(uint256) { return startTime[stageId]; } }
startConditions
function startConditions(bytes32 stageId) internal constant returns(bool) { // Get the startTime for stage uint256 start = startTime[stageId]; // If the startTime is set and has already passed, return true. return start != 0 && block.timestamp > start; }
/// @dev This function overrides the startConditions function in the parent contract in order to enable automatic transitions that depend on the timestamp.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 455, 755 ] }
726
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
TimedStateMachine
contract TimedStateMachine is StateMachine { event LogSetStageStartTime(bytes32 indexed stageId, uint256 startTime); // Stores the start timestamp for each stage (the value is 0 if the stage doesn't have a start timestamp). mapping(bytes32 => uint256) internal startTime; /// @dev This function overrides the startConditions function in the parent contract in order to enable automatic transitions that depend on the timestamp. function startConditions(bytes32 stageId) internal constant returns(bool) { // Get the startTime for stage uint256 start = startTime[stageId]; // If the startTime is set and has already passed, return true. return start != 0 && block.timestamp > start; } /// @dev Sets the starting timestamp for a stage. /// @param stageId The id of the stage for which we want to set the start timestamp. /// @param timestamp The start timestamp for the given stage. It should be bigger than the current one. function setStageStartTime(bytes32 stageId, uint256 timestamp) internal { require(state.validStage[stageId]); require(timestamp > block.timestamp); startTime[stageId] = timestamp; LogSetStageStartTime(stageId, timestamp); } /// @dev Returns the timestamp for the given stage id. /// @param stageId The id of the stage for which we want to set the start timestamp. function getStageStartTime(bytes32 stageId) public view returns(uint256) { return startTime[stageId]; } }
setStageStartTime
function setStageStartTime(bytes32 stageId, uint256 timestamp) internal { require(state.validStage[stageId]); require(timestamp > block.timestamp); startTime[stageId] = timestamp; LogSetStageStartTime(stageId, timestamp); }
/// @dev Sets the starting timestamp for a stage. /// @param stageId The id of the stage for which we want to set the start timestamp. /// @param timestamp The start timestamp for the given stage. It should be bigger than the current one.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1012, 1283 ] }
727
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
TimedStateMachine
contract TimedStateMachine is StateMachine { event LogSetStageStartTime(bytes32 indexed stageId, uint256 startTime); // Stores the start timestamp for each stage (the value is 0 if the stage doesn't have a start timestamp). mapping(bytes32 => uint256) internal startTime; /// @dev This function overrides the startConditions function in the parent contract in order to enable automatic transitions that depend on the timestamp. function startConditions(bytes32 stageId) internal constant returns(bool) { // Get the startTime for stage uint256 start = startTime[stageId]; // If the startTime is set and has already passed, return true. return start != 0 && block.timestamp > start; } /// @dev Sets the starting timestamp for a stage. /// @param stageId The id of the stage for which we want to set the start timestamp. /// @param timestamp The start timestamp for the given stage. It should be bigger than the current one. function setStageStartTime(bytes32 stageId, uint256 timestamp) internal { require(state.validStage[stageId]); require(timestamp > block.timestamp); startTime[stageId] = timestamp; LogSetStageStartTime(stageId, timestamp); } /// @dev Returns the timestamp for the given stage id. /// @param stageId The id of the stage for which we want to set the start timestamp. function getStageStartTime(bytes32 stageId) public view returns(uint256) { return startTime[stageId]; } }
getStageStartTime
function getStageStartTime(bytes32 stageId) public view returns(uint256) { return startTime[stageId]; }
/// @dev Returns the timestamp for the given stage id. /// @param stageId The id of the stage for which we want to set the start timestamp.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1436, 1558 ] }
728
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
Sale
contract Sale is Ownable, TimedStateMachine { using SafeMath for uint256; event LogContribution(address indexed contributor, uint256 amountSent, uint256 excessRefunded); event LogTokenAllocation(address indexed contributor, uint256 contribution, uint256 tokens); event LogDisbursement(address indexed beneficiary, uint256 tokens); // Stages for the state machine bytes32 public constant SETUP = "setup"; bytes32 public constant SETUP_DONE = "setupDone"; bytes32 public constant SALE_IN_PROGRESS = "saleInProgress"; bytes32 public constant SALE_ENDED = "saleEnded"; mapping(address => uint256) public contributions; uint256 public weiContributed = 0; uint256 public contributionCap; // Wallet where funds will be sent address public wallet; MintableToken public token; DisbursementHandler public disbursementHandler; function Sale( address _wallet, uint256 _contributionCap ) public { require(_wallet != 0); require(_contributionCap != 0); wallet = _wallet; token = createTokenContract(); disbursementHandler = new DisbursementHandler(token); contributionCap = _contributionCap; setupStages(); } function() external payable { contribute(); } /// @dev Sets the start timestamp for the SALE_IN_PROGRESS stage. /// @param timestamp The start timestamp. function setSaleStartTime(uint256 timestamp) external onlyOwner checkAllowed { // require(_startTime < getStageStartTime(SALE_ENDED)); setStageStartTime(SALE_IN_PROGRESS, timestamp); } /// @dev Sets the start timestamp for the SALE_ENDED stage. /// @param timestamp The start timestamp. function setSaleEndTime(uint256 timestamp) external onlyOwner checkAllowed { require(getStageStartTime(SALE_IN_PROGRESS) < timestamp); setStageStartTime(SALE_ENDED, timestamp); } /// @dev Called in the SETUP stage, check configurations and to go to the SETUP_DONE stage. function setupDone() public onlyOwner checkAllowed { uint256 _startTime = getStageStartTime(SALE_IN_PROGRESS); uint256 _endTime = getStageStartTime(SALE_ENDED); require(block.timestamp < _startTime); require(_startTime < _endTime); state.goToNextStage(); } /// @dev Called by users to contribute ETH to the sale. function contribute() public payable checkAllowed { require(msg.value > 0); uint256 contributionLimit = getContributionLimit(msg.sender); require(contributionLimit > 0); // Check that the user is allowed to contribute uint256 totalContribution = contributions[msg.sender].add(msg.value); uint256 excess = 0; // Check if it goes over the eth cap for the sale. if (weiContributed.add(msg.value) > contributionCap) { // Subtract the excess excess = weiContributed.add(msg.value).sub(contributionCap); totalContribution = totalContribution.sub(excess); } // Check if it goes over the contribution limit of the user. if (totalContribution > contributionLimit) { excess = excess.add(totalContribution).sub(contributionLimit); contributions[msg.sender] = contributionLimit; } else { contributions[msg.sender] = totalContribution; } // We are only able to refund up to msg.value because the contract will not contain ether // excess = excess < msg.value ? excess : msg.value; require(excess <= msg.value); weiContributed = weiContributed.add(msg.value).sub(excess); if (excess > 0) { msg.sender.transfer(excess); } wallet.transfer(this.balance); assert(contributions[msg.sender] <= contributionLimit); LogContribution(msg.sender, msg.value, excess); } /// @dev Create a disbursement of tokens. /// @param beneficiary The beneficiary of the disbursement. /// @param tokenAmount Amount of tokens to be locked. /// @param timestamp Tokens will be locked until this timestamp. function distributeTimelockedTokens( address beneficiary, uint256 tokenAmount, uint256 timestamp ) public onlyOwner checkAllowed { disbursementHandler.setupDisbursement( beneficiary, tokenAmount, timestamp ); token.mint(disbursementHandler, tokenAmount); LogDisbursement(beneficiary, tokenAmount); } function setupStages() internal { // Set the stages state.setInitialStage(SETUP); state.createTransition(SETUP, SETUP_DONE); state.createTransition(SETUP_DONE, SALE_IN_PROGRESS); state.createTransition(SALE_IN_PROGRESS, SALE_ENDED); state.allowFunction(SETUP, this.distributeTimelockedTokens.selector); state.allowFunction(SETUP, this.setSaleStartTime.selector); state.allowFunction(SETUP, this.setSaleEndTime.selector); state.allowFunction(SETUP, this.setupDone.selector); state.allowFunction(SALE_IN_PROGRESS, this.contribute.selector); state.allowFunction(SALE_IN_PROGRESS, 0); // fallback } // Override in the child sales function createTokenContract() internal returns (MintableToken); function getContributionLimit(address userAddress) public view returns (uint256); /// @dev Stage start conditions. function startConditions(bytes32 stageId) internal constant returns (bool) { // If the cap has been reached, end the sale. if (stageId == SALE_ENDED && contributionCap <= weiContributed) { return true; } return super.startConditions(stageId); } /// @dev State transitions callbacks. function onTransition(bytes32 stageId) internal { if (stageId == SALE_ENDED) { onSaleEnded(); } super.onTransition(stageId); } /// @dev Callback that gets called when entering the SALE_ENDED stage. function onSaleEnded() internal {} }
setSaleStartTime
function setSaleStartTime(uint256 timestamp) external onlyOwner checkAllowed { // require(_startTime < getStageStartTime(SALE_ENDED)); setStageStartTime(SALE_IN_PROGRESS, timestamp); }
/// @dev Sets the start timestamp for the SALE_IN_PROGRESS stage. /// @param timestamp The start timestamp.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1500, 1747 ] }
729
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
Sale
contract Sale is Ownable, TimedStateMachine { using SafeMath for uint256; event LogContribution(address indexed contributor, uint256 amountSent, uint256 excessRefunded); event LogTokenAllocation(address indexed contributor, uint256 contribution, uint256 tokens); event LogDisbursement(address indexed beneficiary, uint256 tokens); // Stages for the state machine bytes32 public constant SETUP = "setup"; bytes32 public constant SETUP_DONE = "setupDone"; bytes32 public constant SALE_IN_PROGRESS = "saleInProgress"; bytes32 public constant SALE_ENDED = "saleEnded"; mapping(address => uint256) public contributions; uint256 public weiContributed = 0; uint256 public contributionCap; // Wallet where funds will be sent address public wallet; MintableToken public token; DisbursementHandler public disbursementHandler; function Sale( address _wallet, uint256 _contributionCap ) public { require(_wallet != 0); require(_contributionCap != 0); wallet = _wallet; token = createTokenContract(); disbursementHandler = new DisbursementHandler(token); contributionCap = _contributionCap; setupStages(); } function() external payable { contribute(); } /// @dev Sets the start timestamp for the SALE_IN_PROGRESS stage. /// @param timestamp The start timestamp. function setSaleStartTime(uint256 timestamp) external onlyOwner checkAllowed { // require(_startTime < getStageStartTime(SALE_ENDED)); setStageStartTime(SALE_IN_PROGRESS, timestamp); } /// @dev Sets the start timestamp for the SALE_ENDED stage. /// @param timestamp The start timestamp. function setSaleEndTime(uint256 timestamp) external onlyOwner checkAllowed { require(getStageStartTime(SALE_IN_PROGRESS) < timestamp); setStageStartTime(SALE_ENDED, timestamp); } /// @dev Called in the SETUP stage, check configurations and to go to the SETUP_DONE stage. function setupDone() public onlyOwner checkAllowed { uint256 _startTime = getStageStartTime(SALE_IN_PROGRESS); uint256 _endTime = getStageStartTime(SALE_ENDED); require(block.timestamp < _startTime); require(_startTime < _endTime); state.goToNextStage(); } /// @dev Called by users to contribute ETH to the sale. function contribute() public payable checkAllowed { require(msg.value > 0); uint256 contributionLimit = getContributionLimit(msg.sender); require(contributionLimit > 0); // Check that the user is allowed to contribute uint256 totalContribution = contributions[msg.sender].add(msg.value); uint256 excess = 0; // Check if it goes over the eth cap for the sale. if (weiContributed.add(msg.value) > contributionCap) { // Subtract the excess excess = weiContributed.add(msg.value).sub(contributionCap); totalContribution = totalContribution.sub(excess); } // Check if it goes over the contribution limit of the user. if (totalContribution > contributionLimit) { excess = excess.add(totalContribution).sub(contributionLimit); contributions[msg.sender] = contributionLimit; } else { contributions[msg.sender] = totalContribution; } // We are only able to refund up to msg.value because the contract will not contain ether // excess = excess < msg.value ? excess : msg.value; require(excess <= msg.value); weiContributed = weiContributed.add(msg.value).sub(excess); if (excess > 0) { msg.sender.transfer(excess); } wallet.transfer(this.balance); assert(contributions[msg.sender] <= contributionLimit); LogContribution(msg.sender, msg.value, excess); } /// @dev Create a disbursement of tokens. /// @param beneficiary The beneficiary of the disbursement. /// @param tokenAmount Amount of tokens to be locked. /// @param timestamp Tokens will be locked until this timestamp. function distributeTimelockedTokens( address beneficiary, uint256 tokenAmount, uint256 timestamp ) public onlyOwner checkAllowed { disbursementHandler.setupDisbursement( beneficiary, tokenAmount, timestamp ); token.mint(disbursementHandler, tokenAmount); LogDisbursement(beneficiary, tokenAmount); } function setupStages() internal { // Set the stages state.setInitialStage(SETUP); state.createTransition(SETUP, SETUP_DONE); state.createTransition(SETUP_DONE, SALE_IN_PROGRESS); state.createTransition(SALE_IN_PROGRESS, SALE_ENDED); state.allowFunction(SETUP, this.distributeTimelockedTokens.selector); state.allowFunction(SETUP, this.setSaleStartTime.selector); state.allowFunction(SETUP, this.setSaleEndTime.selector); state.allowFunction(SETUP, this.setupDone.selector); state.allowFunction(SALE_IN_PROGRESS, this.contribute.selector); state.allowFunction(SALE_IN_PROGRESS, 0); // fallback } // Override in the child sales function createTokenContract() internal returns (MintableToken); function getContributionLimit(address userAddress) public view returns (uint256); /// @dev Stage start conditions. function startConditions(bytes32 stageId) internal constant returns (bool) { // If the cap has been reached, end the sale. if (stageId == SALE_ENDED && contributionCap <= weiContributed) { return true; } return super.startConditions(stageId); } /// @dev State transitions callbacks. function onTransition(bytes32 stageId) internal { if (stageId == SALE_ENDED) { onSaleEnded(); } super.onTransition(stageId); } /// @dev Callback that gets called when entering the SALE_ENDED stage. function onSaleEnded() internal {} }
setSaleEndTime
function setSaleEndTime(uint256 timestamp) external onlyOwner checkAllowed { require(getStageStartTime(SALE_IN_PROGRESS) < timestamp); setStageStartTime(SALE_ENDED, timestamp); }
/// @dev Sets the start timestamp for the SALE_ENDED stage. /// @param timestamp The start timestamp.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1862, 2103 ] }
730
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
Sale
contract Sale is Ownable, TimedStateMachine { using SafeMath for uint256; event LogContribution(address indexed contributor, uint256 amountSent, uint256 excessRefunded); event LogTokenAllocation(address indexed contributor, uint256 contribution, uint256 tokens); event LogDisbursement(address indexed beneficiary, uint256 tokens); // Stages for the state machine bytes32 public constant SETUP = "setup"; bytes32 public constant SETUP_DONE = "setupDone"; bytes32 public constant SALE_IN_PROGRESS = "saleInProgress"; bytes32 public constant SALE_ENDED = "saleEnded"; mapping(address => uint256) public contributions; uint256 public weiContributed = 0; uint256 public contributionCap; // Wallet where funds will be sent address public wallet; MintableToken public token; DisbursementHandler public disbursementHandler; function Sale( address _wallet, uint256 _contributionCap ) public { require(_wallet != 0); require(_contributionCap != 0); wallet = _wallet; token = createTokenContract(); disbursementHandler = new DisbursementHandler(token); contributionCap = _contributionCap; setupStages(); } function() external payable { contribute(); } /// @dev Sets the start timestamp for the SALE_IN_PROGRESS stage. /// @param timestamp The start timestamp. function setSaleStartTime(uint256 timestamp) external onlyOwner checkAllowed { // require(_startTime < getStageStartTime(SALE_ENDED)); setStageStartTime(SALE_IN_PROGRESS, timestamp); } /// @dev Sets the start timestamp for the SALE_ENDED stage. /// @param timestamp The start timestamp. function setSaleEndTime(uint256 timestamp) external onlyOwner checkAllowed { require(getStageStartTime(SALE_IN_PROGRESS) < timestamp); setStageStartTime(SALE_ENDED, timestamp); } /// @dev Called in the SETUP stage, check configurations and to go to the SETUP_DONE stage. function setupDone() public onlyOwner checkAllowed { uint256 _startTime = getStageStartTime(SALE_IN_PROGRESS); uint256 _endTime = getStageStartTime(SALE_ENDED); require(block.timestamp < _startTime); require(_startTime < _endTime); state.goToNextStage(); } /// @dev Called by users to contribute ETH to the sale. function contribute() public payable checkAllowed { require(msg.value > 0); uint256 contributionLimit = getContributionLimit(msg.sender); require(contributionLimit > 0); // Check that the user is allowed to contribute uint256 totalContribution = contributions[msg.sender].add(msg.value); uint256 excess = 0; // Check if it goes over the eth cap for the sale. if (weiContributed.add(msg.value) > contributionCap) { // Subtract the excess excess = weiContributed.add(msg.value).sub(contributionCap); totalContribution = totalContribution.sub(excess); } // Check if it goes over the contribution limit of the user. if (totalContribution > contributionLimit) { excess = excess.add(totalContribution).sub(contributionLimit); contributions[msg.sender] = contributionLimit; } else { contributions[msg.sender] = totalContribution; } // We are only able to refund up to msg.value because the contract will not contain ether // excess = excess < msg.value ? excess : msg.value; require(excess <= msg.value); weiContributed = weiContributed.add(msg.value).sub(excess); if (excess > 0) { msg.sender.transfer(excess); } wallet.transfer(this.balance); assert(contributions[msg.sender] <= contributionLimit); LogContribution(msg.sender, msg.value, excess); } /// @dev Create a disbursement of tokens. /// @param beneficiary The beneficiary of the disbursement. /// @param tokenAmount Amount of tokens to be locked. /// @param timestamp Tokens will be locked until this timestamp. function distributeTimelockedTokens( address beneficiary, uint256 tokenAmount, uint256 timestamp ) public onlyOwner checkAllowed { disbursementHandler.setupDisbursement( beneficiary, tokenAmount, timestamp ); token.mint(disbursementHandler, tokenAmount); LogDisbursement(beneficiary, tokenAmount); } function setupStages() internal { // Set the stages state.setInitialStage(SETUP); state.createTransition(SETUP, SETUP_DONE); state.createTransition(SETUP_DONE, SALE_IN_PROGRESS); state.createTransition(SALE_IN_PROGRESS, SALE_ENDED); state.allowFunction(SETUP, this.distributeTimelockedTokens.selector); state.allowFunction(SETUP, this.setSaleStartTime.selector); state.allowFunction(SETUP, this.setSaleEndTime.selector); state.allowFunction(SETUP, this.setupDone.selector); state.allowFunction(SALE_IN_PROGRESS, this.contribute.selector); state.allowFunction(SALE_IN_PROGRESS, 0); // fallback } // Override in the child sales function createTokenContract() internal returns (MintableToken); function getContributionLimit(address userAddress) public view returns (uint256); /// @dev Stage start conditions. function startConditions(bytes32 stageId) internal constant returns (bool) { // If the cap has been reached, end the sale. if (stageId == SALE_ENDED && contributionCap <= weiContributed) { return true; } return super.startConditions(stageId); } /// @dev State transitions callbacks. function onTransition(bytes32 stageId) internal { if (stageId == SALE_ENDED) { onSaleEnded(); } super.onTransition(stageId); } /// @dev Callback that gets called when entering the SALE_ENDED stage. function onSaleEnded() internal {} }
setupDone
function setupDone() public onlyOwner checkAllowed { uint256 _startTime = getStageStartTime(SALE_IN_PROGRESS); uint256 _endTime = getStageStartTime(SALE_ENDED); require(block.timestamp < _startTime); require(_startTime < _endTime); state.goToNextStage(); }
/// @dev Called in the SETUP stage, check configurations and to go to the SETUP_DONE stage.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 2203, 2551 ] }
731
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
Sale
contract Sale is Ownable, TimedStateMachine { using SafeMath for uint256; event LogContribution(address indexed contributor, uint256 amountSent, uint256 excessRefunded); event LogTokenAllocation(address indexed contributor, uint256 contribution, uint256 tokens); event LogDisbursement(address indexed beneficiary, uint256 tokens); // Stages for the state machine bytes32 public constant SETUP = "setup"; bytes32 public constant SETUP_DONE = "setupDone"; bytes32 public constant SALE_IN_PROGRESS = "saleInProgress"; bytes32 public constant SALE_ENDED = "saleEnded"; mapping(address => uint256) public contributions; uint256 public weiContributed = 0; uint256 public contributionCap; // Wallet where funds will be sent address public wallet; MintableToken public token; DisbursementHandler public disbursementHandler; function Sale( address _wallet, uint256 _contributionCap ) public { require(_wallet != 0); require(_contributionCap != 0); wallet = _wallet; token = createTokenContract(); disbursementHandler = new DisbursementHandler(token); contributionCap = _contributionCap; setupStages(); } function() external payable { contribute(); } /// @dev Sets the start timestamp for the SALE_IN_PROGRESS stage. /// @param timestamp The start timestamp. function setSaleStartTime(uint256 timestamp) external onlyOwner checkAllowed { // require(_startTime < getStageStartTime(SALE_ENDED)); setStageStartTime(SALE_IN_PROGRESS, timestamp); } /// @dev Sets the start timestamp for the SALE_ENDED stage. /// @param timestamp The start timestamp. function setSaleEndTime(uint256 timestamp) external onlyOwner checkAllowed { require(getStageStartTime(SALE_IN_PROGRESS) < timestamp); setStageStartTime(SALE_ENDED, timestamp); } /// @dev Called in the SETUP stage, check configurations and to go to the SETUP_DONE stage. function setupDone() public onlyOwner checkAllowed { uint256 _startTime = getStageStartTime(SALE_IN_PROGRESS); uint256 _endTime = getStageStartTime(SALE_ENDED); require(block.timestamp < _startTime); require(_startTime < _endTime); state.goToNextStage(); } /// @dev Called by users to contribute ETH to the sale. function contribute() public payable checkAllowed { require(msg.value > 0); uint256 contributionLimit = getContributionLimit(msg.sender); require(contributionLimit > 0); // Check that the user is allowed to contribute uint256 totalContribution = contributions[msg.sender].add(msg.value); uint256 excess = 0; // Check if it goes over the eth cap for the sale. if (weiContributed.add(msg.value) > contributionCap) { // Subtract the excess excess = weiContributed.add(msg.value).sub(contributionCap); totalContribution = totalContribution.sub(excess); } // Check if it goes over the contribution limit of the user. if (totalContribution > contributionLimit) { excess = excess.add(totalContribution).sub(contributionLimit); contributions[msg.sender] = contributionLimit; } else { contributions[msg.sender] = totalContribution; } // We are only able to refund up to msg.value because the contract will not contain ether // excess = excess < msg.value ? excess : msg.value; require(excess <= msg.value); weiContributed = weiContributed.add(msg.value).sub(excess); if (excess > 0) { msg.sender.transfer(excess); } wallet.transfer(this.balance); assert(contributions[msg.sender] <= contributionLimit); LogContribution(msg.sender, msg.value, excess); } /// @dev Create a disbursement of tokens. /// @param beneficiary The beneficiary of the disbursement. /// @param tokenAmount Amount of tokens to be locked. /// @param timestamp Tokens will be locked until this timestamp. function distributeTimelockedTokens( address beneficiary, uint256 tokenAmount, uint256 timestamp ) public onlyOwner checkAllowed { disbursementHandler.setupDisbursement( beneficiary, tokenAmount, timestamp ); token.mint(disbursementHandler, tokenAmount); LogDisbursement(beneficiary, tokenAmount); } function setupStages() internal { // Set the stages state.setInitialStage(SETUP); state.createTransition(SETUP, SETUP_DONE); state.createTransition(SETUP_DONE, SALE_IN_PROGRESS); state.createTransition(SALE_IN_PROGRESS, SALE_ENDED); state.allowFunction(SETUP, this.distributeTimelockedTokens.selector); state.allowFunction(SETUP, this.setSaleStartTime.selector); state.allowFunction(SETUP, this.setSaleEndTime.selector); state.allowFunction(SETUP, this.setupDone.selector); state.allowFunction(SALE_IN_PROGRESS, this.contribute.selector); state.allowFunction(SALE_IN_PROGRESS, 0); // fallback } // Override in the child sales function createTokenContract() internal returns (MintableToken); function getContributionLimit(address userAddress) public view returns (uint256); /// @dev Stage start conditions. function startConditions(bytes32 stageId) internal constant returns (bool) { // If the cap has been reached, end the sale. if (stageId == SALE_ENDED && contributionCap <= weiContributed) { return true; } return super.startConditions(stageId); } /// @dev State transitions callbacks. function onTransition(bytes32 stageId) internal { if (stageId == SALE_ENDED) { onSaleEnded(); } super.onTransition(stageId); } /// @dev Callback that gets called when entering the SALE_ENDED stage. function onSaleEnded() internal {} }
contribute
function contribute() public payable checkAllowed { require(msg.value > 0); uint256 contributionLimit = getContributionLimit(msg.sender); require(contributionLimit > 0); // Check that the user is allowed to contribute uint256 totalContribution = contributions[msg.sender].add(msg.value); uint256 excess = 0; // Check if it goes over the eth cap for the sale. if (weiContributed.add(msg.value) > contributionCap) { // Subtract the excess excess = weiContributed.add(msg.value).sub(contributionCap); totalContribution = totalContribution.sub(excess); } // Check if it goes over the contribution limit of the user. if (totalContribution > contributionLimit) { excess = excess.add(totalContribution).sub(contributionLimit); contributions[msg.sender] = contributionLimit; } else { contributions[msg.sender] = totalContribution; } // We are only able to refund up to msg.value because the contract will not contain ether // excess = excess < msg.value ? excess : msg.value; require(excess <= msg.value); weiContributed = weiContributed.add(msg.value).sub(excess); if (excess > 0) { msg.sender.transfer(excess); } wallet.transfer(this.balance); assert(contributions[msg.sender] <= contributionLimit); LogContribution(msg.sender, msg.value, excess); }
/// @dev Called by users to contribute ETH to the sale.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 2615, 4214 ] }
732
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
Sale
contract Sale is Ownable, TimedStateMachine { using SafeMath for uint256; event LogContribution(address indexed contributor, uint256 amountSent, uint256 excessRefunded); event LogTokenAllocation(address indexed contributor, uint256 contribution, uint256 tokens); event LogDisbursement(address indexed beneficiary, uint256 tokens); // Stages for the state machine bytes32 public constant SETUP = "setup"; bytes32 public constant SETUP_DONE = "setupDone"; bytes32 public constant SALE_IN_PROGRESS = "saleInProgress"; bytes32 public constant SALE_ENDED = "saleEnded"; mapping(address => uint256) public contributions; uint256 public weiContributed = 0; uint256 public contributionCap; // Wallet where funds will be sent address public wallet; MintableToken public token; DisbursementHandler public disbursementHandler; function Sale( address _wallet, uint256 _contributionCap ) public { require(_wallet != 0); require(_contributionCap != 0); wallet = _wallet; token = createTokenContract(); disbursementHandler = new DisbursementHandler(token); contributionCap = _contributionCap; setupStages(); } function() external payable { contribute(); } /// @dev Sets the start timestamp for the SALE_IN_PROGRESS stage. /// @param timestamp The start timestamp. function setSaleStartTime(uint256 timestamp) external onlyOwner checkAllowed { // require(_startTime < getStageStartTime(SALE_ENDED)); setStageStartTime(SALE_IN_PROGRESS, timestamp); } /// @dev Sets the start timestamp for the SALE_ENDED stage. /// @param timestamp The start timestamp. function setSaleEndTime(uint256 timestamp) external onlyOwner checkAllowed { require(getStageStartTime(SALE_IN_PROGRESS) < timestamp); setStageStartTime(SALE_ENDED, timestamp); } /// @dev Called in the SETUP stage, check configurations and to go to the SETUP_DONE stage. function setupDone() public onlyOwner checkAllowed { uint256 _startTime = getStageStartTime(SALE_IN_PROGRESS); uint256 _endTime = getStageStartTime(SALE_ENDED); require(block.timestamp < _startTime); require(_startTime < _endTime); state.goToNextStage(); } /// @dev Called by users to contribute ETH to the sale. function contribute() public payable checkAllowed { require(msg.value > 0); uint256 contributionLimit = getContributionLimit(msg.sender); require(contributionLimit > 0); // Check that the user is allowed to contribute uint256 totalContribution = contributions[msg.sender].add(msg.value); uint256 excess = 0; // Check if it goes over the eth cap for the sale. if (weiContributed.add(msg.value) > contributionCap) { // Subtract the excess excess = weiContributed.add(msg.value).sub(contributionCap); totalContribution = totalContribution.sub(excess); } // Check if it goes over the contribution limit of the user. if (totalContribution > contributionLimit) { excess = excess.add(totalContribution).sub(contributionLimit); contributions[msg.sender] = contributionLimit; } else { contributions[msg.sender] = totalContribution; } // We are only able to refund up to msg.value because the contract will not contain ether // excess = excess < msg.value ? excess : msg.value; require(excess <= msg.value); weiContributed = weiContributed.add(msg.value).sub(excess); if (excess > 0) { msg.sender.transfer(excess); } wallet.transfer(this.balance); assert(contributions[msg.sender] <= contributionLimit); LogContribution(msg.sender, msg.value, excess); } /// @dev Create a disbursement of tokens. /// @param beneficiary The beneficiary of the disbursement. /// @param tokenAmount Amount of tokens to be locked. /// @param timestamp Tokens will be locked until this timestamp. function distributeTimelockedTokens( address beneficiary, uint256 tokenAmount, uint256 timestamp ) public onlyOwner checkAllowed { disbursementHandler.setupDisbursement( beneficiary, tokenAmount, timestamp ); token.mint(disbursementHandler, tokenAmount); LogDisbursement(beneficiary, tokenAmount); } function setupStages() internal { // Set the stages state.setInitialStage(SETUP); state.createTransition(SETUP, SETUP_DONE); state.createTransition(SETUP_DONE, SALE_IN_PROGRESS); state.createTransition(SALE_IN_PROGRESS, SALE_ENDED); state.allowFunction(SETUP, this.distributeTimelockedTokens.selector); state.allowFunction(SETUP, this.setSaleStartTime.selector); state.allowFunction(SETUP, this.setSaleEndTime.selector); state.allowFunction(SETUP, this.setupDone.selector); state.allowFunction(SALE_IN_PROGRESS, this.contribute.selector); state.allowFunction(SALE_IN_PROGRESS, 0); // fallback } // Override in the child sales function createTokenContract() internal returns (MintableToken); function getContributionLimit(address userAddress) public view returns (uint256); /// @dev Stage start conditions. function startConditions(bytes32 stageId) internal constant returns (bool) { // If the cap has been reached, end the sale. if (stageId == SALE_ENDED && contributionCap <= weiContributed) { return true; } return super.startConditions(stageId); } /// @dev State transitions callbacks. function onTransition(bytes32 stageId) internal { if (stageId == SALE_ENDED) { onSaleEnded(); } super.onTransition(stageId); } /// @dev Callback that gets called when entering the SALE_ENDED stage. function onSaleEnded() internal {} }
distributeTimelockedTokens
function distributeTimelockedTokens( address beneficiary, uint256 tokenAmount, uint256 timestamp ) public onlyOwner checkAllowed { disbursementHandler.setupDisbursement( beneficiary, tokenAmount, timestamp ); token.mint(disbursementHandler, tokenAmount); LogDisbursement(beneficiary, tokenAmount); }
/// @dev Create a disbursement of tokens. /// @param beneficiary The beneficiary of the disbursement. /// @param tokenAmount Amount of tokens to be locked. /// @param timestamp Tokens will be locked until this timestamp.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 4458, 4908 ] }
733
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
Sale
contract Sale is Ownable, TimedStateMachine { using SafeMath for uint256; event LogContribution(address indexed contributor, uint256 amountSent, uint256 excessRefunded); event LogTokenAllocation(address indexed contributor, uint256 contribution, uint256 tokens); event LogDisbursement(address indexed beneficiary, uint256 tokens); // Stages for the state machine bytes32 public constant SETUP = "setup"; bytes32 public constant SETUP_DONE = "setupDone"; bytes32 public constant SALE_IN_PROGRESS = "saleInProgress"; bytes32 public constant SALE_ENDED = "saleEnded"; mapping(address => uint256) public contributions; uint256 public weiContributed = 0; uint256 public contributionCap; // Wallet where funds will be sent address public wallet; MintableToken public token; DisbursementHandler public disbursementHandler; function Sale( address _wallet, uint256 _contributionCap ) public { require(_wallet != 0); require(_contributionCap != 0); wallet = _wallet; token = createTokenContract(); disbursementHandler = new DisbursementHandler(token); contributionCap = _contributionCap; setupStages(); } function() external payable { contribute(); } /// @dev Sets the start timestamp for the SALE_IN_PROGRESS stage. /// @param timestamp The start timestamp. function setSaleStartTime(uint256 timestamp) external onlyOwner checkAllowed { // require(_startTime < getStageStartTime(SALE_ENDED)); setStageStartTime(SALE_IN_PROGRESS, timestamp); } /// @dev Sets the start timestamp for the SALE_ENDED stage. /// @param timestamp The start timestamp. function setSaleEndTime(uint256 timestamp) external onlyOwner checkAllowed { require(getStageStartTime(SALE_IN_PROGRESS) < timestamp); setStageStartTime(SALE_ENDED, timestamp); } /// @dev Called in the SETUP stage, check configurations and to go to the SETUP_DONE stage. function setupDone() public onlyOwner checkAllowed { uint256 _startTime = getStageStartTime(SALE_IN_PROGRESS); uint256 _endTime = getStageStartTime(SALE_ENDED); require(block.timestamp < _startTime); require(_startTime < _endTime); state.goToNextStage(); } /// @dev Called by users to contribute ETH to the sale. function contribute() public payable checkAllowed { require(msg.value > 0); uint256 contributionLimit = getContributionLimit(msg.sender); require(contributionLimit > 0); // Check that the user is allowed to contribute uint256 totalContribution = contributions[msg.sender].add(msg.value); uint256 excess = 0; // Check if it goes over the eth cap for the sale. if (weiContributed.add(msg.value) > contributionCap) { // Subtract the excess excess = weiContributed.add(msg.value).sub(contributionCap); totalContribution = totalContribution.sub(excess); } // Check if it goes over the contribution limit of the user. if (totalContribution > contributionLimit) { excess = excess.add(totalContribution).sub(contributionLimit); contributions[msg.sender] = contributionLimit; } else { contributions[msg.sender] = totalContribution; } // We are only able to refund up to msg.value because the contract will not contain ether // excess = excess < msg.value ? excess : msg.value; require(excess <= msg.value); weiContributed = weiContributed.add(msg.value).sub(excess); if (excess > 0) { msg.sender.transfer(excess); } wallet.transfer(this.balance); assert(contributions[msg.sender] <= contributionLimit); LogContribution(msg.sender, msg.value, excess); } /// @dev Create a disbursement of tokens. /// @param beneficiary The beneficiary of the disbursement. /// @param tokenAmount Amount of tokens to be locked. /// @param timestamp Tokens will be locked until this timestamp. function distributeTimelockedTokens( address beneficiary, uint256 tokenAmount, uint256 timestamp ) public onlyOwner checkAllowed { disbursementHandler.setupDisbursement( beneficiary, tokenAmount, timestamp ); token.mint(disbursementHandler, tokenAmount); LogDisbursement(beneficiary, tokenAmount); } function setupStages() internal { // Set the stages state.setInitialStage(SETUP); state.createTransition(SETUP, SETUP_DONE); state.createTransition(SETUP_DONE, SALE_IN_PROGRESS); state.createTransition(SALE_IN_PROGRESS, SALE_ENDED); state.allowFunction(SETUP, this.distributeTimelockedTokens.selector); state.allowFunction(SETUP, this.setSaleStartTime.selector); state.allowFunction(SETUP, this.setSaleEndTime.selector); state.allowFunction(SETUP, this.setupDone.selector); state.allowFunction(SALE_IN_PROGRESS, this.contribute.selector); state.allowFunction(SALE_IN_PROGRESS, 0); // fallback } // Override in the child sales function createTokenContract() internal returns (MintableToken); function getContributionLimit(address userAddress) public view returns (uint256); /// @dev Stage start conditions. function startConditions(bytes32 stageId) internal constant returns (bool) { // If the cap has been reached, end the sale. if (stageId == SALE_ENDED && contributionCap <= weiContributed) { return true; } return super.startConditions(stageId); } /// @dev State transitions callbacks. function onTransition(bytes32 stageId) internal { if (stageId == SALE_ENDED) { onSaleEnded(); } super.onTransition(stageId); } /// @dev Callback that gets called when entering the SALE_ENDED stage. function onSaleEnded() internal {} }
createTokenContract
function createTokenContract() internal returns (MintableToken);
// Override in the child sales
LineComment
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 5659, 5728 ] }
734
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
Sale
contract Sale is Ownable, TimedStateMachine { using SafeMath for uint256; event LogContribution(address indexed contributor, uint256 amountSent, uint256 excessRefunded); event LogTokenAllocation(address indexed contributor, uint256 contribution, uint256 tokens); event LogDisbursement(address indexed beneficiary, uint256 tokens); // Stages for the state machine bytes32 public constant SETUP = "setup"; bytes32 public constant SETUP_DONE = "setupDone"; bytes32 public constant SALE_IN_PROGRESS = "saleInProgress"; bytes32 public constant SALE_ENDED = "saleEnded"; mapping(address => uint256) public contributions; uint256 public weiContributed = 0; uint256 public contributionCap; // Wallet where funds will be sent address public wallet; MintableToken public token; DisbursementHandler public disbursementHandler; function Sale( address _wallet, uint256 _contributionCap ) public { require(_wallet != 0); require(_contributionCap != 0); wallet = _wallet; token = createTokenContract(); disbursementHandler = new DisbursementHandler(token); contributionCap = _contributionCap; setupStages(); } function() external payable { contribute(); } /// @dev Sets the start timestamp for the SALE_IN_PROGRESS stage. /// @param timestamp The start timestamp. function setSaleStartTime(uint256 timestamp) external onlyOwner checkAllowed { // require(_startTime < getStageStartTime(SALE_ENDED)); setStageStartTime(SALE_IN_PROGRESS, timestamp); } /// @dev Sets the start timestamp for the SALE_ENDED stage. /// @param timestamp The start timestamp. function setSaleEndTime(uint256 timestamp) external onlyOwner checkAllowed { require(getStageStartTime(SALE_IN_PROGRESS) < timestamp); setStageStartTime(SALE_ENDED, timestamp); } /// @dev Called in the SETUP stage, check configurations and to go to the SETUP_DONE stage. function setupDone() public onlyOwner checkAllowed { uint256 _startTime = getStageStartTime(SALE_IN_PROGRESS); uint256 _endTime = getStageStartTime(SALE_ENDED); require(block.timestamp < _startTime); require(_startTime < _endTime); state.goToNextStage(); } /// @dev Called by users to contribute ETH to the sale. function contribute() public payable checkAllowed { require(msg.value > 0); uint256 contributionLimit = getContributionLimit(msg.sender); require(contributionLimit > 0); // Check that the user is allowed to contribute uint256 totalContribution = contributions[msg.sender].add(msg.value); uint256 excess = 0; // Check if it goes over the eth cap for the sale. if (weiContributed.add(msg.value) > contributionCap) { // Subtract the excess excess = weiContributed.add(msg.value).sub(contributionCap); totalContribution = totalContribution.sub(excess); } // Check if it goes over the contribution limit of the user. if (totalContribution > contributionLimit) { excess = excess.add(totalContribution).sub(contributionLimit); contributions[msg.sender] = contributionLimit; } else { contributions[msg.sender] = totalContribution; } // We are only able to refund up to msg.value because the contract will not contain ether // excess = excess < msg.value ? excess : msg.value; require(excess <= msg.value); weiContributed = weiContributed.add(msg.value).sub(excess); if (excess > 0) { msg.sender.transfer(excess); } wallet.transfer(this.balance); assert(contributions[msg.sender] <= contributionLimit); LogContribution(msg.sender, msg.value, excess); } /// @dev Create a disbursement of tokens. /// @param beneficiary The beneficiary of the disbursement. /// @param tokenAmount Amount of tokens to be locked. /// @param timestamp Tokens will be locked until this timestamp. function distributeTimelockedTokens( address beneficiary, uint256 tokenAmount, uint256 timestamp ) public onlyOwner checkAllowed { disbursementHandler.setupDisbursement( beneficiary, tokenAmount, timestamp ); token.mint(disbursementHandler, tokenAmount); LogDisbursement(beneficiary, tokenAmount); } function setupStages() internal { // Set the stages state.setInitialStage(SETUP); state.createTransition(SETUP, SETUP_DONE); state.createTransition(SETUP_DONE, SALE_IN_PROGRESS); state.createTransition(SALE_IN_PROGRESS, SALE_ENDED); state.allowFunction(SETUP, this.distributeTimelockedTokens.selector); state.allowFunction(SETUP, this.setSaleStartTime.selector); state.allowFunction(SETUP, this.setSaleEndTime.selector); state.allowFunction(SETUP, this.setupDone.selector); state.allowFunction(SALE_IN_PROGRESS, this.contribute.selector); state.allowFunction(SALE_IN_PROGRESS, 0); // fallback } // Override in the child sales function createTokenContract() internal returns (MintableToken); function getContributionLimit(address userAddress) public view returns (uint256); /// @dev Stage start conditions. function startConditions(bytes32 stageId) internal constant returns (bool) { // If the cap has been reached, end the sale. if (stageId == SALE_ENDED && contributionCap <= weiContributed) { return true; } return super.startConditions(stageId); } /// @dev State transitions callbacks. function onTransition(bytes32 stageId) internal { if (stageId == SALE_ENDED) { onSaleEnded(); } super.onTransition(stageId); } /// @dev Callback that gets called when entering the SALE_ENDED stage. function onSaleEnded() internal {} }
startConditions
function startConditions(bytes32 stageId) internal constant returns (bool) { // If the cap has been reached, end the sale. if (stageId == SALE_ENDED && contributionCap <= weiContributed) { return true; } return super.startConditions(stageId); }
/// @dev Stage start conditions.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 5856, 6159 ] }
735
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
Sale
contract Sale is Ownable, TimedStateMachine { using SafeMath for uint256; event LogContribution(address indexed contributor, uint256 amountSent, uint256 excessRefunded); event LogTokenAllocation(address indexed contributor, uint256 contribution, uint256 tokens); event LogDisbursement(address indexed beneficiary, uint256 tokens); // Stages for the state machine bytes32 public constant SETUP = "setup"; bytes32 public constant SETUP_DONE = "setupDone"; bytes32 public constant SALE_IN_PROGRESS = "saleInProgress"; bytes32 public constant SALE_ENDED = "saleEnded"; mapping(address => uint256) public contributions; uint256 public weiContributed = 0; uint256 public contributionCap; // Wallet where funds will be sent address public wallet; MintableToken public token; DisbursementHandler public disbursementHandler; function Sale( address _wallet, uint256 _contributionCap ) public { require(_wallet != 0); require(_contributionCap != 0); wallet = _wallet; token = createTokenContract(); disbursementHandler = new DisbursementHandler(token); contributionCap = _contributionCap; setupStages(); } function() external payable { contribute(); } /// @dev Sets the start timestamp for the SALE_IN_PROGRESS stage. /// @param timestamp The start timestamp. function setSaleStartTime(uint256 timestamp) external onlyOwner checkAllowed { // require(_startTime < getStageStartTime(SALE_ENDED)); setStageStartTime(SALE_IN_PROGRESS, timestamp); } /// @dev Sets the start timestamp for the SALE_ENDED stage. /// @param timestamp The start timestamp. function setSaleEndTime(uint256 timestamp) external onlyOwner checkAllowed { require(getStageStartTime(SALE_IN_PROGRESS) < timestamp); setStageStartTime(SALE_ENDED, timestamp); } /// @dev Called in the SETUP stage, check configurations and to go to the SETUP_DONE stage. function setupDone() public onlyOwner checkAllowed { uint256 _startTime = getStageStartTime(SALE_IN_PROGRESS); uint256 _endTime = getStageStartTime(SALE_ENDED); require(block.timestamp < _startTime); require(_startTime < _endTime); state.goToNextStage(); } /// @dev Called by users to contribute ETH to the sale. function contribute() public payable checkAllowed { require(msg.value > 0); uint256 contributionLimit = getContributionLimit(msg.sender); require(contributionLimit > 0); // Check that the user is allowed to contribute uint256 totalContribution = contributions[msg.sender].add(msg.value); uint256 excess = 0; // Check if it goes over the eth cap for the sale. if (weiContributed.add(msg.value) > contributionCap) { // Subtract the excess excess = weiContributed.add(msg.value).sub(contributionCap); totalContribution = totalContribution.sub(excess); } // Check if it goes over the contribution limit of the user. if (totalContribution > contributionLimit) { excess = excess.add(totalContribution).sub(contributionLimit); contributions[msg.sender] = contributionLimit; } else { contributions[msg.sender] = totalContribution; } // We are only able to refund up to msg.value because the contract will not contain ether // excess = excess < msg.value ? excess : msg.value; require(excess <= msg.value); weiContributed = weiContributed.add(msg.value).sub(excess); if (excess > 0) { msg.sender.transfer(excess); } wallet.transfer(this.balance); assert(contributions[msg.sender] <= contributionLimit); LogContribution(msg.sender, msg.value, excess); } /// @dev Create a disbursement of tokens. /// @param beneficiary The beneficiary of the disbursement. /// @param tokenAmount Amount of tokens to be locked. /// @param timestamp Tokens will be locked until this timestamp. function distributeTimelockedTokens( address beneficiary, uint256 tokenAmount, uint256 timestamp ) public onlyOwner checkAllowed { disbursementHandler.setupDisbursement( beneficiary, tokenAmount, timestamp ); token.mint(disbursementHandler, tokenAmount); LogDisbursement(beneficiary, tokenAmount); } function setupStages() internal { // Set the stages state.setInitialStage(SETUP); state.createTransition(SETUP, SETUP_DONE); state.createTransition(SETUP_DONE, SALE_IN_PROGRESS); state.createTransition(SALE_IN_PROGRESS, SALE_ENDED); state.allowFunction(SETUP, this.distributeTimelockedTokens.selector); state.allowFunction(SETUP, this.setSaleStartTime.selector); state.allowFunction(SETUP, this.setSaleEndTime.selector); state.allowFunction(SETUP, this.setupDone.selector); state.allowFunction(SALE_IN_PROGRESS, this.contribute.selector); state.allowFunction(SALE_IN_PROGRESS, 0); // fallback } // Override in the child sales function createTokenContract() internal returns (MintableToken); function getContributionLimit(address userAddress) public view returns (uint256); /// @dev Stage start conditions. function startConditions(bytes32 stageId) internal constant returns (bool) { // If the cap has been reached, end the sale. if (stageId == SALE_ENDED && contributionCap <= weiContributed) { return true; } return super.startConditions(stageId); } /// @dev State transitions callbacks. function onTransition(bytes32 stageId) internal { if (stageId == SALE_ENDED) { onSaleEnded(); } super.onTransition(stageId); } /// @dev Callback that gets called when entering the SALE_ENDED stage. function onSaleEnded() internal {} }
onTransition
function onTransition(bytes32 stageId) internal { if (stageId == SALE_ENDED) { onSaleEnded(); } super.onTransition(stageId); }
/// @dev State transitions callbacks.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 6205, 6383 ] }
736
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
Sale
contract Sale is Ownable, TimedStateMachine { using SafeMath for uint256; event LogContribution(address indexed contributor, uint256 amountSent, uint256 excessRefunded); event LogTokenAllocation(address indexed contributor, uint256 contribution, uint256 tokens); event LogDisbursement(address indexed beneficiary, uint256 tokens); // Stages for the state machine bytes32 public constant SETUP = "setup"; bytes32 public constant SETUP_DONE = "setupDone"; bytes32 public constant SALE_IN_PROGRESS = "saleInProgress"; bytes32 public constant SALE_ENDED = "saleEnded"; mapping(address => uint256) public contributions; uint256 public weiContributed = 0; uint256 public contributionCap; // Wallet where funds will be sent address public wallet; MintableToken public token; DisbursementHandler public disbursementHandler; function Sale( address _wallet, uint256 _contributionCap ) public { require(_wallet != 0); require(_contributionCap != 0); wallet = _wallet; token = createTokenContract(); disbursementHandler = new DisbursementHandler(token); contributionCap = _contributionCap; setupStages(); } function() external payable { contribute(); } /// @dev Sets the start timestamp for the SALE_IN_PROGRESS stage. /// @param timestamp The start timestamp. function setSaleStartTime(uint256 timestamp) external onlyOwner checkAllowed { // require(_startTime < getStageStartTime(SALE_ENDED)); setStageStartTime(SALE_IN_PROGRESS, timestamp); } /// @dev Sets the start timestamp for the SALE_ENDED stage. /// @param timestamp The start timestamp. function setSaleEndTime(uint256 timestamp) external onlyOwner checkAllowed { require(getStageStartTime(SALE_IN_PROGRESS) < timestamp); setStageStartTime(SALE_ENDED, timestamp); } /// @dev Called in the SETUP stage, check configurations and to go to the SETUP_DONE stage. function setupDone() public onlyOwner checkAllowed { uint256 _startTime = getStageStartTime(SALE_IN_PROGRESS); uint256 _endTime = getStageStartTime(SALE_ENDED); require(block.timestamp < _startTime); require(_startTime < _endTime); state.goToNextStage(); } /// @dev Called by users to contribute ETH to the sale. function contribute() public payable checkAllowed { require(msg.value > 0); uint256 contributionLimit = getContributionLimit(msg.sender); require(contributionLimit > 0); // Check that the user is allowed to contribute uint256 totalContribution = contributions[msg.sender].add(msg.value); uint256 excess = 0; // Check if it goes over the eth cap for the sale. if (weiContributed.add(msg.value) > contributionCap) { // Subtract the excess excess = weiContributed.add(msg.value).sub(contributionCap); totalContribution = totalContribution.sub(excess); } // Check if it goes over the contribution limit of the user. if (totalContribution > contributionLimit) { excess = excess.add(totalContribution).sub(contributionLimit); contributions[msg.sender] = contributionLimit; } else { contributions[msg.sender] = totalContribution; } // We are only able to refund up to msg.value because the contract will not contain ether // excess = excess < msg.value ? excess : msg.value; require(excess <= msg.value); weiContributed = weiContributed.add(msg.value).sub(excess); if (excess > 0) { msg.sender.transfer(excess); } wallet.transfer(this.balance); assert(contributions[msg.sender] <= contributionLimit); LogContribution(msg.sender, msg.value, excess); } /// @dev Create a disbursement of tokens. /// @param beneficiary The beneficiary of the disbursement. /// @param tokenAmount Amount of tokens to be locked. /// @param timestamp Tokens will be locked until this timestamp. function distributeTimelockedTokens( address beneficiary, uint256 tokenAmount, uint256 timestamp ) public onlyOwner checkAllowed { disbursementHandler.setupDisbursement( beneficiary, tokenAmount, timestamp ); token.mint(disbursementHandler, tokenAmount); LogDisbursement(beneficiary, tokenAmount); } function setupStages() internal { // Set the stages state.setInitialStage(SETUP); state.createTransition(SETUP, SETUP_DONE); state.createTransition(SETUP_DONE, SALE_IN_PROGRESS); state.createTransition(SALE_IN_PROGRESS, SALE_ENDED); state.allowFunction(SETUP, this.distributeTimelockedTokens.selector); state.allowFunction(SETUP, this.setSaleStartTime.selector); state.allowFunction(SETUP, this.setSaleEndTime.selector); state.allowFunction(SETUP, this.setupDone.selector); state.allowFunction(SALE_IN_PROGRESS, this.contribute.selector); state.allowFunction(SALE_IN_PROGRESS, 0); // fallback } // Override in the child sales function createTokenContract() internal returns (MintableToken); function getContributionLimit(address userAddress) public view returns (uint256); /// @dev Stage start conditions. function startConditions(bytes32 stageId) internal constant returns (bool) { // If the cap has been reached, end the sale. if (stageId == SALE_ENDED && contributionCap <= weiContributed) { return true; } return super.startConditions(stageId); } /// @dev State transitions callbacks. function onTransition(bytes32 stageId) internal { if (stageId == SALE_ENDED) { onSaleEnded(); } super.onTransition(stageId); } /// @dev Callback that gets called when entering the SALE_ENDED stage. function onSaleEnded() internal {} }
onSaleEnded
function onSaleEnded() internal {}
/// @dev Callback that gets called when entering the SALE_ENDED stage.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 6462, 6501 ] }
737
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
ERC223ReceivingContract
contract ERC223ReceivingContract { /// @dev Standard ERC223 function that will handle incoming token transfers. /// @param _from Token sender address. /// @param _value Amount of tokens. /// @param _data Transaction metadata. function tokenFallback(address _from, uint _value, bytes _data) public; }
tokenFallback
function tokenFallback(address _from, uint _value, bytes _data) public;
/// @dev Standard ERC223 function that will handle incoming token transfers. /// @param _from Token sender address. /// @param _value Amount of tokens. /// @param _data Transaction metadata.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 251, 327 ] }
738
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
ERC223Basic
contract ERC223Basic is ERC20Basic { /** * @dev Transfer the specified amount of tokens to the specified address. * Now with a new parameter _data. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _data Transaction metadata. */ function transfer(address _to, uint _value, bytes _data) public returns (bool); /** * @dev triggered when transfer is successfully called. * * @param _from Sender address. * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _data Transaction metadata. */ event Transfer(address indexed _from, address indexed _to, uint256 indexed _value, bytes _data); }
transfer
function transfer(address _to, uint _value, bytes _data) public returns (bool);
/** * @dev Transfer the specified amount of tokens to the specified address. * Now with a new parameter _data. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _data Transaction metadata. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 346, 430 ] }
739
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
ERC223BasicToken
contract ERC223BasicToken is ERC223Basic, BasicToken { /** * @dev Transfer the specified amount of tokens to the specified address. * Invokes the `tokenFallback` function if the recipient is a contract. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallback` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _data Transaction metadata. */ function transfer(address _to, uint _value, bytes _data) public returns (bool) { // Standard function transfer similar to ERC20 transfer with no _data . // Added due to backwards compatibility reasons . uint codeLength; assembly { // Retrieve the size of the code on target address, this needs assembly . codeLength := extcodesize(_to) } require(super.transfer(_to, _value)); if(codeLength>0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallback(msg.sender, _value, _data); } Transfer(msg.sender, _to, _value, _data); return true; } /** * @dev Transfer the specified amount of tokens to the specified address. * Invokes the `tokenFallback` function if the recipient is a contract. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallback` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { bytes memory empty; require(transfer(_to, _value, empty)); return true; } }
transfer
function transfer(address _to, uint _value, bytes _data) public returns (bool) { // Standard function transfer similar to ERC20 transfer with no _data . // Added due to backwards compatibility reasons . uint codeLength; assembly { // Retrieve the size of the code on target address, this needs assembly . codeLength := extcodesize(_to) } require(super.transfer(_to, _value)); if(codeLength>0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallback(msg.sender, _value, _data); } Transfer(msg.sender, _to, _value, _data); return true; }
/** * @dev Transfer the specified amount of tokens to the specified address. * Invokes the `tokenFallback` function if the recipient is a contract. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallback` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _data Transaction metadata. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 594, 1321 ] }
740
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
ERC223BasicToken
contract ERC223BasicToken is ERC223Basic, BasicToken { /** * @dev Transfer the specified amount of tokens to the specified address. * Invokes the `tokenFallback` function if the recipient is a contract. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallback` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _data Transaction metadata. */ function transfer(address _to, uint _value, bytes _data) public returns (bool) { // Standard function transfer similar to ERC20 transfer with no _data . // Added due to backwards compatibility reasons . uint codeLength; assembly { // Retrieve the size of the code on target address, this needs assembly . codeLength := extcodesize(_to) } require(super.transfer(_to, _value)); if(codeLength>0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallback(msg.sender, _value, _data); } Transfer(msg.sender, _to, _value, _data); return true; } /** * @dev Transfer the specified amount of tokens to the specified address. * Invokes the `tokenFallback` function if the recipient is a contract. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallback` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { bytes memory empty; require(transfer(_to, _value, empty)); return true; } }
transfer
function transfer(address _to, uint256 _value) public returns (bool) { bytes memory empty; require(transfer(_to, _value, empty)); return true; }
/** * @dev Transfer the specified amount of tokens to the specified address. * Invokes the `tokenFallback` function if the recipient is a contract. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallback` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1817, 1998 ] }
741
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
DetherToken
contract DetherToken is DetailedERC20, MintableToken, ERC223BasicToken { string constant NAME = "Dether"; string constant SYMBOL = "DTH"; uint8 constant DECIMALS = 18; /** *@dev Constructor that set Detailed of the ERC20 token. */ function DetherToken() DetailedERC20(NAME, SYMBOL, DECIMALS) public {} }
DetherToken
function DetherToken() DetailedERC20(NAME, SYMBOL, DECIMALS) public {}
/** *@dev Constructor that set Detailed of the ERC20 token. */
NatSpecMultiLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 268, 366 ] }
742
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
DetherSale
contract DetherSale is Sale, Whitelistable { uint256 public constant PRESALE_WEI = 3956 ether * 1.15 + 490 ether; // Amount raised in the presale including bonus uint256 public constant DECIMALS_MULTIPLIER = 1000000000000000000; uint256 public constant MAX_DTH = 100000000 * DECIMALS_MULTIPLIER; // MAX_WEI - PRESALE_WEI // TODO: change to actual amount uint256 public constant WEI_CAP = 10554 ether; // Duration of the whitelisting phase uint256 public constant WHITELISTING_DURATION = 2 days; // Contribution limit for the whitelisting phase uint256 public constant WHITELISTING_MAX_CONTRIBUTION = 5 ether; // Contribution limit for the public sale uint256 public constant PUBLIC_MAX_CONTRIBUTION = 2**256 - 1; // Minimum contribution allowed uint256 public constant MIN_CONTRIBUTION = 0.1 ether; // wei per DTH uint256 public weiPerDTH; // true if the locked tokens have been distributed bool private lockedTokensDistributed; // true if the presale tokens have been allocated bool private presaleAllocated; // Address for the presale buyers (Dether team will distribute manually) address public presaleAddress; uint256 private weiAllocated; // Contribution limits specified for the presale mapping(address => uint256) public presaleMaxContribution; function DetherSale(address _wallet, address _presaleAddress) Sale(_wallet, WEI_CAP) public { presaleAddress = _presaleAddress; } /// @dev Distributes timed locked tokens function performInitialAllocations() external onlyOwner checkAllowed { require(lockedTokensDistributed == false); lockedTokensDistributed = true; // Advisors distributeTimelockedTokens(0x4dc976cEd66d1B87C099B338E1F1388AE657377d, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); // Bounty distributeTimelockedTokens(0xfEF675cC3068Ee798f2312e82B12c841157A0A0E, MAX_DTH.mul(3).div(100), now + 1 weeks); // Early Contributors distributeTimelockedTokens(0x8F38C4ddFE09Bd22545262FE160cf441D43d2489, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); distributeTimelockedTokens(0x87a4eb1c9fdef835DC9197FAff3E09b8007ADe5b, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); // Strategic Partnerships distributeTimelockedTokens(0x6f63D5DF2D8644851cBb5F8607C845704C008284, MAX_DTH.mul(11).div(100), now + 1 weeks); // Team (locked 3 years, 6 months release) distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 2 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 3 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 4 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 5 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 6 * 4 weeks); } /// @dev Registers a user and sets the maximum contribution amount for the whitelisting period function registerPresaleContributor(address userAddress, uint256 maxContribution) external onlyOwner { // Specified contribution has to be lower than the max require(maxContribution <= WHITELISTING_MAX_CONTRIBUTION); // Register user (Whitelistable contract) registerUser(userAddress); // Set contribution presaleMaxContribution[userAddress] = maxContribution; } /// @dev Called to allocate the tokens depending on eth contributed. /// @param contributor The address of the contributor. function allocateTokens(address contributor) external checkAllowed { require(presaleAllocated); require(contributions[contributor] != 0); // We keep a record of how much wei contributed has already been used for allocations weiAllocated = weiAllocated.add(contributions[contributor]); // Mint the respective tokens to the contributor token.mint(contributor, contributions[contributor].mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); // Set contributions to 0 contributions[contributor] = 0; // If all tokens were allocated, stop minting functionality // and send the remaining (rounding errors) tokens to the owner if (weiAllocated == weiContributed) { uint256 remaining = MAX_DTH.sub(token.totalSupply()); token.mint(owner, remaining); token.finishMinting(); } } /// @dev Called to allocate the tokens for presale address. function presaleAllocateTokens() external checkAllowed { require(!presaleAllocated); presaleAllocated = true; // Mint the respective tokens to the contributor token.mint(presaleAddress, PRESALE_WEI.mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); } function contribute() public payable checkAllowed { require(msg.value >= MIN_CONTRIBUTION); super.contribute(); } /// @dev The limit will be different for every address during the whitelist period, and after that phase there is no limit for contributions. function getContributionLimit(address userAddress) public view returns (uint256) { uint256 saleStartTime = getStageStartTime(SALE_IN_PROGRESS); // If not whitelisted or sale has not started, return 0 if (!whitelisted[userAddress] || block.timestamp < saleStartTime) { return 0; } // Are we in the first two days? bool whitelistingPeriod = block.timestamp - saleStartTime <= WHITELISTING_DURATION; // If we are in the whitelisting period, return the contribution limit for the user // If not, return the public max contribution return whitelistingPeriod ? presaleMaxContribution[userAddress] : PUBLIC_MAX_CONTRIBUTION; } function createTokenContract() internal returns(MintableToken) { return new DetherToken(); } function setupStages() internal { super.setupStages(); state.allowFunction(SETUP, this.performInitialAllocations.selector); state.allowFunction(SALE_ENDED, this.allocateTokens.selector); state.allowFunction(SALE_ENDED, this.presaleAllocateTokens.selector); } /// @dev The price will be the total wei contributed divided by the amount of tokens to be allocated to contributors. function calculatePrice() public view returns(uint256) { return weiContributed.add(PRESALE_WEI).div(60000000).add(1); } function onSaleEnded() internal { // Calculate DTH per Wei weiPerDTH = calculatePrice(); } }
performInitialAllocations
function performInitialAllocations() external onlyOwner checkAllowed { require(lockedTokensDistributed == false); lockedTokensDistributed = true; // Advisors distributeTimelockedTokens(0x4dc976cEd66d1B87C099B338E1F1388AE657377d, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); // Bounty distributeTimelockedTokens(0xfEF675cC3068Ee798f2312e82B12c841157A0A0E, MAX_DTH.mul(3).div(100), now + 1 weeks); // Early Contributors distributeTimelockedTokens(0x8F38C4ddFE09Bd22545262FE160cf441D43d2489, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); distributeTimelockedTokens(0x87a4eb1c9fdef835DC9197FAff3E09b8007ADe5b, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); // Strategic Partnerships distributeTimelockedTokens(0x6f63D5DF2D8644851cBb5F8607C845704C008284, MAX_DTH.mul(11).div(100), now + 1 weeks); // Team (locked 3 years, 6 months release) distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 2 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 3 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 4 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 5 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 6 * 4 weeks); }
/// @dev Distributes timed locked tokens
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 1597, 3334 ] }
743
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
DetherSale
contract DetherSale is Sale, Whitelistable { uint256 public constant PRESALE_WEI = 3956 ether * 1.15 + 490 ether; // Amount raised in the presale including bonus uint256 public constant DECIMALS_MULTIPLIER = 1000000000000000000; uint256 public constant MAX_DTH = 100000000 * DECIMALS_MULTIPLIER; // MAX_WEI - PRESALE_WEI // TODO: change to actual amount uint256 public constant WEI_CAP = 10554 ether; // Duration of the whitelisting phase uint256 public constant WHITELISTING_DURATION = 2 days; // Contribution limit for the whitelisting phase uint256 public constant WHITELISTING_MAX_CONTRIBUTION = 5 ether; // Contribution limit for the public sale uint256 public constant PUBLIC_MAX_CONTRIBUTION = 2**256 - 1; // Minimum contribution allowed uint256 public constant MIN_CONTRIBUTION = 0.1 ether; // wei per DTH uint256 public weiPerDTH; // true if the locked tokens have been distributed bool private lockedTokensDistributed; // true if the presale tokens have been allocated bool private presaleAllocated; // Address for the presale buyers (Dether team will distribute manually) address public presaleAddress; uint256 private weiAllocated; // Contribution limits specified for the presale mapping(address => uint256) public presaleMaxContribution; function DetherSale(address _wallet, address _presaleAddress) Sale(_wallet, WEI_CAP) public { presaleAddress = _presaleAddress; } /// @dev Distributes timed locked tokens function performInitialAllocations() external onlyOwner checkAllowed { require(lockedTokensDistributed == false); lockedTokensDistributed = true; // Advisors distributeTimelockedTokens(0x4dc976cEd66d1B87C099B338E1F1388AE657377d, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); // Bounty distributeTimelockedTokens(0xfEF675cC3068Ee798f2312e82B12c841157A0A0E, MAX_DTH.mul(3).div(100), now + 1 weeks); // Early Contributors distributeTimelockedTokens(0x8F38C4ddFE09Bd22545262FE160cf441D43d2489, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); distributeTimelockedTokens(0x87a4eb1c9fdef835DC9197FAff3E09b8007ADe5b, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); // Strategic Partnerships distributeTimelockedTokens(0x6f63D5DF2D8644851cBb5F8607C845704C008284, MAX_DTH.mul(11).div(100), now + 1 weeks); // Team (locked 3 years, 6 months release) distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 2 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 3 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 4 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 5 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 6 * 4 weeks); } /// @dev Registers a user and sets the maximum contribution amount for the whitelisting period function registerPresaleContributor(address userAddress, uint256 maxContribution) external onlyOwner { // Specified contribution has to be lower than the max require(maxContribution <= WHITELISTING_MAX_CONTRIBUTION); // Register user (Whitelistable contract) registerUser(userAddress); // Set contribution presaleMaxContribution[userAddress] = maxContribution; } /// @dev Called to allocate the tokens depending on eth contributed. /// @param contributor The address of the contributor. function allocateTokens(address contributor) external checkAllowed { require(presaleAllocated); require(contributions[contributor] != 0); // We keep a record of how much wei contributed has already been used for allocations weiAllocated = weiAllocated.add(contributions[contributor]); // Mint the respective tokens to the contributor token.mint(contributor, contributions[contributor].mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); // Set contributions to 0 contributions[contributor] = 0; // If all tokens were allocated, stop minting functionality // and send the remaining (rounding errors) tokens to the owner if (weiAllocated == weiContributed) { uint256 remaining = MAX_DTH.sub(token.totalSupply()); token.mint(owner, remaining); token.finishMinting(); } } /// @dev Called to allocate the tokens for presale address. function presaleAllocateTokens() external checkAllowed { require(!presaleAllocated); presaleAllocated = true; // Mint the respective tokens to the contributor token.mint(presaleAddress, PRESALE_WEI.mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); } function contribute() public payable checkAllowed { require(msg.value >= MIN_CONTRIBUTION); super.contribute(); } /// @dev The limit will be different for every address during the whitelist period, and after that phase there is no limit for contributions. function getContributionLimit(address userAddress) public view returns (uint256) { uint256 saleStartTime = getStageStartTime(SALE_IN_PROGRESS); // If not whitelisted or sale has not started, return 0 if (!whitelisted[userAddress] || block.timestamp < saleStartTime) { return 0; } // Are we in the first two days? bool whitelistingPeriod = block.timestamp - saleStartTime <= WHITELISTING_DURATION; // If we are in the whitelisting period, return the contribution limit for the user // If not, return the public max contribution return whitelistingPeriod ? presaleMaxContribution[userAddress] : PUBLIC_MAX_CONTRIBUTION; } function createTokenContract() internal returns(MintableToken) { return new DetherToken(); } function setupStages() internal { super.setupStages(); state.allowFunction(SETUP, this.performInitialAllocations.selector); state.allowFunction(SALE_ENDED, this.allocateTokens.selector); state.allowFunction(SALE_ENDED, this.presaleAllocateTokens.selector); } /// @dev The price will be the total wei contributed divided by the amount of tokens to be allocated to contributors. function calculatePrice() public view returns(uint256) { return weiContributed.add(PRESALE_WEI).div(60000000).add(1); } function onSaleEnded() internal { // Calculate DTH per Wei weiPerDTH = calculatePrice(); } }
registerPresaleContributor
function registerPresaleContributor(address userAddress, uint256 maxContribution) external onlyOwner { // Specified contribution has to be lower than the max require(maxContribution <= WHITELISTING_MAX_CONTRIBUTION); // Register user (Whitelistable contract) registerUser(userAddress); // Set contribution presaleMaxContribution[userAddress] = maxContribution; }
/// @dev Registers a user and sets the maximum contribution amount for the whitelisting period
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 3437, 3890 ] }
744
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
DetherSale
contract DetherSale is Sale, Whitelistable { uint256 public constant PRESALE_WEI = 3956 ether * 1.15 + 490 ether; // Amount raised in the presale including bonus uint256 public constant DECIMALS_MULTIPLIER = 1000000000000000000; uint256 public constant MAX_DTH = 100000000 * DECIMALS_MULTIPLIER; // MAX_WEI - PRESALE_WEI // TODO: change to actual amount uint256 public constant WEI_CAP = 10554 ether; // Duration of the whitelisting phase uint256 public constant WHITELISTING_DURATION = 2 days; // Contribution limit for the whitelisting phase uint256 public constant WHITELISTING_MAX_CONTRIBUTION = 5 ether; // Contribution limit for the public sale uint256 public constant PUBLIC_MAX_CONTRIBUTION = 2**256 - 1; // Minimum contribution allowed uint256 public constant MIN_CONTRIBUTION = 0.1 ether; // wei per DTH uint256 public weiPerDTH; // true if the locked tokens have been distributed bool private lockedTokensDistributed; // true if the presale tokens have been allocated bool private presaleAllocated; // Address for the presale buyers (Dether team will distribute manually) address public presaleAddress; uint256 private weiAllocated; // Contribution limits specified for the presale mapping(address => uint256) public presaleMaxContribution; function DetherSale(address _wallet, address _presaleAddress) Sale(_wallet, WEI_CAP) public { presaleAddress = _presaleAddress; } /// @dev Distributes timed locked tokens function performInitialAllocations() external onlyOwner checkAllowed { require(lockedTokensDistributed == false); lockedTokensDistributed = true; // Advisors distributeTimelockedTokens(0x4dc976cEd66d1B87C099B338E1F1388AE657377d, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); // Bounty distributeTimelockedTokens(0xfEF675cC3068Ee798f2312e82B12c841157A0A0E, MAX_DTH.mul(3).div(100), now + 1 weeks); // Early Contributors distributeTimelockedTokens(0x8F38C4ddFE09Bd22545262FE160cf441D43d2489, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); distributeTimelockedTokens(0x87a4eb1c9fdef835DC9197FAff3E09b8007ADe5b, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); // Strategic Partnerships distributeTimelockedTokens(0x6f63D5DF2D8644851cBb5F8607C845704C008284, MAX_DTH.mul(11).div(100), now + 1 weeks); // Team (locked 3 years, 6 months release) distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 2 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 3 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 4 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 5 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 6 * 4 weeks); } /// @dev Registers a user and sets the maximum contribution amount for the whitelisting period function registerPresaleContributor(address userAddress, uint256 maxContribution) external onlyOwner { // Specified contribution has to be lower than the max require(maxContribution <= WHITELISTING_MAX_CONTRIBUTION); // Register user (Whitelistable contract) registerUser(userAddress); // Set contribution presaleMaxContribution[userAddress] = maxContribution; } /// @dev Called to allocate the tokens depending on eth contributed. /// @param contributor The address of the contributor. function allocateTokens(address contributor) external checkAllowed { require(presaleAllocated); require(contributions[contributor] != 0); // We keep a record of how much wei contributed has already been used for allocations weiAllocated = weiAllocated.add(contributions[contributor]); // Mint the respective tokens to the contributor token.mint(contributor, contributions[contributor].mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); // Set contributions to 0 contributions[contributor] = 0; // If all tokens were allocated, stop minting functionality // and send the remaining (rounding errors) tokens to the owner if (weiAllocated == weiContributed) { uint256 remaining = MAX_DTH.sub(token.totalSupply()); token.mint(owner, remaining); token.finishMinting(); } } /// @dev Called to allocate the tokens for presale address. function presaleAllocateTokens() external checkAllowed { require(!presaleAllocated); presaleAllocated = true; // Mint the respective tokens to the contributor token.mint(presaleAddress, PRESALE_WEI.mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); } function contribute() public payable checkAllowed { require(msg.value >= MIN_CONTRIBUTION); super.contribute(); } /// @dev The limit will be different for every address during the whitelist period, and after that phase there is no limit for contributions. function getContributionLimit(address userAddress) public view returns (uint256) { uint256 saleStartTime = getStageStartTime(SALE_IN_PROGRESS); // If not whitelisted or sale has not started, return 0 if (!whitelisted[userAddress] || block.timestamp < saleStartTime) { return 0; } // Are we in the first two days? bool whitelistingPeriod = block.timestamp - saleStartTime <= WHITELISTING_DURATION; // If we are in the whitelisting period, return the contribution limit for the user // If not, return the public max contribution return whitelistingPeriod ? presaleMaxContribution[userAddress] : PUBLIC_MAX_CONTRIBUTION; } function createTokenContract() internal returns(MintableToken) { return new DetherToken(); } function setupStages() internal { super.setupStages(); state.allowFunction(SETUP, this.performInitialAllocations.selector); state.allowFunction(SALE_ENDED, this.allocateTokens.selector); state.allowFunction(SALE_ENDED, this.presaleAllocateTokens.selector); } /// @dev The price will be the total wei contributed divided by the amount of tokens to be allocated to contributors. function calculatePrice() public view returns(uint256) { return weiContributed.add(PRESALE_WEI).div(60000000).add(1); } function onSaleEnded() internal { // Calculate DTH per Wei weiPerDTH = calculatePrice(); } }
allocateTokens
function allocateTokens(address contributor) external checkAllowed { require(presaleAllocated); require(contributions[contributor] != 0); // We keep a record of how much wei contributed has already been used for allocations weiAllocated = weiAllocated.add(contributions[contributor]); // Mint the respective tokens to the contributor token.mint(contributor, contributions[contributor].mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); // Set contributions to 0 contributions[contributor] = 0; // If all tokens were allocated, stop minting functionality // and send the remaining (rounding errors) tokens to the owner if (weiAllocated == weiContributed) { uint256 remaining = MAX_DTH.sub(token.totalSupply()); token.mint(owner, remaining); token.finishMinting(); } }
/// @dev Called to allocate the tokens depending on eth contributed. /// @param contributor The address of the contributor.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 4027, 4966 ] }
745
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
DetherSale
contract DetherSale is Sale, Whitelistable { uint256 public constant PRESALE_WEI = 3956 ether * 1.15 + 490 ether; // Amount raised in the presale including bonus uint256 public constant DECIMALS_MULTIPLIER = 1000000000000000000; uint256 public constant MAX_DTH = 100000000 * DECIMALS_MULTIPLIER; // MAX_WEI - PRESALE_WEI // TODO: change to actual amount uint256 public constant WEI_CAP = 10554 ether; // Duration of the whitelisting phase uint256 public constant WHITELISTING_DURATION = 2 days; // Contribution limit for the whitelisting phase uint256 public constant WHITELISTING_MAX_CONTRIBUTION = 5 ether; // Contribution limit for the public sale uint256 public constant PUBLIC_MAX_CONTRIBUTION = 2**256 - 1; // Minimum contribution allowed uint256 public constant MIN_CONTRIBUTION = 0.1 ether; // wei per DTH uint256 public weiPerDTH; // true if the locked tokens have been distributed bool private lockedTokensDistributed; // true if the presale tokens have been allocated bool private presaleAllocated; // Address for the presale buyers (Dether team will distribute manually) address public presaleAddress; uint256 private weiAllocated; // Contribution limits specified for the presale mapping(address => uint256) public presaleMaxContribution; function DetherSale(address _wallet, address _presaleAddress) Sale(_wallet, WEI_CAP) public { presaleAddress = _presaleAddress; } /// @dev Distributes timed locked tokens function performInitialAllocations() external onlyOwner checkAllowed { require(lockedTokensDistributed == false); lockedTokensDistributed = true; // Advisors distributeTimelockedTokens(0x4dc976cEd66d1B87C099B338E1F1388AE657377d, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); // Bounty distributeTimelockedTokens(0xfEF675cC3068Ee798f2312e82B12c841157A0A0E, MAX_DTH.mul(3).div(100), now + 1 weeks); // Early Contributors distributeTimelockedTokens(0x8F38C4ddFE09Bd22545262FE160cf441D43d2489, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); distributeTimelockedTokens(0x87a4eb1c9fdef835DC9197FAff3E09b8007ADe5b, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); // Strategic Partnerships distributeTimelockedTokens(0x6f63D5DF2D8644851cBb5F8607C845704C008284, MAX_DTH.mul(11).div(100), now + 1 weeks); // Team (locked 3 years, 6 months release) distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 2 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 3 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 4 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 5 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 6 * 4 weeks); } /// @dev Registers a user and sets the maximum contribution amount for the whitelisting period function registerPresaleContributor(address userAddress, uint256 maxContribution) external onlyOwner { // Specified contribution has to be lower than the max require(maxContribution <= WHITELISTING_MAX_CONTRIBUTION); // Register user (Whitelistable contract) registerUser(userAddress); // Set contribution presaleMaxContribution[userAddress] = maxContribution; } /// @dev Called to allocate the tokens depending on eth contributed. /// @param contributor The address of the contributor. function allocateTokens(address contributor) external checkAllowed { require(presaleAllocated); require(contributions[contributor] != 0); // We keep a record of how much wei contributed has already been used for allocations weiAllocated = weiAllocated.add(contributions[contributor]); // Mint the respective tokens to the contributor token.mint(contributor, contributions[contributor].mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); // Set contributions to 0 contributions[contributor] = 0; // If all tokens were allocated, stop minting functionality // and send the remaining (rounding errors) tokens to the owner if (weiAllocated == weiContributed) { uint256 remaining = MAX_DTH.sub(token.totalSupply()); token.mint(owner, remaining); token.finishMinting(); } } /// @dev Called to allocate the tokens for presale address. function presaleAllocateTokens() external checkAllowed { require(!presaleAllocated); presaleAllocated = true; // Mint the respective tokens to the contributor token.mint(presaleAddress, PRESALE_WEI.mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); } function contribute() public payable checkAllowed { require(msg.value >= MIN_CONTRIBUTION); super.contribute(); } /// @dev The limit will be different for every address during the whitelist period, and after that phase there is no limit for contributions. function getContributionLimit(address userAddress) public view returns (uint256) { uint256 saleStartTime = getStageStartTime(SALE_IN_PROGRESS); // If not whitelisted or sale has not started, return 0 if (!whitelisted[userAddress] || block.timestamp < saleStartTime) { return 0; } // Are we in the first two days? bool whitelistingPeriod = block.timestamp - saleStartTime <= WHITELISTING_DURATION; // If we are in the whitelisting period, return the contribution limit for the user // If not, return the public max contribution return whitelistingPeriod ? presaleMaxContribution[userAddress] : PUBLIC_MAX_CONTRIBUTION; } function createTokenContract() internal returns(MintableToken) { return new DetherToken(); } function setupStages() internal { super.setupStages(); state.allowFunction(SETUP, this.performInitialAllocations.selector); state.allowFunction(SALE_ENDED, this.allocateTokens.selector); state.allowFunction(SALE_ENDED, this.presaleAllocateTokens.selector); } /// @dev The price will be the total wei contributed divided by the amount of tokens to be allocated to contributors. function calculatePrice() public view returns(uint256) { return weiContributed.add(PRESALE_WEI).div(60000000).add(1); } function onSaleEnded() internal { // Calculate DTH per Wei weiPerDTH = calculatePrice(); } }
presaleAllocateTokens
function presaleAllocateTokens() external checkAllowed { require(!presaleAllocated); presaleAllocated = true; // Mint the respective tokens to the contributor token.mint(presaleAddress, PRESALE_WEI.mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); }
/// @dev Called to allocate the tokens for presale address.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 5034, 5346 ] }
746
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
DetherSale
contract DetherSale is Sale, Whitelistable { uint256 public constant PRESALE_WEI = 3956 ether * 1.15 + 490 ether; // Amount raised in the presale including bonus uint256 public constant DECIMALS_MULTIPLIER = 1000000000000000000; uint256 public constant MAX_DTH = 100000000 * DECIMALS_MULTIPLIER; // MAX_WEI - PRESALE_WEI // TODO: change to actual amount uint256 public constant WEI_CAP = 10554 ether; // Duration of the whitelisting phase uint256 public constant WHITELISTING_DURATION = 2 days; // Contribution limit for the whitelisting phase uint256 public constant WHITELISTING_MAX_CONTRIBUTION = 5 ether; // Contribution limit for the public sale uint256 public constant PUBLIC_MAX_CONTRIBUTION = 2**256 - 1; // Minimum contribution allowed uint256 public constant MIN_CONTRIBUTION = 0.1 ether; // wei per DTH uint256 public weiPerDTH; // true if the locked tokens have been distributed bool private lockedTokensDistributed; // true if the presale tokens have been allocated bool private presaleAllocated; // Address for the presale buyers (Dether team will distribute manually) address public presaleAddress; uint256 private weiAllocated; // Contribution limits specified for the presale mapping(address => uint256) public presaleMaxContribution; function DetherSale(address _wallet, address _presaleAddress) Sale(_wallet, WEI_CAP) public { presaleAddress = _presaleAddress; } /// @dev Distributes timed locked tokens function performInitialAllocations() external onlyOwner checkAllowed { require(lockedTokensDistributed == false); lockedTokensDistributed = true; // Advisors distributeTimelockedTokens(0x4dc976cEd66d1B87C099B338E1F1388AE657377d, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); // Bounty distributeTimelockedTokens(0xfEF675cC3068Ee798f2312e82B12c841157A0A0E, MAX_DTH.mul(3).div(100), now + 1 weeks); // Early Contributors distributeTimelockedTokens(0x8F38C4ddFE09Bd22545262FE160cf441D43d2489, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); distributeTimelockedTokens(0x87a4eb1c9fdef835DC9197FAff3E09b8007ADe5b, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); // Strategic Partnerships distributeTimelockedTokens(0x6f63D5DF2D8644851cBb5F8607C845704C008284, MAX_DTH.mul(11).div(100), now + 1 weeks); // Team (locked 3 years, 6 months release) distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 2 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 3 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 4 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 5 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 6 * 4 weeks); } /// @dev Registers a user and sets the maximum contribution amount for the whitelisting period function registerPresaleContributor(address userAddress, uint256 maxContribution) external onlyOwner { // Specified contribution has to be lower than the max require(maxContribution <= WHITELISTING_MAX_CONTRIBUTION); // Register user (Whitelistable contract) registerUser(userAddress); // Set contribution presaleMaxContribution[userAddress] = maxContribution; } /// @dev Called to allocate the tokens depending on eth contributed. /// @param contributor The address of the contributor. function allocateTokens(address contributor) external checkAllowed { require(presaleAllocated); require(contributions[contributor] != 0); // We keep a record of how much wei contributed has already been used for allocations weiAllocated = weiAllocated.add(contributions[contributor]); // Mint the respective tokens to the contributor token.mint(contributor, contributions[contributor].mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); // Set contributions to 0 contributions[contributor] = 0; // If all tokens were allocated, stop minting functionality // and send the remaining (rounding errors) tokens to the owner if (weiAllocated == weiContributed) { uint256 remaining = MAX_DTH.sub(token.totalSupply()); token.mint(owner, remaining); token.finishMinting(); } } /// @dev Called to allocate the tokens for presale address. function presaleAllocateTokens() external checkAllowed { require(!presaleAllocated); presaleAllocated = true; // Mint the respective tokens to the contributor token.mint(presaleAddress, PRESALE_WEI.mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); } function contribute() public payable checkAllowed { require(msg.value >= MIN_CONTRIBUTION); super.contribute(); } /// @dev The limit will be different for every address during the whitelist period, and after that phase there is no limit for contributions. function getContributionLimit(address userAddress) public view returns (uint256) { uint256 saleStartTime = getStageStartTime(SALE_IN_PROGRESS); // If not whitelisted or sale has not started, return 0 if (!whitelisted[userAddress] || block.timestamp < saleStartTime) { return 0; } // Are we in the first two days? bool whitelistingPeriod = block.timestamp - saleStartTime <= WHITELISTING_DURATION; // If we are in the whitelisting period, return the contribution limit for the user // If not, return the public max contribution return whitelistingPeriod ? presaleMaxContribution[userAddress] : PUBLIC_MAX_CONTRIBUTION; } function createTokenContract() internal returns(MintableToken) { return new DetherToken(); } function setupStages() internal { super.setupStages(); state.allowFunction(SETUP, this.performInitialAllocations.selector); state.allowFunction(SALE_ENDED, this.allocateTokens.selector); state.allowFunction(SALE_ENDED, this.presaleAllocateTokens.selector); } /// @dev The price will be the total wei contributed divided by the amount of tokens to be allocated to contributors. function calculatePrice() public view returns(uint256) { return weiContributed.add(PRESALE_WEI).div(60000000).add(1); } function onSaleEnded() internal { // Calculate DTH per Wei weiPerDTH = calculatePrice(); } }
getContributionLimit
function getContributionLimit(address userAddress) public view returns (uint256) { uint256 saleStartTime = getStageStartTime(SALE_IN_PROGRESS); // If not whitelisted or sale has not started, return 0 if (!whitelisted[userAddress] || block.timestamp < saleStartTime) { return 0; } // Are we in the first two days? bool whitelistingPeriod = block.timestamp - saleStartTime <= WHITELISTING_DURATION; // If we are in the whitelisting period, return the contribution limit for the user // If not, return the public max contribution return whitelistingPeriod ? presaleMaxContribution[userAddress] : PUBLIC_MAX_CONTRIBUTION; }
/// @dev The limit will be different for every address during the whitelist period, and after that phase there is no limit for contributions.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 5674, 6403 ] }
747
DetherToken
DetherToken.sol
0x5adc961d6ac3f7062d2ea45fefb8d8167d44b190
Solidity
DetherSale
contract DetherSale is Sale, Whitelistable { uint256 public constant PRESALE_WEI = 3956 ether * 1.15 + 490 ether; // Amount raised in the presale including bonus uint256 public constant DECIMALS_MULTIPLIER = 1000000000000000000; uint256 public constant MAX_DTH = 100000000 * DECIMALS_MULTIPLIER; // MAX_WEI - PRESALE_WEI // TODO: change to actual amount uint256 public constant WEI_CAP = 10554 ether; // Duration of the whitelisting phase uint256 public constant WHITELISTING_DURATION = 2 days; // Contribution limit for the whitelisting phase uint256 public constant WHITELISTING_MAX_CONTRIBUTION = 5 ether; // Contribution limit for the public sale uint256 public constant PUBLIC_MAX_CONTRIBUTION = 2**256 - 1; // Minimum contribution allowed uint256 public constant MIN_CONTRIBUTION = 0.1 ether; // wei per DTH uint256 public weiPerDTH; // true if the locked tokens have been distributed bool private lockedTokensDistributed; // true if the presale tokens have been allocated bool private presaleAllocated; // Address for the presale buyers (Dether team will distribute manually) address public presaleAddress; uint256 private weiAllocated; // Contribution limits specified for the presale mapping(address => uint256) public presaleMaxContribution; function DetherSale(address _wallet, address _presaleAddress) Sale(_wallet, WEI_CAP) public { presaleAddress = _presaleAddress; } /// @dev Distributes timed locked tokens function performInitialAllocations() external onlyOwner checkAllowed { require(lockedTokensDistributed == false); lockedTokensDistributed = true; // Advisors distributeTimelockedTokens(0x4dc976cEd66d1B87C099B338E1F1388AE657377d, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); // Bounty distributeTimelockedTokens(0xfEF675cC3068Ee798f2312e82B12c841157A0A0E, MAX_DTH.mul(3).div(100), now + 1 weeks); // Early Contributors distributeTimelockedTokens(0x8F38C4ddFE09Bd22545262FE160cf441D43d2489, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); distributeTimelockedTokens(0x87a4eb1c9fdef835DC9197FAff3E09b8007ADe5b, MAX_DTH.mul(25).div(1000), now + 6 * 4 weeks); // Strategic Partnerships distributeTimelockedTokens(0x6f63D5DF2D8644851cBb5F8607C845704C008284, MAX_DTH.mul(11).div(100), now + 1 weeks); // Team (locked 3 years, 6 months release) distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 2 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 3 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 4 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 5 * 6 * 4 weeks); distributeTimelockedTokens(0x24c14796f401D77fc401F9c2FA1dF42A136EbF83, MAX_DTH.mul(3).div(100), now + 6 * 6 * 4 weeks); } /// @dev Registers a user and sets the maximum contribution amount for the whitelisting period function registerPresaleContributor(address userAddress, uint256 maxContribution) external onlyOwner { // Specified contribution has to be lower than the max require(maxContribution <= WHITELISTING_MAX_CONTRIBUTION); // Register user (Whitelistable contract) registerUser(userAddress); // Set contribution presaleMaxContribution[userAddress] = maxContribution; } /// @dev Called to allocate the tokens depending on eth contributed. /// @param contributor The address of the contributor. function allocateTokens(address contributor) external checkAllowed { require(presaleAllocated); require(contributions[contributor] != 0); // We keep a record of how much wei contributed has already been used for allocations weiAllocated = weiAllocated.add(contributions[contributor]); // Mint the respective tokens to the contributor token.mint(contributor, contributions[contributor].mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); // Set contributions to 0 contributions[contributor] = 0; // If all tokens were allocated, stop minting functionality // and send the remaining (rounding errors) tokens to the owner if (weiAllocated == weiContributed) { uint256 remaining = MAX_DTH.sub(token.totalSupply()); token.mint(owner, remaining); token.finishMinting(); } } /// @dev Called to allocate the tokens for presale address. function presaleAllocateTokens() external checkAllowed { require(!presaleAllocated); presaleAllocated = true; // Mint the respective tokens to the contributor token.mint(presaleAddress, PRESALE_WEI.mul(DECIMALS_MULTIPLIER).div(weiPerDTH)); } function contribute() public payable checkAllowed { require(msg.value >= MIN_CONTRIBUTION); super.contribute(); } /// @dev The limit will be different for every address during the whitelist period, and after that phase there is no limit for contributions. function getContributionLimit(address userAddress) public view returns (uint256) { uint256 saleStartTime = getStageStartTime(SALE_IN_PROGRESS); // If not whitelisted or sale has not started, return 0 if (!whitelisted[userAddress] || block.timestamp < saleStartTime) { return 0; } // Are we in the first two days? bool whitelistingPeriod = block.timestamp - saleStartTime <= WHITELISTING_DURATION; // If we are in the whitelisting period, return the contribution limit for the user // If not, return the public max contribution return whitelistingPeriod ? presaleMaxContribution[userAddress] : PUBLIC_MAX_CONTRIBUTION; } function createTokenContract() internal returns(MintableToken) { return new DetherToken(); } function setupStages() internal { super.setupStages(); state.allowFunction(SETUP, this.performInitialAllocations.selector); state.allowFunction(SALE_ENDED, this.allocateTokens.selector); state.allowFunction(SALE_ENDED, this.presaleAllocateTokens.selector); } /// @dev The price will be the total wei contributed divided by the amount of tokens to be allocated to contributors. function calculatePrice() public view returns(uint256) { return weiContributed.add(PRESALE_WEI).div(60000000).add(1); } function onSaleEnded() internal { // Calculate DTH per Wei weiPerDTH = calculatePrice(); } }
calculatePrice
function calculatePrice() public view returns(uint256) { return weiContributed.add(PRESALE_WEI).div(60000000).add(1); }
/// @dev The price will be the total wei contributed divided by the amount of tokens to be allocated to contributors.
NatSpecSingleLine
v0.4.18+commit.9cf6e910
bzzr://31679c746f39dbdd5c090cd5514df308ef9098903284459826a5c4f30a8510bd
{ "func_code_index": [ 6950, 7088 ] }
748
xBAKC
contracts/xMAYC.sol
0xa3a7d67b14ccca2e94746c62728cd6c13f4601e3
Solidity
xBAKC
contract xBAKC is ERC721A, Ownable, ReentrancyGuard { using Strings for uint256; uint256 public PRICE; uint256 public MAX_SUPPLY; string private BASE_URI; uint256 public FREE_MINT_LIMIT_PER_WALLET; uint256 public MAX_MINT_AMOUNT_PER_TX; bool public IS_SALE_ACTIVE; uint256 public FREE_MINT_IS_ALLOWED_UNTIL; bool public METADATA_FROZEN; mapping(address => uint256) private freeMintCountMap; constructor( uint256 price, uint256 maxSupply, string memory baseUri, uint256 freeMintAllowance, uint256 maxMintPerTx, bool isSaleActive, uint256 freeMintIsAllowedUntil ) ERC721A("0xBAKC", "0xBAKC") { PRICE = price; MAX_SUPPLY = maxSupply; BASE_URI = baseUri; FREE_MINT_LIMIT_PER_WALLET = freeMintAllowance; MAX_MINT_AMOUNT_PER_TX = maxMintPerTx; IS_SALE_ACTIVE = isSaleActive; FREE_MINT_IS_ALLOWED_UNTIL = freeMintIsAllowedUntil; } /** FREE MINT **/ function updateFreeMintCount(address minter, uint256 count) private { freeMintCountMap[minter] += count; } /** GETTERS **/ function _baseURI() internal view virtual override returns (string memory) { return BASE_URI; } /** SETTERS **/ function setPrice(uint256 customPrice) external onlyOwner { PRICE = customPrice; } function lowerMaxSupply(uint256 newMaxSupply) external onlyOwner { require(newMaxSupply < MAX_SUPPLY, "Invalid new max supply"); require(newMaxSupply >= _currentIndex, "Invalid new max supply"); MAX_SUPPLY = newMaxSupply; } function setBaseURI(string memory customBaseURI_) external onlyOwner { require(!METADATA_FROZEN, "Metadata frozen!"); BASE_URI = customBaseURI_; } function setFreeMintAllowance(uint256 freeMintAllowance) external onlyOwner { FREE_MINT_LIMIT_PER_WALLET = freeMintAllowance; } function setMaxMintPerTx(uint256 maxMintPerTx) external onlyOwner { MAX_MINT_AMOUNT_PER_TX = maxMintPerTx; } function setSaleActive(bool saleIsActive) external onlyOwner { IS_SALE_ACTIVE = saleIsActive; } function setFreeMintAllowedUntil(uint256 freeMintIsAllowedUntil) external onlyOwner { FREE_MINT_IS_ALLOWED_UNTIL = freeMintIsAllowedUntil; } function freezeMetadata() external onlyOwner { METADATA_FROZEN = true; } /** MINT **/ modifier mintCompliance(uint256 _mintAmount) { require( _mintAmount > 0 && _mintAmount <= MAX_MINT_AMOUNT_PER_TX, "Invalid mint amount!" ); require( _currentIndex + _mintAmount <= MAX_SUPPLY, "Max supply exceeded!" ); _; } function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) { require(IS_SALE_ACTIVE, "Sale is not active!"); uint256 price = PRICE * _mintAmount; if (_currentIndex < FREE_MINT_IS_ALLOWED_UNTIL) { uint256 remainingFreeMint = FREE_MINT_LIMIT_PER_WALLET - freeMintCountMap[msg.sender]; if (remainingFreeMint > 0) { if (_mintAmount >= remainingFreeMint) { price -= remainingFreeMint * PRICE; updateFreeMintCount(msg.sender, remainingFreeMint); } else { price -= _mintAmount * PRICE; updateFreeMintCount(msg.sender, _mintAmount); } } } require(msg.value >= price, "Insufficient funds!"); _safeMint(msg.sender, _mintAmount); } function mintOwner(address _to, uint256 _mintAmount) public mintCompliance(_mintAmount) onlyOwner { _safeMint(_to, _mintAmount); } /** PAYOUT **/ address private constant payoutAddress1 = 0x688ceDCad62cC1d3901FD0300Afb079f6f79D74E; address private constant payoutAddress2 = 0x8641FEef38b67F8206945e2Ed49021113EcB8aEf; function withdraw() public onlyOwner nonReentrant { uint256 balance = address(this).balance; Address.sendValue(payable(payoutAddress1), (balance / 100) * 25); Address.sendValue(payable(payoutAddress2), (balance / 100) * 75); } }
updateFreeMintCount
function updateFreeMintCount(address minter, uint256 count) private { freeMintCountMap[minter] += count; }
/** FREE MINT **/
NatSpecMultiLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 1015, 1137 ] }
749
xBAKC
contracts/xMAYC.sol
0xa3a7d67b14ccca2e94746c62728cd6c13f4601e3
Solidity
xBAKC
contract xBAKC is ERC721A, Ownable, ReentrancyGuard { using Strings for uint256; uint256 public PRICE; uint256 public MAX_SUPPLY; string private BASE_URI; uint256 public FREE_MINT_LIMIT_PER_WALLET; uint256 public MAX_MINT_AMOUNT_PER_TX; bool public IS_SALE_ACTIVE; uint256 public FREE_MINT_IS_ALLOWED_UNTIL; bool public METADATA_FROZEN; mapping(address => uint256) private freeMintCountMap; constructor( uint256 price, uint256 maxSupply, string memory baseUri, uint256 freeMintAllowance, uint256 maxMintPerTx, bool isSaleActive, uint256 freeMintIsAllowedUntil ) ERC721A("0xBAKC", "0xBAKC") { PRICE = price; MAX_SUPPLY = maxSupply; BASE_URI = baseUri; FREE_MINT_LIMIT_PER_WALLET = freeMintAllowance; MAX_MINT_AMOUNT_PER_TX = maxMintPerTx; IS_SALE_ACTIVE = isSaleActive; FREE_MINT_IS_ALLOWED_UNTIL = freeMintIsAllowedUntil; } /** FREE MINT **/ function updateFreeMintCount(address minter, uint256 count) private { freeMintCountMap[minter] += count; } /** GETTERS **/ function _baseURI() internal view virtual override returns (string memory) { return BASE_URI; } /** SETTERS **/ function setPrice(uint256 customPrice) external onlyOwner { PRICE = customPrice; } function lowerMaxSupply(uint256 newMaxSupply) external onlyOwner { require(newMaxSupply < MAX_SUPPLY, "Invalid new max supply"); require(newMaxSupply >= _currentIndex, "Invalid new max supply"); MAX_SUPPLY = newMaxSupply; } function setBaseURI(string memory customBaseURI_) external onlyOwner { require(!METADATA_FROZEN, "Metadata frozen!"); BASE_URI = customBaseURI_; } function setFreeMintAllowance(uint256 freeMintAllowance) external onlyOwner { FREE_MINT_LIMIT_PER_WALLET = freeMintAllowance; } function setMaxMintPerTx(uint256 maxMintPerTx) external onlyOwner { MAX_MINT_AMOUNT_PER_TX = maxMintPerTx; } function setSaleActive(bool saleIsActive) external onlyOwner { IS_SALE_ACTIVE = saleIsActive; } function setFreeMintAllowedUntil(uint256 freeMintIsAllowedUntil) external onlyOwner { FREE_MINT_IS_ALLOWED_UNTIL = freeMintIsAllowedUntil; } function freezeMetadata() external onlyOwner { METADATA_FROZEN = true; } /** MINT **/ modifier mintCompliance(uint256 _mintAmount) { require( _mintAmount > 0 && _mintAmount <= MAX_MINT_AMOUNT_PER_TX, "Invalid mint amount!" ); require( _currentIndex + _mintAmount <= MAX_SUPPLY, "Max supply exceeded!" ); _; } function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) { require(IS_SALE_ACTIVE, "Sale is not active!"); uint256 price = PRICE * _mintAmount; if (_currentIndex < FREE_MINT_IS_ALLOWED_UNTIL) { uint256 remainingFreeMint = FREE_MINT_LIMIT_PER_WALLET - freeMintCountMap[msg.sender]; if (remainingFreeMint > 0) { if (_mintAmount >= remainingFreeMint) { price -= remainingFreeMint * PRICE; updateFreeMintCount(msg.sender, remainingFreeMint); } else { price -= _mintAmount * PRICE; updateFreeMintCount(msg.sender, _mintAmount); } } } require(msg.value >= price, "Insufficient funds!"); _safeMint(msg.sender, _mintAmount); } function mintOwner(address _to, uint256 _mintAmount) public mintCompliance(_mintAmount) onlyOwner { _safeMint(_to, _mintAmount); } /** PAYOUT **/ address private constant payoutAddress1 = 0x688ceDCad62cC1d3901FD0300Afb079f6f79D74E; address private constant payoutAddress2 = 0x8641FEef38b67F8206945e2Ed49021113EcB8aEf; function withdraw() public onlyOwner nonReentrant { uint256 balance = address(this).balance; Address.sendValue(payable(payoutAddress1), (balance / 100) * 25); Address.sendValue(payable(payoutAddress2), (balance / 100) * 75); } }
_baseURI
function _baseURI() internal view virtual override returns (string memory) { return BASE_URI; }
/** GETTERS **/
NatSpecMultiLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 1160, 1271 ] }
750
xBAKC
contracts/xMAYC.sol
0xa3a7d67b14ccca2e94746c62728cd6c13f4601e3
Solidity
xBAKC
contract xBAKC is ERC721A, Ownable, ReentrancyGuard { using Strings for uint256; uint256 public PRICE; uint256 public MAX_SUPPLY; string private BASE_URI; uint256 public FREE_MINT_LIMIT_PER_WALLET; uint256 public MAX_MINT_AMOUNT_PER_TX; bool public IS_SALE_ACTIVE; uint256 public FREE_MINT_IS_ALLOWED_UNTIL; bool public METADATA_FROZEN; mapping(address => uint256) private freeMintCountMap; constructor( uint256 price, uint256 maxSupply, string memory baseUri, uint256 freeMintAllowance, uint256 maxMintPerTx, bool isSaleActive, uint256 freeMintIsAllowedUntil ) ERC721A("0xBAKC", "0xBAKC") { PRICE = price; MAX_SUPPLY = maxSupply; BASE_URI = baseUri; FREE_MINT_LIMIT_PER_WALLET = freeMintAllowance; MAX_MINT_AMOUNT_PER_TX = maxMintPerTx; IS_SALE_ACTIVE = isSaleActive; FREE_MINT_IS_ALLOWED_UNTIL = freeMintIsAllowedUntil; } /** FREE MINT **/ function updateFreeMintCount(address minter, uint256 count) private { freeMintCountMap[minter] += count; } /** GETTERS **/ function _baseURI() internal view virtual override returns (string memory) { return BASE_URI; } /** SETTERS **/ function setPrice(uint256 customPrice) external onlyOwner { PRICE = customPrice; } function lowerMaxSupply(uint256 newMaxSupply) external onlyOwner { require(newMaxSupply < MAX_SUPPLY, "Invalid new max supply"); require(newMaxSupply >= _currentIndex, "Invalid new max supply"); MAX_SUPPLY = newMaxSupply; } function setBaseURI(string memory customBaseURI_) external onlyOwner { require(!METADATA_FROZEN, "Metadata frozen!"); BASE_URI = customBaseURI_; } function setFreeMintAllowance(uint256 freeMintAllowance) external onlyOwner { FREE_MINT_LIMIT_PER_WALLET = freeMintAllowance; } function setMaxMintPerTx(uint256 maxMintPerTx) external onlyOwner { MAX_MINT_AMOUNT_PER_TX = maxMintPerTx; } function setSaleActive(bool saleIsActive) external onlyOwner { IS_SALE_ACTIVE = saleIsActive; } function setFreeMintAllowedUntil(uint256 freeMintIsAllowedUntil) external onlyOwner { FREE_MINT_IS_ALLOWED_UNTIL = freeMintIsAllowedUntil; } function freezeMetadata() external onlyOwner { METADATA_FROZEN = true; } /** MINT **/ modifier mintCompliance(uint256 _mintAmount) { require( _mintAmount > 0 && _mintAmount <= MAX_MINT_AMOUNT_PER_TX, "Invalid mint amount!" ); require( _currentIndex + _mintAmount <= MAX_SUPPLY, "Max supply exceeded!" ); _; } function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) { require(IS_SALE_ACTIVE, "Sale is not active!"); uint256 price = PRICE * _mintAmount; if (_currentIndex < FREE_MINT_IS_ALLOWED_UNTIL) { uint256 remainingFreeMint = FREE_MINT_LIMIT_PER_WALLET - freeMintCountMap[msg.sender]; if (remainingFreeMint > 0) { if (_mintAmount >= remainingFreeMint) { price -= remainingFreeMint * PRICE; updateFreeMintCount(msg.sender, remainingFreeMint); } else { price -= _mintAmount * PRICE; updateFreeMintCount(msg.sender, _mintAmount); } } } require(msg.value >= price, "Insufficient funds!"); _safeMint(msg.sender, _mintAmount); } function mintOwner(address _to, uint256 _mintAmount) public mintCompliance(_mintAmount) onlyOwner { _safeMint(_to, _mintAmount); } /** PAYOUT **/ address private constant payoutAddress1 = 0x688ceDCad62cC1d3901FD0300Afb079f6f79D74E; address private constant payoutAddress2 = 0x8641FEef38b67F8206945e2Ed49021113EcB8aEf; function withdraw() public onlyOwner nonReentrant { uint256 balance = address(this).balance; Address.sendValue(payable(payoutAddress1), (balance / 100) * 25); Address.sendValue(payable(payoutAddress2), (balance / 100) * 75); } }
setPrice
function setPrice(uint256 customPrice) external onlyOwner { PRICE = customPrice; }
/** SETTERS **/
NatSpecMultiLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 1294, 1392 ] }
751
BancorBuyer
BancorBuyer.sol
0x6bd33d49d48f76abcd96652e5347e398aa3fda96
Solidity
BancorBuyer
contract BancorBuyer { // Store the amount of ETH deposited or BNT owned by each account. mapping (address => uint) public balances; // Reward for first to execute the buy. uint public reward; // Track whether the contract has bought the tokens yet. bool public bought_tokens; // Record the time the contract bought the tokens. uint public time_bought; // The Bancor Token Sale address. address sale = 0xBbc79794599b19274850492394004087cBf89710; // Bancor Smart Token Contract address. address token = 0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C; // The developer address. address developer = 0x4e6A1c57CdBfd97e8efe831f8f4418b1F2A09e6e; // Withdraws all ETH deposited by the sender. // Called to cancel a user's participation in the sale. function withdraw(){ // Store the user's balance prior to withdrawal in a temporary variable. uint amount = balances[msg.sender]; // Update the user's balance prior to sending ETH to prevent recursive call. balances[msg.sender] = 0; // Return the user's funds. Throws on failure to prevent loss of funds. msg.sender.transfer(amount); } // Allow anyone to contribute to the buy executer's reward. function add_reward() payable { // Update reward value to include received amount. reward += msg.value; } // Buys tokens in the crowdsale and rewards the caller, callable by anyone. function buy(){ // Record that the contract has bought the tokens. bought_tokens = true; // Record the time the contract bought the tokens. time_bought = now; // Transfer all the funds (less the caller reward) // to the Bancor crowdsale contract to buy tokens. // Throws if the crowdsale hasn't started yet or has // already completed, preventing loss of funds. CrowdsaleController(sale).contributeETH.value(this.balance - reward)(); // Reward the caller for being the first to execute the buy. msg.sender.transfer(reward); } // A helper function for the default function, allowing contracts to interact. function default_helper() payable { // Only allow deposits if the contract hasn't already purchased the tokens. if (!bought_tokens) { // Update records of deposited ETH to include the received amount. balances[msg.sender] += msg.value; } // Withdraw the sender's tokens if the contract has already purchased them. else { // Store the user's BNT balance in a temporary variable (1 ETHWei -> 100 BNTWei). uint amount = balances[msg.sender] * 100; // Update the user's balance prior to sending BNT to prevent recursive call. balances[msg.sender] = 0; // No fee for withdrawing during the crowdsale. uint fee = 0; // 1% fee for withdrawing after the crowdsale has ended. if (now > time_bought + 1 hours) { fee = amount / 100; } // Transfer the tokens to the sender and the developer. ERC20(token).transfer(msg.sender, amount - fee); ERC20(token).transfer(developer, fee); // Refund any ETH sent after the contract has already purchased tokens. msg.sender.transfer(msg.value); } } function () payable { default_helper(); } }
withdraw
function withdraw(){ // Store the user's balance prior to withdrawal in a temporary variable. uint amount = balances[msg.sender]; // Update the user's balance prior to sending ETH to prevent recursive call. balances[msg.sender] = 0; // Return the user's funds. Throws on failure to prevent loss of funds. msg.sender.transfer(amount); }
// Withdraws all ETH deposited by the sender. // Called to cancel a user's participation in the sale.
LineComment
v0.4.11+commit.68ef5810
bzzr://bf0736ae213424e929ec58ad488fe91cd5227e281620a943c3792f37619e04a6
{ "func_code_index": [ 793, 1165 ] }
752
BancorBuyer
BancorBuyer.sol
0x6bd33d49d48f76abcd96652e5347e398aa3fda96
Solidity
BancorBuyer
contract BancorBuyer { // Store the amount of ETH deposited or BNT owned by each account. mapping (address => uint) public balances; // Reward for first to execute the buy. uint public reward; // Track whether the contract has bought the tokens yet. bool public bought_tokens; // Record the time the contract bought the tokens. uint public time_bought; // The Bancor Token Sale address. address sale = 0xBbc79794599b19274850492394004087cBf89710; // Bancor Smart Token Contract address. address token = 0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C; // The developer address. address developer = 0x4e6A1c57CdBfd97e8efe831f8f4418b1F2A09e6e; // Withdraws all ETH deposited by the sender. // Called to cancel a user's participation in the sale. function withdraw(){ // Store the user's balance prior to withdrawal in a temporary variable. uint amount = balances[msg.sender]; // Update the user's balance prior to sending ETH to prevent recursive call. balances[msg.sender] = 0; // Return the user's funds. Throws on failure to prevent loss of funds. msg.sender.transfer(amount); } // Allow anyone to contribute to the buy executer's reward. function add_reward() payable { // Update reward value to include received amount. reward += msg.value; } // Buys tokens in the crowdsale and rewards the caller, callable by anyone. function buy(){ // Record that the contract has bought the tokens. bought_tokens = true; // Record the time the contract bought the tokens. time_bought = now; // Transfer all the funds (less the caller reward) // to the Bancor crowdsale contract to buy tokens. // Throws if the crowdsale hasn't started yet or has // already completed, preventing loss of funds. CrowdsaleController(sale).contributeETH.value(this.balance - reward)(); // Reward the caller for being the first to execute the buy. msg.sender.transfer(reward); } // A helper function for the default function, allowing contracts to interact. function default_helper() payable { // Only allow deposits if the contract hasn't already purchased the tokens. if (!bought_tokens) { // Update records of deposited ETH to include the received amount. balances[msg.sender] += msg.value; } // Withdraw the sender's tokens if the contract has already purchased them. else { // Store the user's BNT balance in a temporary variable (1 ETHWei -> 100 BNTWei). uint amount = balances[msg.sender] * 100; // Update the user's balance prior to sending BNT to prevent recursive call. balances[msg.sender] = 0; // No fee for withdrawing during the crowdsale. uint fee = 0; // 1% fee for withdrawing after the crowdsale has ended. if (now > time_bought + 1 hours) { fee = amount / 100; } // Transfer the tokens to the sender and the developer. ERC20(token).transfer(msg.sender, amount - fee); ERC20(token).transfer(developer, fee); // Refund any ETH sent after the contract has already purchased tokens. msg.sender.transfer(msg.value); } } function () payable { default_helper(); } }
add_reward
function add_reward() payable { // Update reward value to include received amount. reward += msg.value; }
// Allow anyone to contribute to the buy executer's reward.
LineComment
v0.4.11+commit.68ef5810
bzzr://bf0736ae213424e929ec58ad488fe91cd5227e281620a943c3792f37619e04a6
{ "func_code_index": [ 1233, 1354 ] }
753
BancorBuyer
BancorBuyer.sol
0x6bd33d49d48f76abcd96652e5347e398aa3fda96
Solidity
BancorBuyer
contract BancorBuyer { // Store the amount of ETH deposited or BNT owned by each account. mapping (address => uint) public balances; // Reward for first to execute the buy. uint public reward; // Track whether the contract has bought the tokens yet. bool public bought_tokens; // Record the time the contract bought the tokens. uint public time_bought; // The Bancor Token Sale address. address sale = 0xBbc79794599b19274850492394004087cBf89710; // Bancor Smart Token Contract address. address token = 0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C; // The developer address. address developer = 0x4e6A1c57CdBfd97e8efe831f8f4418b1F2A09e6e; // Withdraws all ETH deposited by the sender. // Called to cancel a user's participation in the sale. function withdraw(){ // Store the user's balance prior to withdrawal in a temporary variable. uint amount = balances[msg.sender]; // Update the user's balance prior to sending ETH to prevent recursive call. balances[msg.sender] = 0; // Return the user's funds. Throws on failure to prevent loss of funds. msg.sender.transfer(amount); } // Allow anyone to contribute to the buy executer's reward. function add_reward() payable { // Update reward value to include received amount. reward += msg.value; } // Buys tokens in the crowdsale and rewards the caller, callable by anyone. function buy(){ // Record that the contract has bought the tokens. bought_tokens = true; // Record the time the contract bought the tokens. time_bought = now; // Transfer all the funds (less the caller reward) // to the Bancor crowdsale contract to buy tokens. // Throws if the crowdsale hasn't started yet or has // already completed, preventing loss of funds. CrowdsaleController(sale).contributeETH.value(this.balance - reward)(); // Reward the caller for being the first to execute the buy. msg.sender.transfer(reward); } // A helper function for the default function, allowing contracts to interact. function default_helper() payable { // Only allow deposits if the contract hasn't already purchased the tokens. if (!bought_tokens) { // Update records of deposited ETH to include the received amount. balances[msg.sender] += msg.value; } // Withdraw the sender's tokens if the contract has already purchased them. else { // Store the user's BNT balance in a temporary variable (1 ETHWei -> 100 BNTWei). uint amount = balances[msg.sender] * 100; // Update the user's balance prior to sending BNT to prevent recursive call. balances[msg.sender] = 0; // No fee for withdrawing during the crowdsale. uint fee = 0; // 1% fee for withdrawing after the crowdsale has ended. if (now > time_bought + 1 hours) { fee = amount / 100; } // Transfer the tokens to the sender and the developer. ERC20(token).transfer(msg.sender, amount - fee); ERC20(token).transfer(developer, fee); // Refund any ETH sent after the contract has already purchased tokens. msg.sender.transfer(msg.value); } } function () payable { default_helper(); } }
buy
function buy(){ // Record that the contract has bought the tokens. bought_tokens = true; // Record the time the contract bought the tokens. time_bought = now; // Transfer all the funds (less the caller reward) // to the Bancor crowdsale contract to buy tokens. // Throws if the crowdsale hasn't started yet or has // already completed, preventing loss of funds. CrowdsaleController(sale).contributeETH.value(this.balance - reward)(); // Reward the caller for being the first to execute the buy. msg.sender.transfer(reward); }
// Buys tokens in the crowdsale and rewards the caller, callable by anyone.
LineComment
v0.4.11+commit.68ef5810
bzzr://bf0736ae213424e929ec58ad488fe91cd5227e281620a943c3792f37619e04a6
{ "func_code_index": [ 1438, 2025 ] }
754
BancorBuyer
BancorBuyer.sol
0x6bd33d49d48f76abcd96652e5347e398aa3fda96
Solidity
BancorBuyer
contract BancorBuyer { // Store the amount of ETH deposited or BNT owned by each account. mapping (address => uint) public balances; // Reward for first to execute the buy. uint public reward; // Track whether the contract has bought the tokens yet. bool public bought_tokens; // Record the time the contract bought the tokens. uint public time_bought; // The Bancor Token Sale address. address sale = 0xBbc79794599b19274850492394004087cBf89710; // Bancor Smart Token Contract address. address token = 0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C; // The developer address. address developer = 0x4e6A1c57CdBfd97e8efe831f8f4418b1F2A09e6e; // Withdraws all ETH deposited by the sender. // Called to cancel a user's participation in the sale. function withdraw(){ // Store the user's balance prior to withdrawal in a temporary variable. uint amount = balances[msg.sender]; // Update the user's balance prior to sending ETH to prevent recursive call. balances[msg.sender] = 0; // Return the user's funds. Throws on failure to prevent loss of funds. msg.sender.transfer(amount); } // Allow anyone to contribute to the buy executer's reward. function add_reward() payable { // Update reward value to include received amount. reward += msg.value; } // Buys tokens in the crowdsale and rewards the caller, callable by anyone. function buy(){ // Record that the contract has bought the tokens. bought_tokens = true; // Record the time the contract bought the tokens. time_bought = now; // Transfer all the funds (less the caller reward) // to the Bancor crowdsale contract to buy tokens. // Throws if the crowdsale hasn't started yet or has // already completed, preventing loss of funds. CrowdsaleController(sale).contributeETH.value(this.balance - reward)(); // Reward the caller for being the first to execute the buy. msg.sender.transfer(reward); } // A helper function for the default function, allowing contracts to interact. function default_helper() payable { // Only allow deposits if the contract hasn't already purchased the tokens. if (!bought_tokens) { // Update records of deposited ETH to include the received amount. balances[msg.sender] += msg.value; } // Withdraw the sender's tokens if the contract has already purchased them. else { // Store the user's BNT balance in a temporary variable (1 ETHWei -> 100 BNTWei). uint amount = balances[msg.sender] * 100; // Update the user's balance prior to sending BNT to prevent recursive call. balances[msg.sender] = 0; // No fee for withdrawing during the crowdsale. uint fee = 0; // 1% fee for withdrawing after the crowdsale has ended. if (now > time_bought + 1 hours) { fee = amount / 100; } // Transfer the tokens to the sender and the developer. ERC20(token).transfer(msg.sender, amount - fee); ERC20(token).transfer(developer, fee); // Refund any ETH sent after the contract has already purchased tokens. msg.sender.transfer(msg.value); } } function () payable { default_helper(); } }
default_helper
function default_helper() payable { // Only allow deposits if the contract hasn't already purchased the tokens. if (!bought_tokens) { // Update records of deposited ETH to include the received amount. balances[msg.sender] += msg.value; } // Withdraw the sender's tokens if the contract has already purchased them. else { // Store the user's BNT balance in a temporary variable (1 ETHWei -> 100 BNTWei). uint amount = balances[msg.sender] * 100; // Update the user's balance prior to sending BNT to prevent recursive call. balances[msg.sender] = 0; // No fee for withdrawing during the crowdsale. uint fee = 0; // 1% fee for withdrawing after the crowdsale has ended. if (now > time_bought + 1 hours) { fee = amount / 100; } // Transfer the tokens to the sender and the developer. ERC20(token).transfer(msg.sender, amount - fee); ERC20(token).transfer(developer, fee); // Refund any ETH sent after the contract has already purchased tokens. msg.sender.transfer(msg.value); } }
// A helper function for the default function, allowing contracts to interact.
LineComment
v0.4.11+commit.68ef5810
bzzr://bf0736ae213424e929ec58ad488fe91cd5227e281620a943c3792f37619e04a6
{ "func_code_index": [ 2112, 3244 ] }
755
CyberChainToken
CyberChainToken.sol
0x17e16d30a05324b44cf78df847137fa1220448f8
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } 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 a / b; } /** * @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 c) { c = a + b; assert(c >= a); return c; } }
/** * @title SafeMath * @dev Math operations with safety checks that throw on error * Name : CyberChain (Cyber) * Decimals : 8 * TotalSupply : 20000000000 * * * * */
NatSpecMultiLine
mul
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } c = a * b; assert(c / a == b); return c; }
/** * @dev Multiplies two numbers, throws on overflow. */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://5364046cd91ba3b793b25467ac20d6b1bf74eb3996d00349f67055cd45eabbf9
{ "func_code_index": [ 95, 302 ] }
756
CyberChainToken
CyberChainToken.sol
0x17e16d30a05324b44cf78df847137fa1220448f8
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } 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 a / b; } /** * @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 c) { c = a + b; assert(c >= a); return c; } }
/** * @title SafeMath * @dev Math operations with safety checks that throw on error * Name : CyberChain (Cyber) * Decimals : 8 * TotalSupply : 20000000000 * * * * */
NatSpecMultiLine
div
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 a / b; }
/** * @dev Integer division of two numbers, truncating the quotient. */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://5364046cd91ba3b793b25467ac20d6b1bf74eb3996d00349f67055cd45eabbf9
{ "func_code_index": [ 392, 692 ] }
757
CyberChainToken
CyberChainToken.sol
0x17e16d30a05324b44cf78df847137fa1220448f8
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } 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 a / b; } /** * @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 c) { c = a + b; assert(c >= a); return c; } }
/** * @title SafeMath * @dev Math operations with safety checks that throw on error * Name : CyberChain (Cyber) * Decimals : 8 * TotalSupply : 20000000000 * * * * */
NatSpecMultiLine
sub
function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; }
/** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://5364046cd91ba3b793b25467ac20d6b1bf74eb3996d00349f67055cd45eabbf9
{ "func_code_index": [ 812, 940 ] }
758
CyberChainToken
CyberChainToken.sol
0x17e16d30a05324b44cf78df847137fa1220448f8
Solidity
SafeMath
library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } 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 a / b; } /** * @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 c) { c = a + b; assert(c >= a); return c; } }
/** * @title SafeMath * @dev Math operations with safety checks that throw on error * Name : CyberChain (Cyber) * Decimals : 8 * TotalSupply : 20000000000 * * * * */
NatSpecMultiLine
add
function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; }
/** * @dev Adds two numbers, throws on overflow. */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://5364046cd91ba3b793b25467ac20d6b1bf74eb3996d00349f67055cd45eabbf9
{ "func_code_index": [ 1010, 1156 ] }
759
Mooniswap_ZapIn_V2
contracts/1inch/Mooniswap_ZapIn_V2.sol
0x1d0cb9498c81b264322a7a3570c6602f1d38f343
Solidity
Mooniswap_ZapIn_V2
contract Mooniswap_ZapIn_V2 is ZapInBaseV3_1 { using SafeERC20 for IERC20; address private constant wethTokenAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; constructor(uint256 _goodwill, uint256 _affiliateSplit) ZapBaseV2_1(_goodwill, _affiliateSplit) { // 0x exchange approvedTargets[0xDef1C0ded9bec7F1a1670819833240f027b25EfF] = true; } event zapIn(address sender, address pool, uint256 tokensRec); /** @notice Add liquidity to Mooniswap pools with ETH/ERC20 Tokens @param fromToken The ERC20 token used (address(0x00) if ether) @param amountIn The amount of fromToken to invest @param minPoolTokens Minimum quantity of pool tokens to receive. Reverts otherwise @param swapTarget Excecution target for the first swap @param swapData DEX quote data @param affiliate Affiliate address @param transferResidual Set false to save gas by donating the residual remaining after a Zap @return lpReceived Quantity of LP received */ function ZapIn( address fromToken, uint256 amountIn, address toPool, uint256 minPoolTokens, address intermediateToken, address swapTarget, bytes calldata swapData, address affiliate, bool transferResidual ) external payable stopInEmergency returns (uint256 lpReceived) { uint256 intermediateAmt; { // get incoming tokens uint256 toInvest = _pullTokens(fromToken, amountIn, affiliate, true); // get intermediate pool token intermediateAmt = _fillQuote( fromToken, intermediateToken, toInvest, swapTarget, swapData ); } // fetch pool tokens address[] memory tokens = IMooniswap(toPool).getTokens(); // divide intermediate into appropriate underlying tokens to add liquidity uint256[2] memory tokensBought = _swapIntermediate( toPool, tokens, intermediateToken, intermediateAmt ); // add liquidity lpReceived = _inchDeposit( tokens, tokensBought, toPool, transferResidual ); require(lpReceived >= minPoolTokens, "High Slippage"); } function _fillQuote( address _fromTokenAddress, address toToken, uint256 _amount, address _swapTarget, bytes memory swapData ) internal returns (uint256 amtBought) { if (_fromTokenAddress == toToken) { return _amount; } if (_fromTokenAddress == address(0) && toToken == wethTokenAddress) { IWETH(wethTokenAddress).deposit{ value: _amount }(); return _amount; } uint256 valueToSend; if (_fromTokenAddress == address(0)) { valueToSend = _amount; } else { _approveToken(_fromTokenAddress, _swapTarget); } uint256 iniBal = _getBalance(toToken); require(approvedTargets[_swapTarget], "Target not Authorized"); (bool success, ) = _swapTarget.call{ value: valueToSend }(swapData); require(success, "Error Swapping Tokens 1"); uint256 finalBal = _getBalance(toToken); amtBought = finalBal - iniBal; } function _getReserves(address token, address user) internal view returns (uint256 balance) { if (token == address(0)) { balance = user.balance; } else { balance = IERC20(token).balanceOf(user); } } function _swapIntermediate( address toPool, address[] memory tokens, address intermediateToken, uint256 intermediateAmt ) internal returns (uint256[2] memory tokensBought) { uint256[2] memory reserves = [_getReserves(tokens[0], toPool), _getReserves(tokens[1], toPool)]; if (intermediateToken == tokens[0]) { uint256 amountToSwap = calculateSwapInAmount(reserves[0], intermediateAmt); tokensBought[1] = _token2Token( intermediateToken, tokens[1], amountToSwap, toPool ); tokensBought[0] = intermediateAmt - amountToSwap; } else { uint256 amountToSwap = calculateSwapInAmount(reserves[1], intermediateAmt); tokensBought[0] = _token2Token( intermediateToken, tokens[0], amountToSwap, toPool ); tokensBought[1] = intermediateAmt - amountToSwap; } } function calculateSwapInAmount(uint256 reserveIn, uint256 userIn) internal pure returns (uint256) { return (Babylonian.sqrt( reserveIn * ((userIn * 3988000) + (reserveIn * 3988009)) ) - (reserveIn * 1997)) / 1994; } function _token2Token( address fromToken, address toToken, uint256 amount, address viaPool ) internal returns (uint256 tokenBought) { uint256 valueToSend; if (fromToken != address(0)) { _approveToken(fromToken, viaPool); } else { valueToSend = amount; } tokenBought = IMooniswap(viaPool).swap{ value: valueToSend }( IERC20(fromToken), IERC20(toToken), amount, 0, address(0) ); require(tokenBought > 0, "Error Swapping Tokens 2"); } function _inchDeposit( address[] memory tokens, uint256[2] memory amounts, address toPool, bool transferResidual ) internal returns (uint256 lpReceived) { uint256[2] memory minAmounts; uint256[2] memory receivedAmounts; // tokens[1] is never ETH, approving for both cases _approveToken(tokens[1], toPool); if (tokens[0] == address(0)) { (lpReceived, receivedAmounts) = IMooniswap(toPool).depositFor{ value: amounts[0] }([amounts[0], amounts[1]], minAmounts, msg.sender); } else { _approveToken(tokens[0], toPool); (lpReceived, receivedAmounts) = IMooniswap(toPool).depositFor( [amounts[0], amounts[1]], minAmounts, msg.sender ); } emit zapIn(msg.sender, toPool, lpReceived); if (transferResidual) { // transfer any residue if (amounts[0] > receivedAmounts[0]) { _transferTokens(tokens[0], amounts[0] - receivedAmounts[0]); } if (amounts[1] > receivedAmounts[1]) { _transferTokens(tokens[1], amounts[1] - receivedAmounts[1]); } } } function _transferTokens(address token, uint256 amt) internal { if (token == address(0)) { Address.sendValue(payable(msg.sender), amt); } else { IERC20(token).safeTransfer(msg.sender, amt); } } }
ZapIn
function ZapIn( address fromToken, uint256 amountIn, address toPool, uint256 minPoolTokens, address intermediateToken, address swapTarget, bytes calldata swapData, address affiliate, bool transferResidual ) external payable stopInEmergency returns (uint256 lpReceived) { uint256 intermediateAmt; { // get incoming tokens uint256 toInvest = _pullTokens(fromToken, amountIn, affiliate, true); // get intermediate pool token intermediateAmt = _fillQuote( fromToken, intermediateToken, toInvest, swapTarget, swapData ); } // fetch pool tokens address[] memory tokens = IMooniswap(toPool).getTokens(); // divide intermediate into appropriate underlying tokens to add liquidity uint256[2] memory tokensBought = _swapIntermediate( toPool, tokens, intermediateToken, intermediateAmt ); // add liquidity lpReceived = _inchDeposit( tokens, tokensBought, toPool, transferResidual ); require(lpReceived >= minPoolTokens, "High Slippage"); }
/** @notice Add liquidity to Mooniswap pools with ETH/ERC20 Tokens @param fromToken The ERC20 token used (address(0x00) if ether) @param amountIn The amount of fromToken to invest @param minPoolTokens Minimum quantity of pool tokens to receive. Reverts otherwise @param swapTarget Excecution target for the first swap @param swapData DEX quote data @param affiliate Affiliate address @param transferResidual Set false to save gas by donating the residual remaining after a Zap @return lpReceived Quantity of LP received */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
GNU GPLv2
{ "func_code_index": [ 1036, 2434 ] }
760
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); }
/// @dev Fallback function allows to deposit ether.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 2228, 2345 ] }
761
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
addOwner
function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); }
/// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 3079, 3376 ] }
762
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
removeOwner
function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); }
/// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 3498, 3996 ] }
763
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
replaceOwner
function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); }
/// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 4195, 4687 ] }
764
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
changeRequirement
function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); }
/// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 4857, 5081 ] }
765
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
submitTransaction
function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); }
/// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 5342, 5597 ] }
766
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
confirmTransaction
function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); }
/// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 5702, 6065 ] }
767
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
revokeConfirmation
function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); }
/// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 6188, 6497 ] }
768
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
executeTransaction
function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } }
/// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 6610, 7281 ] }
769
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
isConfirmed
function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } }
/// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 7432, 7790 ] }
770
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
addTransaction
function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); }
/// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 8128, 8604 ] }
771
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
getConfirmationCount
function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } }
/// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 8804, 9086 ] }
772
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
getTransactionCount
function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } }
/// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 9349, 9679 ] }
773
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
getOwners
function getOwners() public constant returns (address[]) { return owners; }
/// @dev Returns list of owners. /// @return List of owner addresses.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 9762, 9888 ] }
774
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
getConfirmations
function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } }
/// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 10067, 10697 ] }
775
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiMultiSigWallet
contract NamiMultiSigWallet { uint constant public MAX_OWNER_COUNT = 50; event Confirmation(address indexed sender, uint indexed transactionId); event Revocation(address indexed sender, uint indexed transactionId); event Submission(uint indexed transactionId); event Execution(uint indexed transactionId); event ExecutionFailure(uint indexed transactionId); event Deposit(address indexed sender, uint value); event OwnerAddition(address indexed owner); event OwnerRemoval(address indexed owner); event RequirementChange(uint required); mapping (uint => Transaction) public transactions; mapping (uint => mapping (address => bool)) public confirmations; mapping (address => bool) public isOwner; address[] public owners; uint public required; uint public transactionCount; struct Transaction { address destination; uint value; bytes data; bool executed; } modifier onlyWallet() { require(msg.sender == address(this)); _; } modifier ownerDoesNotExist(address owner) { require(!isOwner[owner]); _; } modifier ownerExists(address owner) { require(isOwner[owner]); _; } modifier transactionExists(uint transactionId) { require(transactions[transactionId].destination != 0); _; } modifier confirmed(uint transactionId, address owner) { require(confirmations[transactionId][owner]); _; } modifier notConfirmed(uint transactionId, address owner) { require(!confirmations[transactionId][owner]); _; } modifier notExecuted(uint transactionId) { require(!transactions[transactionId].executed); _; } modifier notNull(address _address) { require(_address != 0); _; } modifier validRequirement(uint ownerCount, uint _required) { require(!(ownerCount > MAX_OWNER_COUNT || _required > ownerCount || _required == 0 || ownerCount == 0)); _; } /// @dev Fallback function allows to deposit ether. function() public payable { if (msg.value > 0) emit Deposit(msg.sender, msg.value); } /* * Public functions */ /// @dev Contract constructor sets initial owners and required number of confirmations. /// @param _owners List of initial owners. /// @param _required Number of required confirmations. constructor(address[] _owners, uint _required) public validRequirement(_owners.length, _required) { for (uint i = 0; i < _owners.length; i++) { require(!(isOwner[_owners[i]] || _owners[i] == 0)); isOwner[_owners[i]] = true; } owners = _owners; required = _required; } /// @dev Allows to add a new owner. Transaction has to be sent by wallet. /// @param owner Address of new owner. function addOwner(address owner) public onlyWallet ownerDoesNotExist(owner) notNull(owner) validRequirement(owners.length + 1, required) { isOwner[owner] = true; owners.push(owner); emit OwnerAddition(owner); } /// @dev Allows to remove an owner. Transaction has to be sent by wallet. /// @param owner Address of owner. function removeOwner(address owner) public onlyWallet ownerExists(owner) { isOwner[owner] = false; for (uint i=0; i<owners.length - 1; i++) { if (owners[i] == owner) { owners[i] = owners[owners.length - 1]; break; } } owners.length -= 1; if (required > owners.length) changeRequirement(owners.length); emit OwnerRemoval(owner); } /// @dev Allows to replace an owner with a new owner. Transaction has to be sent by wallet. /// @param owner Address of owner to be replaced. /// @param owner Address of new owner. function replaceOwner(address owner, address newOwner) public onlyWallet ownerExists(owner) ownerDoesNotExist(newOwner) { for (uint i=0; i<owners.length; i++) { if (owners[i] == owner) { owners[i] = newOwner; break; } } isOwner[owner] = false; isOwner[newOwner] = true; emit OwnerRemoval(owner); emit OwnerAddition(newOwner); } /// @dev Allows to change the number of required confirmations. Transaction has to be sent by wallet. /// @param _required Number of required confirmations. function changeRequirement(uint _required) public onlyWallet validRequirement(owners.length, _required) { required = _required; emit RequirementChange(_required); } /// @dev Allows an owner to submit and confirm a transaction. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function submitTransaction(address destination, uint value, bytes data) public returns (uint transactionId) { transactionId = addTransaction(destination, value, data); confirmTransaction(transactionId); } /// @dev Allows an owner to confirm a transaction. /// @param transactionId Transaction ID. function confirmTransaction(uint transactionId) public ownerExists(msg.sender) transactionExists(transactionId) notConfirmed(transactionId, msg.sender) { confirmations[transactionId][msg.sender] = true; emit Confirmation(msg.sender, transactionId); executeTransaction(transactionId); } /// @dev Allows an owner to revoke a confirmation for a transaction. /// @param transactionId Transaction ID. function revokeConfirmation(uint transactionId) public ownerExists(msg.sender) confirmed(transactionId, msg.sender) notExecuted(transactionId) { confirmations[transactionId][msg.sender] = false; emit Revocation(msg.sender, transactionId); } /// @dev Allows anyone to execute a confirmed transaction. /// @param transactionId Transaction ID. function executeTransaction(uint transactionId) public notExecuted(transactionId) { if (isConfirmed(transactionId)) { // Transaction tx = transactions[transactionId]; transactions[transactionId].executed = true; // tx.executed = true; if (transactions[transactionId].destination.call.value(transactions[transactionId].value)(transactions[transactionId].data)) { emit Execution(transactionId); } else { emit ExecutionFailure(transactionId); transactions[transactionId].executed = false; } } } /// @dev Returns the confirmation status of a transaction. /// @param transactionId Transaction ID. /// @return Confirmation status. function isConfirmed(uint transactionId) public constant returns (bool) { uint count = 0; for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; if (count == required) return true; } } /* * Internal functions */ /// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param data Transaction data payload. /// @return Returns transaction ID. function addTransaction(address destination, uint value, bytes data) internal notNull(destination) returns (uint transactionId) { transactionId = transactionCount; transactions[transactionId] = Transaction({ destination: destination, value: value, data: data, executed: false }); transactionCount += 1; emit Submission(transactionId); } /* * Web3 call functions */ /// @dev Returns number of confirmations of a transaction. /// @param transactionId Transaction ID. /// @return Number of confirmations. function getConfirmationCount(uint transactionId) public constant returns (uint count) { for (uint i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) count += 1; } } /// @dev Returns total number of transactions after filers are applied. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Total number of transactions after filters are applied. function getTransactionCount(bool pending, bool executed) public constant returns (uint count) { for (uint i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) count += 1; } } /// @dev Returns list of owners. /// @return List of owner addresses. function getOwners() public constant returns (address[]) { return owners; } /// @dev Returns array with owner addresses, which confirmed transaction. /// @param transactionId Transaction ID. /// @return Returns array of owner addresses. function getConfirmations(uint transactionId) public constant returns (address[] _confirmations) { address[] memory confirmationsTemp = new address[](owners.length); uint count = 0; uint i; for (i = 0; i < owners.length; i++) { if (confirmations[transactionId][owners[i]]) { confirmationsTemp[count] = owners[i]; count += 1; } } _confirmations = new address[](count); for (i = 0; i < count; i++) { _confirmations[i] = confirmationsTemp[i]; } } /// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs. function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } } }
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
NatSpecSingleLine
getTransactionIds
function getTransactionIds(uint from, uint to, bool pending, bool executed) public constant returns (uint[] _transactionIds) { uint[] memory transactionIdsTemp = new uint[](transactionCount); uint count = 0; uint i; for (i = 0; i < transactionCount; i++) { if (pending && !transactions[i].executed || executed && transactions[i].executed) { transactionIdsTemp[count] = i; count += 1; } } _transactionIds = new uint[](to - from); for (i = from; i < to; i++) { _transactionIds[i - from] = transactionIdsTemp[i]; } }
/// @dev Returns list of transaction IDs in defined range. /// @param from Index start position of transaction array. /// @param to Index end position of transaction array. /// @param pending Include pending transactions. /// @param executed Include executed transactions. /// @return Returns array of transaction IDs.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 11049, 11749 ] }
776
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
ERC223ReceivingContract
contract ERC223ReceivingContract { /** * @dev Standard ERC223 function that will handle incoming token transfers. * * @param _from Token sender address. * @param _value Amount of tokens. * @param _data Transaction metadata. */ function tokenFallback(address _from, uint _value, bytes _data) public returns (bool success); function tokenFallbackBuyer(address _from, uint _value, address _buyer) public returns (bool success); function tokenFallbackExchange(address _from, uint _value, uint _price) public returns (bool success); }
/** * @title Contract that will work with ERC223 tokens. */
NatSpecMultiLine
tokenFallback
function tokenFallback(address _from, uint _value, bytes _data) public returns (bool success);
/** * @dev Standard ERC223 function that will handle incoming token transfers. * * @param _from Token sender address. * @param _value Amount of tokens. * @param _data Transaction metadata. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 243, 342 ] }
777
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
_transfer
function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); }
/** * Internal transfer, only can be called by this contract */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 2653, 3500 ] }
778
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
transferForTeam
function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); }
// Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale)
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 3636, 3780 ] }
779
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
transfer
function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); }
/** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 3990, 4132 ] }
780
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; }
/** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 4414, 4764 ] }
781
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
approve
function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; }
/** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 5028, 5235 ] }
782
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
approveAndCall
function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } }
/** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 5629, 6012 ] }
783
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
changeTransferable
function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; }
// allows transfer token
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 6045, 6160 ] }
784
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
changeEscrow
function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; }
// change escrow
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 6189, 6340 ] }
785
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
changeBinary
function changeBinary(uint _binary) public onlyEscrow { binary = _binary; }
// change binary value
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 6375, 6492 ] }
786
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
changeBinaryAddress
function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; }
// change binary address
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 6529, 6718 ] }
787
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
getPrice
function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } }
/* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */
Comment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 7566, 8668 ] }
788
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
burnTokens
function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } }
/// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner.
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 9566, 10197 ] }
789
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
setPresalePhase
function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); }
/*/ * Administrative functions /*/
Comment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 10254, 11164 ] }
790
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
_migrateToken
function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); }
// internal migrate migration tokens
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 12025, 12591 ] }
791
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
migrateToken
function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); }
// migate token function for Nami Team
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 12638, 12769 ] }
792
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
migrateForInvestor
function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); }
// migrate token for investor
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 12807, 12905 ] }
793
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
transferToExchange
function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } }
/** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 13720, 14361 ] }
794
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiCrowdSale
contract NamiCrowdSale { using SafeMath for uint256; /// NAC Broker Presale Token /// @dev Constructor constructor(address _escrow, address _namiMultiSigWallet, address _namiPresale) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; namiPresale = _namiPresale; } /*/ * Constants /*/ string public name = "Nami ICO"; string public symbol = "NAC"; uint public decimals = 18; bool public TRANSFERABLE = false; // default not transferable uint public constant TOKEN_SUPPLY_LIMIT = 1000000000 * (1 ether / 1 wei); uint public binary = 0; /*/ * Token state /*/ enum Phase { Created, Running, Paused, Migrating, Migrated } Phase public currentPhase = Phase.Created; uint public totalSupply = 0; // amount of tokens already sold // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; // nami presale contract address public namiPresale; // Crowdsale manager has exclusive priveleges to burn presale tokens. address public crowdsaleManager; // binary option address address public binaryAddress; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; modifier onlyCrowdsaleManager() { require(msg.sender == crowdsaleManager); _; } modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyTranferable() { require(TRANSFERABLE); _; } modifier onlyNamiMultisig() { require(msg.sender == namiMultiSigWallet); _; } /*/ * Events /*/ event LogBuy(address indexed owner, uint value); event LogBurn(address indexed owner, uint value); event LogPhaseSwitch(Phase newPhase); // Log migrate token event LogMigrate(address _from, address _to, uint256 amount); // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); /*/ * Public functions /*/ /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value > balanceOf[_to]); // Save this for an assertion in the future uint previousBalances = balanceOf[_from] + balanceOf[_to]; // Subtract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; emit Transfer(_from, _to, _value); // Asserts are used to use static analysis to find bugs in your code. They should never fail assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } // Transfer the balance from owner's account to another account // only escrow can send token (to send token private sale) function transferForTeam(address _to, uint256 _value) public onlyEscrow { _transfer(msg.sender, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public onlyTranferable { _transfer(msg.sender, _to, _value); } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public onlyTranferable returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public onlyTranferable returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it * * @param _spender The address authorized to spend * @param _value the max amount they can spend * @param _extraData some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public onlyTranferable returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if (approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } // allows transfer token function changeTransferable () public onlyEscrow { TRANSFERABLE = !TRANSFERABLE; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // change binary value function changeBinary(uint _binary) public onlyEscrow { binary = _binary; } // change binary address function changeBinaryAddress(address _binaryAddress) public onlyEscrow { require(_binaryAddress != 0x0); binaryAddress = _binaryAddress; } /* * price in ICO: * first week: 1 ETH = 2400 NAC * second week: 1 ETH = 23000 NAC * 3rd week: 1 ETH = 2200 NAC * 4th week: 1 ETH = 2100 NAC * 5th week: 1 ETH = 2000 NAC * 6th week: 1 ETH = 1900 NAC * 7th week: 1 ETH = 1800 NAC * 8th week: 1 ETH = 1700 nac * time: * 1517443200: Thursday, February 1, 2018 12:00:00 AM * 1518048000: Thursday, February 8, 2018 12:00:00 AM * 1518652800: Thursday, February 15, 2018 12:00:00 AM * 1519257600: Thursday, February 22, 2018 12:00:00 AM * 1519862400: Thursday, March 1, 2018 12:00:00 AM * 1520467200: Thursday, March 8, 2018 12:00:00 AM * 1521072000: Thursday, March 15, 2018 12:00:00 AM * 1521676800: Thursday, March 22, 2018 12:00:00 AM * 1522281600: Thursday, March 29, 2018 12:00:00 AM */ function getPrice() public view returns (uint price) { if (now < 1517443200) { // presale return 3450; } else if (1517443200 < now && now <= 1518048000) { // 1st week return 2400; } else if (1518048000 < now && now <= 1518652800) { // 2nd week return 2300; } else if (1518652800 < now && now <= 1519257600) { // 3rd week return 2200; } else if (1519257600 < now && now <= 1519862400) { // 4th week return 2100; } else if (1519862400 < now && now <= 1520467200) { // 5th week return 2000; } else if (1520467200 < now && now <= 1521072000) { // 6th week return 1900; } else if (1521072000 < now && now <= 1521676800) { // 7th week return 1800; } else if (1521676800 < now && now <= 1522281600) { // 8th week return 1700; } else { return binary; } } function() payable public { buy(msg.sender); } function buy(address _buyer) payable public { // Available only if presale is running. require(currentPhase == Phase.Running); // require ICO time or binary option require(now <= 1522281600 || msg.sender == binaryAddress); require(msg.value != 0); uint newTokens = msg.value * getPrice(); require (totalSupply + newTokens < TOKEN_SUPPLY_LIMIT); // add new token to buyer balanceOf[_buyer] = balanceOf[_buyer].add(newTokens); // add new token to totalSupply totalSupply = totalSupply.add(newTokens); emit LogBuy(_buyer,newTokens); emit Transfer(this,_buyer,newTokens); } /// @dev Returns number of tokens owned by given address. /// @param _owner Address of token owner. function burnTokens(address _owner) public onlyCrowdsaleManager { // Available only during migration phase require(currentPhase == Phase.Migrating); uint tokens = balanceOf[_owner]; require(tokens != 0); balanceOf[_owner] = 0; totalSupply -= tokens; emit LogBurn(_owner, tokens); emit Transfer(_owner, crowdsaleManager, tokens); // Automatically switch phase when migration is done. if (totalSupply == 0) { currentPhase = Phase.Migrated; emit LogPhaseSwitch(Phase.Migrated); } } /*/ * Administrative functions /*/ function setPresalePhase(Phase _nextPhase) public onlyEscrow { bool canSwitchPhase = (currentPhase == Phase.Created && _nextPhase == Phase.Running) || (currentPhase == Phase.Running && _nextPhase == Phase.Paused) // switch to migration phase only if crowdsale manager is set || ((currentPhase == Phase.Running || currentPhase == Phase.Paused) && _nextPhase == Phase.Migrating && crowdsaleManager != 0x0) || (currentPhase == Phase.Paused && _nextPhase == Phase.Running) // switch to migrated only if everyting is migrated || (currentPhase == Phase.Migrating && _nextPhase == Phase.Migrated && totalSupply == 0); require(canSwitchPhase); currentPhase = _nextPhase; emit LogPhaseSwitch(_nextPhase); } function withdrawEther(uint _amount) public onlyEscrow { require(namiMultiSigWallet != 0x0); // Available at any phase. if (address(this).balance > 0) { namiMultiSigWallet.transfer(_amount); } } function safeWithdraw(address _withdraw, uint _amount) public onlyEscrow { NamiMultiSigWallet namiWallet = NamiMultiSigWallet(namiMultiSigWallet); if (namiWallet.isOwner(_withdraw)) { _withdraw.transfer(_amount); } } function setCrowdsaleManager(address _mgr) public onlyEscrow { // You can't change crowdsale contract when migration is in progress. require(currentPhase != Phase.Migrating); crowdsaleManager = _mgr; } // internal migrate migration tokens function _migrateToken(address _from, address _to) internal { PresaleToken presale = PresaleToken(namiPresale); uint256 newToken = presale.balanceOf(_from); require(newToken > 0); // burn old token presale.burnTokens(_from); // add new token to _to balanceOf[_to] = balanceOf[_to].add(newToken); // add new token to totalSupply totalSupply = totalSupply.add(newToken); emit LogMigrate(_from, _to, newToken); emit Transfer(this,_to,newToken); } // migate token function for Nami Team function migrateToken(address _from, address _to) public onlyEscrow { _migrateToken(_from, _to); } // migrate token for investor function migrateForInvestor() public { _migrateToken(msg.sender, msg.sender); } // Nami internal exchange // event for Nami exchange event TransferToBuyer(address indexed _from, address indexed _to, uint _value, address indexed _seller); event TransferToExchange(address indexed _from, address indexed _to, uint _value, uint _price); /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackExchange` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackExchange` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _price price to sell token. */ function transferToExchange(address _to, uint _value, uint _price) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackExchange(msg.sender, _value, _price); emit TransferToExchange(msg.sender, _to, _value, _price); } } /** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */ function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } } //------------------------------------------------------------------------------------------------------- }
transferToBuyer
function transferToBuyer(address _to, uint _value, address _buyer) public { uint codeLength; assembly { codeLength := extcodesize(_to) } balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(msg.sender,_to,_value); if (codeLength > 0) { ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); receiver.tokenFallbackBuyer(msg.sender, _value, _buyer); emit TransferToBuyer(msg.sender, _to, _value, _buyer); } }
/** * @dev Transfer the specified amount of tokens to the NamiExchange address. * Invokes the `tokenFallbackBuyer` function. * The token transfer fails if the recipient is a contract * but does not implement the `tokenFallbackBuyer` function * or the fallback function to receive funds. * * @param _to Receiver address. * @param _value Amount of tokens that will be transferred. * @param _buyer address of seller. */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 14880, 15515 ] }
795
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
DSMath
contract DSMath { function add(uint x, uint y) internal pure returns (uint z) { require((z = x + y) >= x); } function sub(uint x, uint y) internal pure returns (uint z) { require((z = x - y) <= x); } function mul(uint x, uint y) internal pure returns (uint z) { require(y == 0 || (z = x * y) / y == x); } function min(uint x, uint y) internal pure returns (uint z) { return x <= y ? x : y; } function max(uint x, uint y) internal pure returns (uint z) { return x >= y ? x : y; } function imin(int x, int y) internal pure returns (int z) { return x <= y ? x : y; } function imax(int x, int y) internal pure returns (int z) { return x >= y ? x : y; } uint constant WAD = 10 ** 18; uint constant RAY = 10 ** 27; function wmul(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, y), WAD / 2) / WAD; } function rmul(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, y), RAY / 2) / RAY; } function wdiv(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, WAD), y / 2) / y; } function rdiv(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, RAY), y / 2) / y; } // This famous algorithm is called "exponentiation by squaring" // and calculates x^n with x as fixed-point and n as regular unsigned. // // It's O(log n), instead of O(n) for naive repeated multiplication. // // These facts are why it works: // // If n is even, then x^n = (x^2)^(n/2). // If n is odd, then x^n = x * x^(n-1), // and applying the equation for even x gives // x^n = x * (x^2)^((n-1) / 2). // // Also, EVM division is flooring and // floor[(n-1) / 2] = floor[n / 2]. // function rpow(uint x, uint n) internal pure returns (uint z) { z = n % 2 != 0 ? x : RAY; for (n /= 2; n != 0; n /= 2) { x = rmul(x, x); if (n % 2 != 0) { z = rmul(z, x); } } } }
rpow
function rpow(uint x, uint n) internal pure returns (uint z) { z = n % 2 != 0 ? x : RAY; for (n /= 2; n != 0; n /= 2) { x = rmul(x, x); if (n % 2 != 0) { z = rmul(z, x); } } }
// This famous algorithm is called "exponentiation by squaring" // and calculates x^n with x as fixed-point and n as regular unsigned. // // It's O(log n), instead of O(n) for naive repeated multiplication. // // These facts are why it works: // // If n is even, then x^n = (x^2)^(n/2). // If n is odd, then x^n = x * x^(n-1), // and applying the equation for even x gives // x^n = x * (x^2)^((n-1) / 2). // // Also, EVM division is flooring and // floor[(n-1) / 2] = floor[n / 2]. //
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 1905, 2177 ] }
796
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
DSToken
contract DSToken is DSTokenBase(10000000000000000000000000), DSStop { bytes32 public symbol; uint256 public decimals = 18; // standard token precision. override to customize function DSToken(bytes32 symbol_) public { symbol = symbol_; } event Mint(address indexed guy, uint wad); event Burn(address indexed guy, uint wad); function approve(address guy) public stoppable returns (bool) { return super.approve(guy, uint(-1)); } function approve(address guy, uint wad) public stoppable returns (bool) { return super.approve(guy, wad); } function transferFrom(address src, address dst, uint wad) public stoppable returns (bool) { if (src != msg.sender && _approvals[src][msg.sender] != uint(-1)) { _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad); } _balances[src] = sub(_balances[src], wad); _balances[dst] = add(_balances[dst], wad); Transfer(src, dst, wad); return true; } function push(address dst, uint wad) public { transferFrom(msg.sender, dst, wad); } function pull(address src, uint wad) public { transferFrom(src, msg.sender, wad); } function move(address src, address dst, uint wad) public { transferFrom(src, dst, wad); } function mint(uint wad) public { mint(msg.sender, wad); } function burn(uint wad) public { burn(msg.sender, wad); } function mint(address guy, uint wad) public auth stoppable { _balances[guy] = add(_balances[guy], wad); _supply = add(_supply, wad); Mint(guy, wad); } function burn(address guy, uint wad) public auth stoppable { if (guy != msg.sender && _approvals[guy][msg.sender] != uint(-1)) { _approvals[guy][msg.sender] = sub(_approvals[guy][msg.sender], wad); } _balances[guy] = sub(_balances[guy], wad); _supply = sub(_supply, wad); Burn(guy, wad); } // Optional token name bytes32 public name = ""; function setName(bytes32 name_) public auth { name = name_; } }
/* import "./base.sol"; */
Comment
DSToken
function DSToken(bytes32 symbol_) public { symbol = symbol_; }
// standard token precision. override to customize
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 193, 274 ] }
797
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiTradeDai
contract NamiTradeDai{ using SafeMath for uint256; constructor(address _escrow, address _namiMultiSigWallet, address _namiAddress, address _daiAddress) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; NamiAddr = _namiAddress; DaiAddress = _daiAddress; } // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; uint public minWithdraw = 10 * 10**18; // 10 DAI uint public maxWithdraw = 100 * 10**18; // max DAI withdraw one time // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; address public DaiAddress; /// address of Nami token address public NamiAddr; /** * list setting function */ mapping(address => bool) public isController; /** * List event */ event Withdraw(address indexed user, uint amount, uint timeWithdraw); modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyNamiMultisig { require(msg.sender == namiMultiSigWallet); _; } modifier onlyController { require(isController[msg.sender] == true); _; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // min and max for withdraw nac function changeMinWithdraw(uint _minWithdraw) public onlyEscrow { require(_minWithdraw != 0); minWithdraw = _minWithdraw; } function changeMaxWithdraw(uint _maxNac) public onlyEscrow { require(_maxNac != 0); maxWithdraw = _maxNac; } /// @dev withdraw ether to nami multisignature wallet, only escrow can call /// @param _amount value ether in wei to withdraw function withdrawEther(uint _amount, address _to) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. if (address(this).balance > 0) { _to.transfer(_amount); } } /// @dev withdraw NAC to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawNac(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. NamiCrowdSale namiToken = NamiCrowdSale(NamiAddr); if (namiToken.balanceOf(address(this)) > 0) { namiToken.transfer(namiMultiSigWallet, _amount); } } /// @dev withdraw DAI to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawDai(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) > 0) { DAIToken.transfer(namiMultiSigWallet, _amount); } } // set controller address /** * make new controller * require input address is not a controller * execute any time in sc state */ function setController(address _controller) public onlyEscrow { require(!isController[_controller]); isController[_controller] = true; } /** * remove controller * require input address is a controller * execute any time in sc state */ function removeController(address _controller) public onlyEscrow { require(isController[_controller]); isController[_controller] = false; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string public name = "Nami wallet"; function withdrawToken(address _account, uint _amount) public onlyController { require(_account != address(0x0) && _amount != 0); require(_amount >= minWithdraw && _amount <= maxWithdraw); DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) >= _amount) { DAIToken.transfer(_account, _amount); } // emit event emit Withdraw(_account, _amount, now); } }
changeEscrow
function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; }
// change escrow
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 1384, 1531 ] }
798
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiTradeDai
contract NamiTradeDai{ using SafeMath for uint256; constructor(address _escrow, address _namiMultiSigWallet, address _namiAddress, address _daiAddress) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; NamiAddr = _namiAddress; DaiAddress = _daiAddress; } // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; uint public minWithdraw = 10 * 10**18; // 10 DAI uint public maxWithdraw = 100 * 10**18; // max DAI withdraw one time // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; address public DaiAddress; /// address of Nami token address public NamiAddr; /** * list setting function */ mapping(address => bool) public isController; /** * List event */ event Withdraw(address indexed user, uint amount, uint timeWithdraw); modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyNamiMultisig { require(msg.sender == namiMultiSigWallet); _; } modifier onlyController { require(isController[msg.sender] == true); _; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // min and max for withdraw nac function changeMinWithdraw(uint _minWithdraw) public onlyEscrow { require(_minWithdraw != 0); minWithdraw = _minWithdraw; } function changeMaxWithdraw(uint _maxNac) public onlyEscrow { require(_maxNac != 0); maxWithdraw = _maxNac; } /// @dev withdraw ether to nami multisignature wallet, only escrow can call /// @param _amount value ether in wei to withdraw function withdrawEther(uint _amount, address _to) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. if (address(this).balance > 0) { _to.transfer(_amount); } } /// @dev withdraw NAC to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawNac(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. NamiCrowdSale namiToken = NamiCrowdSale(NamiAddr); if (namiToken.balanceOf(address(this)) > 0) { namiToken.transfer(namiMultiSigWallet, _amount); } } /// @dev withdraw DAI to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawDai(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) > 0) { DAIToken.transfer(namiMultiSigWallet, _amount); } } // set controller address /** * make new controller * require input address is not a controller * execute any time in sc state */ function setController(address _controller) public onlyEscrow { require(!isController[_controller]); isController[_controller] = true; } /** * remove controller * require input address is a controller * execute any time in sc state */ function removeController(address _controller) public onlyEscrow { require(isController[_controller]); isController[_controller] = false; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string public name = "Nami wallet"; function withdrawToken(address _account, uint _amount) public onlyController { require(_account != address(0x0) && _amount != 0); require(_amount >= minWithdraw && _amount <= maxWithdraw); DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) >= _amount) { DAIToken.transfer(_account, _amount); } // emit event emit Withdraw(_account, _amount, now); } }
changeMinWithdraw
function changeMinWithdraw(uint _minWithdraw) public onlyEscrow { require(_minWithdraw != 0); minWithdraw = _minWithdraw; }
// min and max for withdraw nac
LineComment
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 1571, 1732 ] }
799
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiTradeDai
contract NamiTradeDai{ using SafeMath for uint256; constructor(address _escrow, address _namiMultiSigWallet, address _namiAddress, address _daiAddress) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; NamiAddr = _namiAddress; DaiAddress = _daiAddress; } // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; uint public minWithdraw = 10 * 10**18; // 10 DAI uint public maxWithdraw = 100 * 10**18; // max DAI withdraw one time // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; address public DaiAddress; /// address of Nami token address public NamiAddr; /** * list setting function */ mapping(address => bool) public isController; /** * List event */ event Withdraw(address indexed user, uint amount, uint timeWithdraw); modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyNamiMultisig { require(msg.sender == namiMultiSigWallet); _; } modifier onlyController { require(isController[msg.sender] == true); _; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // min and max for withdraw nac function changeMinWithdraw(uint _minWithdraw) public onlyEscrow { require(_minWithdraw != 0); minWithdraw = _minWithdraw; } function changeMaxWithdraw(uint _maxNac) public onlyEscrow { require(_maxNac != 0); maxWithdraw = _maxNac; } /// @dev withdraw ether to nami multisignature wallet, only escrow can call /// @param _amount value ether in wei to withdraw function withdrawEther(uint _amount, address _to) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. if (address(this).balance > 0) { _to.transfer(_amount); } } /// @dev withdraw NAC to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawNac(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. NamiCrowdSale namiToken = NamiCrowdSale(NamiAddr); if (namiToken.balanceOf(address(this)) > 0) { namiToken.transfer(namiMultiSigWallet, _amount); } } /// @dev withdraw DAI to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawDai(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) > 0) { DAIToken.transfer(namiMultiSigWallet, _amount); } } // set controller address /** * make new controller * require input address is not a controller * execute any time in sc state */ function setController(address _controller) public onlyEscrow { require(!isController[_controller]); isController[_controller] = true; } /** * remove controller * require input address is a controller * execute any time in sc state */ function removeController(address _controller) public onlyEscrow { require(isController[_controller]); isController[_controller] = false; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string public name = "Nami wallet"; function withdrawToken(address _account, uint _amount) public onlyController { require(_account != address(0x0) && _amount != 0); require(_amount >= minWithdraw && _amount <= maxWithdraw); DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) >= _amount) { DAIToken.transfer(_account, _amount); } // emit event emit Withdraw(_account, _amount, now); } }
withdrawEther
function withdrawEther(uint _amount, address _to) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. if (address(this).balance > 0) { _to.transfer(_amount); } }
/// @dev withdraw ether to nami multisignature wallet, only escrow can call /// @param _amount value ether in wei to withdraw
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 2020, 2290 ] }
800
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiTradeDai
contract NamiTradeDai{ using SafeMath for uint256; constructor(address _escrow, address _namiMultiSigWallet, address _namiAddress, address _daiAddress) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; NamiAddr = _namiAddress; DaiAddress = _daiAddress; } // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; uint public minWithdraw = 10 * 10**18; // 10 DAI uint public maxWithdraw = 100 * 10**18; // max DAI withdraw one time // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; address public DaiAddress; /// address of Nami token address public NamiAddr; /** * list setting function */ mapping(address => bool) public isController; /** * List event */ event Withdraw(address indexed user, uint amount, uint timeWithdraw); modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyNamiMultisig { require(msg.sender == namiMultiSigWallet); _; } modifier onlyController { require(isController[msg.sender] == true); _; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // min and max for withdraw nac function changeMinWithdraw(uint _minWithdraw) public onlyEscrow { require(_minWithdraw != 0); minWithdraw = _minWithdraw; } function changeMaxWithdraw(uint _maxNac) public onlyEscrow { require(_maxNac != 0); maxWithdraw = _maxNac; } /// @dev withdraw ether to nami multisignature wallet, only escrow can call /// @param _amount value ether in wei to withdraw function withdrawEther(uint _amount, address _to) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. if (address(this).balance > 0) { _to.transfer(_amount); } } /// @dev withdraw NAC to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawNac(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. NamiCrowdSale namiToken = NamiCrowdSale(NamiAddr); if (namiToken.balanceOf(address(this)) > 0) { namiToken.transfer(namiMultiSigWallet, _amount); } } /// @dev withdraw DAI to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawDai(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) > 0) { DAIToken.transfer(namiMultiSigWallet, _amount); } } // set controller address /** * make new controller * require input address is not a controller * execute any time in sc state */ function setController(address _controller) public onlyEscrow { require(!isController[_controller]); isController[_controller] = true; } /** * remove controller * require input address is a controller * execute any time in sc state */ function removeController(address _controller) public onlyEscrow { require(isController[_controller]); isController[_controller] = false; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string public name = "Nami wallet"; function withdrawToken(address _account, uint _amount) public onlyController { require(_account != address(0x0) && _amount != 0); require(_amount >= minWithdraw && _amount <= maxWithdraw); DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) >= _amount) { DAIToken.transfer(_account, _amount); } // emit event emit Withdraw(_account, _amount, now); } }
withdrawNac
function withdrawNac(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. NamiCrowdSale namiToken = NamiCrowdSale(NamiAddr); if (namiToken.balanceOf(address(this)) > 0) { namiToken.transfer(namiMultiSigWallet, _amount); } }
/// @dev withdraw NAC to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 2420, 2774 ] }
801
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiTradeDai
contract NamiTradeDai{ using SafeMath for uint256; constructor(address _escrow, address _namiMultiSigWallet, address _namiAddress, address _daiAddress) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; NamiAddr = _namiAddress; DaiAddress = _daiAddress; } // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; uint public minWithdraw = 10 * 10**18; // 10 DAI uint public maxWithdraw = 100 * 10**18; // max DAI withdraw one time // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; address public DaiAddress; /// address of Nami token address public NamiAddr; /** * list setting function */ mapping(address => bool) public isController; /** * List event */ event Withdraw(address indexed user, uint amount, uint timeWithdraw); modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyNamiMultisig { require(msg.sender == namiMultiSigWallet); _; } modifier onlyController { require(isController[msg.sender] == true); _; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // min and max for withdraw nac function changeMinWithdraw(uint _minWithdraw) public onlyEscrow { require(_minWithdraw != 0); minWithdraw = _minWithdraw; } function changeMaxWithdraw(uint _maxNac) public onlyEscrow { require(_maxNac != 0); maxWithdraw = _maxNac; } /// @dev withdraw ether to nami multisignature wallet, only escrow can call /// @param _amount value ether in wei to withdraw function withdrawEther(uint _amount, address _to) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. if (address(this).balance > 0) { _to.transfer(_amount); } } /// @dev withdraw NAC to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawNac(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. NamiCrowdSale namiToken = NamiCrowdSale(NamiAddr); if (namiToken.balanceOf(address(this)) > 0) { namiToken.transfer(namiMultiSigWallet, _amount); } } /// @dev withdraw DAI to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawDai(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) > 0) { DAIToken.transfer(namiMultiSigWallet, _amount); } } // set controller address /** * make new controller * require input address is not a controller * execute any time in sc state */ function setController(address _controller) public onlyEscrow { require(!isController[_controller]); isController[_controller] = true; } /** * remove controller * require input address is a controller * execute any time in sc state */ function removeController(address _controller) public onlyEscrow { require(isController[_controller]); isController[_controller] = false; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string public name = "Nami wallet"; function withdrawToken(address _account, uint _amount) public onlyController { require(_account != address(0x0) && _amount != 0); require(_amount >= minWithdraw && _amount <= maxWithdraw); DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) >= _amount) { DAIToken.transfer(_account, _amount); } // emit event emit Withdraw(_account, _amount, now); } }
withdrawDai
function withdrawDai(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) > 0) { DAIToken.transfer(namiMultiSigWallet, _amount); } }
/// @dev withdraw DAI to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 2902, 3243 ] }
802
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiTradeDai
contract NamiTradeDai{ using SafeMath for uint256; constructor(address _escrow, address _namiMultiSigWallet, address _namiAddress, address _daiAddress) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; NamiAddr = _namiAddress; DaiAddress = _daiAddress; } // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; uint public minWithdraw = 10 * 10**18; // 10 DAI uint public maxWithdraw = 100 * 10**18; // max DAI withdraw one time // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; address public DaiAddress; /// address of Nami token address public NamiAddr; /** * list setting function */ mapping(address => bool) public isController; /** * List event */ event Withdraw(address indexed user, uint amount, uint timeWithdraw); modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyNamiMultisig { require(msg.sender == namiMultiSigWallet); _; } modifier onlyController { require(isController[msg.sender] == true); _; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // min and max for withdraw nac function changeMinWithdraw(uint _minWithdraw) public onlyEscrow { require(_minWithdraw != 0); minWithdraw = _minWithdraw; } function changeMaxWithdraw(uint _maxNac) public onlyEscrow { require(_maxNac != 0); maxWithdraw = _maxNac; } /// @dev withdraw ether to nami multisignature wallet, only escrow can call /// @param _amount value ether in wei to withdraw function withdrawEther(uint _amount, address _to) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. if (address(this).balance > 0) { _to.transfer(_amount); } } /// @dev withdraw NAC to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawNac(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. NamiCrowdSale namiToken = NamiCrowdSale(NamiAddr); if (namiToken.balanceOf(address(this)) > 0) { namiToken.transfer(namiMultiSigWallet, _amount); } } /// @dev withdraw DAI to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawDai(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) > 0) { DAIToken.transfer(namiMultiSigWallet, _amount); } } // set controller address /** * make new controller * require input address is not a controller * execute any time in sc state */ function setController(address _controller) public onlyEscrow { require(!isController[_controller]); isController[_controller] = true; } /** * remove controller * require input address is a controller * execute any time in sc state */ function removeController(address _controller) public onlyEscrow { require(isController[_controller]); isController[_controller] = false; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string public name = "Nami wallet"; function withdrawToken(address _account, uint _amount) public onlyController { require(_account != address(0x0) && _amount != 0); require(_amount >= minWithdraw && _amount <= maxWithdraw); DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) >= _amount) { DAIToken.transfer(_account, _amount); } // emit event emit Withdraw(_account, _amount, now); } }
setController
function setController(address _controller) public onlyEscrow { require(!isController[_controller]); isController[_controller] = true; }
/** * make new controller * require input address is not a controller * execute any time in sc state */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 3410, 3589 ] }
803
NamiTradeDai
NamiTradeDai.sol
0x6b49586597da3742f4224a13495ca91add35639e
Solidity
NamiTradeDai
contract NamiTradeDai{ using SafeMath for uint256; constructor(address _escrow, address _namiMultiSigWallet, address _namiAddress, address _daiAddress) public { require(_namiMultiSigWallet != 0x0); escrow = _escrow; namiMultiSigWallet = _namiMultiSigWallet; NamiAddr = _namiAddress; DaiAddress = _daiAddress; } // escrow has exclusive priveleges to call administrative // functions on this contract. address public escrow; uint public minWithdraw = 10 * 10**18; // 10 DAI uint public maxWithdraw = 100 * 10**18; // max DAI withdraw one time // Gathered funds can be withdraw only to namimultisigwallet's address. address public namiMultiSigWallet; address public DaiAddress; /// address of Nami token address public NamiAddr; /** * list setting function */ mapping(address => bool) public isController; /** * List event */ event Withdraw(address indexed user, uint amount, uint timeWithdraw); modifier onlyEscrow() { require(msg.sender == escrow); _; } modifier onlyNamiMultisig { require(msg.sender == namiMultiSigWallet); _; } modifier onlyController { require(isController[msg.sender] == true); _; } // change escrow function changeEscrow(address _escrow) public onlyNamiMultisig { require(_escrow != 0x0); escrow = _escrow; } // min and max for withdraw nac function changeMinWithdraw(uint _minWithdraw) public onlyEscrow { require(_minWithdraw != 0); minWithdraw = _minWithdraw; } function changeMaxWithdraw(uint _maxNac) public onlyEscrow { require(_maxNac != 0); maxWithdraw = _maxNac; } /// @dev withdraw ether to nami multisignature wallet, only escrow can call /// @param _amount value ether in wei to withdraw function withdrawEther(uint _amount, address _to) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. if (address(this).balance > 0) { _to.transfer(_amount); } } /// @dev withdraw NAC to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawNac(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. NamiCrowdSale namiToken = NamiCrowdSale(NamiAddr); if (namiToken.balanceOf(address(this)) > 0) { namiToken.transfer(namiMultiSigWallet, _amount); } } /// @dev withdraw DAI to nami multisignature wallet, only escrow can call /// @param _amount value NAC to withdraw function withdrawDai(uint _amount) public onlyEscrow { require(namiMultiSigWallet != address(0x0)); // Available at any phase. DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) > 0) { DAIToken.transfer(namiMultiSigWallet, _amount); } } // set controller address /** * make new controller * require input address is not a controller * execute any time in sc state */ function setController(address _controller) public onlyEscrow { require(!isController[_controller]); isController[_controller] = true; } /** * remove controller * require input address is a controller * execute any time in sc state */ function removeController(address _controller) public onlyEscrow { require(isController[_controller]); isController[_controller] = false; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string public name = "Nami wallet"; function withdrawToken(address _account, uint _amount) public onlyController { require(_account != address(0x0) && _amount != 0); require(_amount >= minWithdraw && _amount <= maxWithdraw); DSToken DAIToken = DSToken(DaiAddress); if (DAIToken.balanceOf(address(this)) >= _amount) { DAIToken.transfer(_account, _amount); } // emit event emit Withdraw(_account, _amount, now); } }
removeController
function removeController(address _controller) public onlyEscrow { require(isController[_controller]); isController[_controller] = false; }
/** * remove controller * require input address is a controller * execute any time in sc state */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://0536bde712de9405b6b4b27444ebc916aa467e1026d1d052a48431289f7d69f1
{ "func_code_index": [ 3719, 3901 ] }
804
MetaFunRunNFT
contracts/MetaFunRunNFT.sol
0xf21991430c5593e1af819d583c87e39850b7d82a
Solidity
MetaFunRunNFT
contract MetaFunRunNFT is ERC721Enumerable, Ownable { using Strings for uint256; bool public _isSaleActive = false; bool public _revealed = false; uint256 public constant MAX_SUPPLY = 7777; uint256 public mintPrice = 0.077 ether; uint256 public maxBalance = 1; uint256 public maxMint = 1; string baseURI; string public notRevealedUri; string public baseExtension = ".json"; mapping(uint256 => string) private _tokenURIs; constructor(string memory initBaseURI, string memory initNotRevealedUri) ERC721("MetaFunRunNFT", "MFRN") { setBaseURI(initBaseURI); setNotRevealedURI(initNotRevealedUri); } function mintMeta(uint256 tokenQuantity) public payable { require( totalSupply() + tokenQuantity <= MAX_SUPPLY, "Sale would exceed max supply" ); require(_isSaleActive, "Sale must be active to mint NicMetas"); require( balanceOf(msg.sender) + tokenQuantity <= maxBalance, "Sale would exceed max balance" ); require( tokenQuantity * mintPrice <= msg.value, "Not enough ether sent" ); require(tokenQuantity <= maxMint, "Can only mint 1 tokens at a time"); _mintMeta(tokenQuantity); } function _mintMeta(uint256 tokenQuantity) internal { for (uint256 i = 0; i < tokenQuantity; i++) { uint256 mintIndex = totalSupply(); if (totalSupply() < MAX_SUPPLY) { _safeMint(msg.sender, mintIndex); } } } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); if (_revealed == false) { return notRevealedUri; } string memory _tokenURI = _tokenURIs[tokenId]; string memory base = _baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString(), baseExtension)); } // internal function _baseURI() internal view virtual override returns (string memory) { return baseURI; } //only owner function flipSaleActive() public onlyOwner { _isSaleActive = !_isSaleActive; } function flipReveal() public onlyOwner { _revealed = !_revealed; } function setMintPrice(uint256 _mintPrice) public onlyOwner { mintPrice = _mintPrice; } function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner { notRevealedUri = _notRevealedURI; } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setBaseExtension(string memory _newBaseExtension) public onlyOwner { baseExtension = _newBaseExtension; } function setMaxBalance(uint256 _maxBalance) public onlyOwner { maxBalance = _maxBalance; } function setMaxMint(uint256 _maxMint) public onlyOwner { maxMint = _maxMint; } function withdraw(address to) public onlyOwner { uint256 balance = address(this).balance; payable(to).transfer(balance); } }
_baseURI
function _baseURI() internal view virtual override returns (string memory) { return baseURI; }
// internal
LineComment
v0.8.7+commit.e28d00a7
None
ipfs://3309964e0a7465d1bba3b4aa9a58c67089c2799ba947a178c3aa765c35afbbab
{ "func_code_index": [ 2708, 2821 ] }
805
MetaFunRunNFT
contracts/MetaFunRunNFT.sol
0xf21991430c5593e1af819d583c87e39850b7d82a
Solidity
MetaFunRunNFT
contract MetaFunRunNFT is ERC721Enumerable, Ownable { using Strings for uint256; bool public _isSaleActive = false; bool public _revealed = false; uint256 public constant MAX_SUPPLY = 7777; uint256 public mintPrice = 0.077 ether; uint256 public maxBalance = 1; uint256 public maxMint = 1; string baseURI; string public notRevealedUri; string public baseExtension = ".json"; mapping(uint256 => string) private _tokenURIs; constructor(string memory initBaseURI, string memory initNotRevealedUri) ERC721("MetaFunRunNFT", "MFRN") { setBaseURI(initBaseURI); setNotRevealedURI(initNotRevealedUri); } function mintMeta(uint256 tokenQuantity) public payable { require( totalSupply() + tokenQuantity <= MAX_SUPPLY, "Sale would exceed max supply" ); require(_isSaleActive, "Sale must be active to mint NicMetas"); require( balanceOf(msg.sender) + tokenQuantity <= maxBalance, "Sale would exceed max balance" ); require( tokenQuantity * mintPrice <= msg.value, "Not enough ether sent" ); require(tokenQuantity <= maxMint, "Can only mint 1 tokens at a time"); _mintMeta(tokenQuantity); } function _mintMeta(uint256 tokenQuantity) internal { for (uint256 i = 0; i < tokenQuantity; i++) { uint256 mintIndex = totalSupply(); if (totalSupply() < MAX_SUPPLY) { _safeMint(msg.sender, mintIndex); } } } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); if (_revealed == false) { return notRevealedUri; } string memory _tokenURI = _tokenURIs[tokenId]; string memory base = _baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString(), baseExtension)); } // internal function _baseURI() internal view virtual override returns (string memory) { return baseURI; } //only owner function flipSaleActive() public onlyOwner { _isSaleActive = !_isSaleActive; } function flipReveal() public onlyOwner { _revealed = !_revealed; } function setMintPrice(uint256 _mintPrice) public onlyOwner { mintPrice = _mintPrice; } function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner { notRevealedUri = _notRevealedURI; } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setBaseExtension(string memory _newBaseExtension) public onlyOwner { baseExtension = _newBaseExtension; } function setMaxBalance(uint256 _maxBalance) public onlyOwner { maxBalance = _maxBalance; } function setMaxMint(uint256 _maxMint) public onlyOwner { maxMint = _maxMint; } function withdraw(address to) public onlyOwner { uint256 balance = address(this).balance; payable(to).transfer(balance); } }
flipSaleActive
function flipSaleActive() public onlyOwner { _isSaleActive = !_isSaleActive; }
//only owner
LineComment
v0.8.7+commit.e28d00a7
None
ipfs://3309964e0a7465d1bba3b4aa9a58c67089c2799ba947a178c3aa765c35afbbab
{ "func_code_index": [ 2842, 2939 ] }
806