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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | ERC20 | contract ERC20 {
// modifiers
// mitigate short address attack
// thanks to https://github.com/numerai/contract/blob/c182465f82e50ced8dacb3977ec374a892f5fa8c/contracts/Safe.sol#L30-L34.
// TODO: doublecheck implication of >= compared to ==
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
uint256 public totalSupply;
/*
* Public functions
*/
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
/*
* Events
*/
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
event Burn(address indexed from, uint256 value);
event SaleContractActivation(address saleContract, uint256 tokensForSale);
} | balanceOf | function balanceOf(address who) public view returns (uint256);
| /*
* Public functions
*/ | Comment | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
452,
519
]
} | 807 |
|||
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | StandardToken | contract StandardToken is ERC20 {
using SafeMath for uint256;
mapping (address => mapping (address => uint256)) internal allowed;
mapping(address => uint256) balances;
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Balance of owner
// it is recommended to define functions which can read the state of blockchain but cannot write in it as view instead of constant
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
/// @dev Transfers sender's tokens to a given address. Returns success
/// @param _to Address of token receiver
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
function transfer(address _to, uint256 _value) public onlyPayloadSize(2) returns (bool success) {
if (balances[msg.sender] >= _value && _value > 0 && balances[_to].add(_value) > balances[_to]) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value); // solhint-disable-line
return true;
} else {
return false;
}
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success
/// @param _from Address from where tokens are withdrawn
/// @param _to Address to where tokens are sent
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
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);
emit Transfer(_from, _to, _value); // solhint-disable-line
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 onlyPayloadSize(2) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require(_value == 0 || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value); // solhint-disable-line
return true;
}
function changeApproval(address _spender, uint256 _oldValue, uint256 _newValue) public onlyPayloadSize(3) returns (bool success) {
require(allowed[msg.sender][_spender] == _oldValue);
allowed[msg.sender][_spender] = _newValue;
emit Approval(msg.sender, _spender, _newValue); // solhint-disable-line
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 Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public returns (bool burnSuccess) {
require(_value > 0);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
emit Burn(burner, _value); // solhint-disable-line
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
| // it is recommended to define functions which can read the state of blockchain but cannot write in it as view instead of constant | LineComment | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
460,
572
]
} | 808 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | StandardToken | contract StandardToken is ERC20 {
using SafeMath for uint256;
mapping (address => mapping (address => uint256)) internal allowed;
mapping(address => uint256) balances;
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Balance of owner
// it is recommended to define functions which can read the state of blockchain but cannot write in it as view instead of constant
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
/// @dev Transfers sender's tokens to a given address. Returns success
/// @param _to Address of token receiver
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
function transfer(address _to, uint256 _value) public onlyPayloadSize(2) returns (bool success) {
if (balances[msg.sender] >= _value && _value > 0 && balances[_to].add(_value) > balances[_to]) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value); // solhint-disable-line
return true;
} else {
return false;
}
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success
/// @param _from Address from where tokens are withdrawn
/// @param _to Address to where tokens are sent
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
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);
emit Transfer(_from, _to, _value); // solhint-disable-line
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 onlyPayloadSize(2) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require(_value == 0 || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value); // solhint-disable-line
return true;
}
function changeApproval(address _spender, uint256 _oldValue, uint256 _newValue) public onlyPayloadSize(3) returns (bool success) {
require(allowed[msg.sender][_spender] == _oldValue);
allowed[msg.sender][_spender] = _newValue;
emit Approval(msg.sender, _spender, _newValue); // solhint-disable-line
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 Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public returns (bool burnSuccess) {
require(_value > 0);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
emit Burn(burner, _value); // solhint-disable-line
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public onlyPayloadSize(2) returns (bool success) {
if (balances[msg.sender] >= _value && _value > 0 && balances[_to].add(_value) > balances[_to]) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value); // solhint-disable-line
return true;
} else {
return false;
}
}
| /// @dev Transfers sender's tokens to a given address. Returns success
/// @param _to Address of token receiver
/// @param _value Number of tokens to transfer
/// @return Was transfer successful? | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
785,
1285
]
} | 809 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | StandardToken | contract StandardToken is ERC20 {
using SafeMath for uint256;
mapping (address => mapping (address => uint256)) internal allowed;
mapping(address => uint256) balances;
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Balance of owner
// it is recommended to define functions which can read the state of blockchain but cannot write in it as view instead of constant
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
/// @dev Transfers sender's tokens to a given address. Returns success
/// @param _to Address of token receiver
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
function transfer(address _to, uint256 _value) public onlyPayloadSize(2) returns (bool success) {
if (balances[msg.sender] >= _value && _value > 0 && balances[_to].add(_value) > balances[_to]) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value); // solhint-disable-line
return true;
} else {
return false;
}
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success
/// @param _from Address from where tokens are withdrawn
/// @param _to Address to where tokens are sent
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
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);
emit Transfer(_from, _to, _value); // solhint-disable-line
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 onlyPayloadSize(2) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require(_value == 0 || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value); // solhint-disable-line
return true;
}
function changeApproval(address _spender, uint256 _oldValue, uint256 _newValue) public onlyPayloadSize(3) returns (bool success) {
require(allowed[msg.sender][_spender] == _oldValue);
allowed[msg.sender][_spender] = _newValue;
emit Approval(msg.sender, _spender, _newValue); // solhint-disable-line
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 Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public returns (bool burnSuccess) {
require(_value > 0);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
emit Burn(burner, _value); // solhint-disable-line
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | transferFrom | 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);
emit Transfer(_from, _to, _value); // solhint-disable-line
return true;
}
| /// @dev Allows allowed third party to transfer tokens from one address to another. Returns success
/// @param _from Address from where tokens are withdrawn
/// @param _to Address to where tokens are sent
/// @param _value Number of tokens to transfer
/// @return Was transfer successful? | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
1604,
2121
]
} | 810 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | StandardToken | contract StandardToken is ERC20 {
using SafeMath for uint256;
mapping (address => mapping (address => uint256)) internal allowed;
mapping(address => uint256) balances;
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Balance of owner
// it is recommended to define functions which can read the state of blockchain but cannot write in it as view instead of constant
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
/// @dev Transfers sender's tokens to a given address. Returns success
/// @param _to Address of token receiver
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
function transfer(address _to, uint256 _value) public onlyPayloadSize(2) returns (bool success) {
if (balances[msg.sender] >= _value && _value > 0 && balances[_to].add(_value) > balances[_to]) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value); // solhint-disable-line
return true;
} else {
return false;
}
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success
/// @param _from Address from where tokens are withdrawn
/// @param _to Address to where tokens are sent
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
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);
emit Transfer(_from, _to, _value); // solhint-disable-line
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 onlyPayloadSize(2) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require(_value == 0 || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value); // solhint-disable-line
return true;
}
function changeApproval(address _spender, uint256 _oldValue, uint256 _newValue) public onlyPayloadSize(3) returns (bool success) {
require(allowed[msg.sender][_spender] == _oldValue);
allowed[msg.sender][_spender] = _newValue;
emit Approval(msg.sender, _spender, _newValue); // solhint-disable-line
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 Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public returns (bool burnSuccess) {
require(_value > 0);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
emit Burn(burner, _value); // solhint-disable-line
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | approve | function approve(address _spender, uint256 _value) public onlyPayloadSize(2) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require(_value == 0 || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value); // solhint-disable-line
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.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
2757,
3384
]
} | 811 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | StandardToken | contract StandardToken is ERC20 {
using SafeMath for uint256;
mapping (address => mapping (address => uint256)) internal allowed;
mapping(address => uint256) balances;
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Balance of owner
// it is recommended to define functions which can read the state of blockchain but cannot write in it as view instead of constant
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
/// @dev Transfers sender's tokens to a given address. Returns success
/// @param _to Address of token receiver
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
function transfer(address _to, uint256 _value) public onlyPayloadSize(2) returns (bool success) {
if (balances[msg.sender] >= _value && _value > 0 && balances[_to].add(_value) > balances[_to]) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value); // solhint-disable-line
return true;
} else {
return false;
}
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success
/// @param _from Address from where tokens are withdrawn
/// @param _to Address to where tokens are sent
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
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);
emit Transfer(_from, _to, _value); // solhint-disable-line
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 onlyPayloadSize(2) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require(_value == 0 || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value); // solhint-disable-line
return true;
}
function changeApproval(address _spender, uint256 _oldValue, uint256 _newValue) public onlyPayloadSize(3) returns (bool success) {
require(allowed[msg.sender][_spender] == _oldValue);
allowed[msg.sender][_spender] = _newValue;
emit Approval(msg.sender, _spender, _newValue); // solhint-disable-line
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 Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public returns (bool burnSuccess) {
require(_value > 0);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
emit Burn(burner, _value); // solhint-disable-line
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | 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.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
4070,
4209
]
} | 812 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | StandardToken | contract StandardToken is ERC20 {
using SafeMath for uint256;
mapping (address => mapping (address => uint256)) internal allowed;
mapping(address => uint256) balances;
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Balance of owner
// it is recommended to define functions which can read the state of blockchain but cannot write in it as view instead of constant
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
/// @dev Transfers sender's tokens to a given address. Returns success
/// @param _to Address of token receiver
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
function transfer(address _to, uint256 _value) public onlyPayloadSize(2) returns (bool success) {
if (balances[msg.sender] >= _value && _value > 0 && balances[_to].add(_value) > balances[_to]) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value); // solhint-disable-line
return true;
} else {
return false;
}
}
/// @dev Allows allowed third party to transfer tokens from one address to another. Returns success
/// @param _from Address from where tokens are withdrawn
/// @param _to Address to where tokens are sent
/// @param _value Number of tokens to transfer
/// @return Was transfer successful?
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);
emit Transfer(_from, _to, _value); // solhint-disable-line
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 onlyPayloadSize(2) returns (bool) {
// To change the approve amount you first have to reduce the addresses`
// allowance to zero by calling `approve(_spender, 0)` if it is not
// already 0 to mitigate the race condition described here:
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
require(_value == 0 || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value); // solhint-disable-line
return true;
}
function changeApproval(address _spender, uint256 _oldValue, uint256 _newValue) public onlyPayloadSize(3) returns (bool success) {
require(allowed[msg.sender][_spender] == _oldValue);
allowed[msg.sender][_spender] = _newValue;
emit Approval(msg.sender, _spender, _newValue); // solhint-disable-line
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 Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public returns (bool burnSuccess) {
require(_value > 0);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
emit Burn(burner, _value); // solhint-disable-line
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | burn | function burn(uint256 _value) public returns (bool burnSuccess) {
require(_value > 0);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
emit Burn(burner, _value); // solhint-disable-line
return true;
}
| /**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
4322,
4888
]
} | 813 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
| /**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
2704,
3265
]
} | 814 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
| /**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
3471,
4099
]
} | 815 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | activateSaleContract | function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
| /**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
4255,
4561
]
} | 816 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | activateVestingContract | function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
| /**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
4719,
5021
]
} | 817 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | sendBounty | function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
| /**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
5219,
5552
]
} | 818 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | sendMarketingTokens | function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
| /**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
5749,
6095
]
} | 819 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | sendExpansionTokens | function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
| /**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
6292,
6638
]
} | 820 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | sendAdvisorTokens | function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
| /**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
6835,
7173
]
} | 821 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | isContract | function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
| /**
* @dev function to check whether passed address is a contract address
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
7268,
7570
]
} | 822 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | saleTransfer | function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
| /**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
7808,
8208
]
} | 823 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | vestingTransfer | function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
| /**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
8447,
8846
]
} | 824 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | finalize | function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
| /**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
8969,
9210
]
} | 825 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | freezeAccount | function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
| /**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
9510,
9733
]
} | 826 |
|
Synapse | Synapse.sol | 0x5dcd2a3c8fdef5115cd11e9ae20b59d412189b9c | Solidity | Synapse | contract Synapse is StandardToken, Owned, Pausable {
using SafeMath for uint256;
string public symbol;
string public name;
uint8 public decimals;
uint256 public tokensForSale = 495000000 * 1 ether;//50% total of Supply for crowdsale
uint256 public vestingTokens = 227700000 * 1 ether;//23% of total Supply will be freeze(10% team, 8% reserve and 5% others)
uint256 public managementTokens = 267300000 * 1 ether;//27% total Supply(12% Marketing, 9% Expansion, 3% Bounty, 3% Advisor)
mapping(address => bool) public investorIsVested;
uint256 public vestingTime = 15552000;// 6 months
uint256 public bountyTokens = 29700000 * 1 ether;
uint256 public marketingTokens = 118800000 * 1 ether;
uint256 public expansionTokens = 89100000 * 1 ether;
uint256 public advisorTokens = 29700000 * 1 ether;
uint256 public icoStartTime;
uint256 public icoFinalizedTime;
address public tokenOwner;
address public crowdSaleOwner;
address public vestingOwner;
address public saleContract;
address public vestingContract;
bool public fundraising = true;
mapping (address => bool) public frozenAccounts;
event FrozenFund(address target, bool frozen);
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
modifier manageTransfer() {
if (msg.sender == owner) {
_;
} else {
require(fundraising == false);
_;
}
}
/**
* @dev constructor of a token contract
* @param _tokenOwner address of the owner of contract.
*/
constructor(address _tokenOwner,address _crowdSaleOwner, address _vestingOwner ) public Owned(_tokenOwner) {
symbol ="SYP";
name = "Synapsecoin";
decimals = 18;
tokenOwner = _tokenOwner;
crowdSaleOwner = _crowdSaleOwner;
vestingOwner = _vestingOwner;
totalSupply = 990000000 * 1 ether;
balances[_tokenOwner] = balances[_tokenOwner].add(managementTokens);
balances[_crowdSaleOwner] = balances[_crowdSaleOwner].add(tokensForSale);
balances[_vestingOwner] = balances[_vestingOwner].add(vestingTokens);
emit Transfer(address(0), _tokenOwner, managementTokens);
emit Transfer(address(0), _crowdSaleOwner, tokensForSale);
emit Transfer(address(0), _vestingOwner, vestingTokens);
}
/**
* @dev Investor can Transfer token from this method
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transfer(address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(2) returns (bool success) {
require(_value>0);
require(_to != address(0));
require(!frozenAccounts[msg.sender]);
if(investorIsVested[msg.sender]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));
super.transfer(_to,_value);
return true;
}
else {
super.transfer(_to,_value);
return true;
}
}
/**
* @dev Transfer from allow to trasfer token
* @param _from address of sender
* @param _to address of the reciever
* @param _value amount of tokens to transfer
*/
function transferFrom(address _from, address _to, uint256 _value) public manageTransfer whenNotPaused onlyPayloadSize(3) returns (bool) {
require(_value>0);
require(_to != address(0));
require(_from != address(0));
require(!frozenAccounts[_from]);
if(investorIsVested[_from]==true )
{
require(now >= icoFinalizedTime.add(vestingTime));//15552000
super.transferFrom(_from,_to,_value);
return true;
}
else {
super.transferFrom(_from,_to,_value);
return true;
} }
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _saleContract ,address of crowdsale contract
*/
function activateSaleContract(address _saleContract) public whenNotPaused {
require(msg.sender == crowdSaleOwner);
require(_saleContract != address(0));
require(saleContract == address(0));
saleContract = _saleContract;
icoStartTime = now;
}
/**
* activates the sale contract (i.e. transfers saleable contracts)
* @param _vestingContract ,address of crowdsale contract
*/
function activateVestingContract(address _vestingContract) public whenNotPaused {
require(msg.sender == vestingOwner);
require(_vestingContract != address(0));
require(vestingContract == address(0));
vestingContract = _vestingContract;
}
/**
* @dev this function will send the bounty tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendBounty(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(bountyTokens >= _value);
bountyTokens = bountyTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the Marketing tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendMarketingTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(marketingTokens >= _value);
marketingTokens = marketingTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendExpansionTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(expansionTokens >= _value);
expansionTokens = expansionTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev this function will send the expansion tokens to given address
* @param _to ,address of the bounty receiver.
* @param _value , number of tokens to be sent.
*/
function sendAdvisorTokens(address _to, uint256 _value) public whenNotPaused onlyOwner returns (bool) {
require(_to != address(0));
require(_value > 0 );
require(advisorTokens >= _value);
advisorTokens = advisorTokens.sub(_value);
return super.transfer(_to, _value);
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev this function can only be called by crowdsale contract to transfer tokens to investor
* @param _to address The address of the investor.
* @param _value uint256 The amount of tokens to be send
*/
function saleTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(saleContract != address(0),'sale address is not activated');
require(msg.sender == saleContract,'caller is not crowdsale contract');
require(!frozenAccounts[_to],'account is freezed');
return super.transferFrom(crowdSaleOwner,_to, _value);
}
/**
* @dev this function can only be called by contract to transfer tokens to vesting beneficiary
* @param _to address The address of the beneficiary.
* @param _value uint256 The amount of tokens to be send
*/
function vestingTransfer(address _to, uint256 _value) external whenNotPaused returns (bool) {
require(icoFinalizedTime == 0,'ico is finalised');
require(vestingContract != address(0));
require(msg.sender == vestingContract,'caller is not a vesting contract');
investorIsVested[_to] = true;
return super.transferFrom(vestingOwner,_to, _value);
}
/**
* @dev this function will closes the sale ,after this anyone can transfer their tokens to others.
*/
function finalize() external whenNotPaused returns(bool){
require(fundraising != false);
require(msg.sender == saleContract);
fundraising = false;
icoFinalizedTime = now;
return true;
}
/**
* @dev this function will freeze the any account so that the frozen account will not able to participate in crowdsale.
* @param target ,address of the target account
* @param freeze ,boolean value to freeze or unfreeze the account ,true to freeze and false to unfreeze
*/
function freezeAccount (address target, bool freeze) public onlyOwner {
require(target != 0x0);
frozenAccounts[target] = freeze;
emit FrozenFund(target, freeze); // solhint-disable-line
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
function () external payable {
revert();
}
} | /**
* @title Synapse
*/ | NatSpecMultiLine | transferAnyERC20Token | function transferAnyERC20Token(address tokenAddress, uint tokens) public whenNotPaused onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
| /**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://aa5a3cdb91a4525f886bbaa60f0acb073913b5fbb9821431c4a6c7aebbfce38d | {
"func_code_index": [
10062,
10346
]
} | 827 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | supportsInterface | function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
| // ERC721 | LineComment | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
3793,
4066
]
} | 828 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | balanceOf | function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
| /// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
4398,
4569
]
} | 829 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | ownerOf | function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
| /// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
4717,
4874
]
} | 830 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | safeTransferFrom | function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
| /// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to` | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
5179,
5379
]
} | 831 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | safeTransferFrom | function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
| /// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
5599,
5785
]
} | 832 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | transferFrom | function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
| /// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
6018,
6423
]
} | 833 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | approve | function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
| /// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
6593,
6981
]
} | 834 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | setApprovalForAll | function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
| /// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
7245,
7492
]
} | 835 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | getApproved | function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
| /// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
7709,
7864
]
} | 836 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | isApprovedForAll | function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
| /// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
8164,
8323
]
} | 837 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | totalSupply | function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
| /// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
8542,
8673
]
} | 838 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | _transfer | function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
| /// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
8906,
10048
]
} | 839 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | _safeTransferFrom | function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
| /// @dev Actually perform the safeTransferFrom | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
10103,
10944
]
} | 840 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | createFashion | function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
(_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
| /// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
11260,
12872
]
} | 841 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | _changeAttrByIndex | function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
| /// @dev One specific attribute of the equipment modified | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
12938,
13695
]
} | 842 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | changeFashionAttr | function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
| /// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc. | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
14001,
14814
]
} | 843 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | destroyFashion | function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
| /// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
14957,
15890
]
} | 844 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | safeTransferByContract | function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
| /// @dev Safe transfer by trust contracts | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
15940,
16385
]
} | 845 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | getFashion | function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
| /// @dev Get fashion attrs by tokenId | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
16549,
17187
]
} | 846 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | getOwnFashions | function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
| /// @dev Get tokenIds and flags by owner | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
17238,
17831
]
} | 847 |
|
RaceToken | RaceToken.sol | 0x5ad89bb4f55a33320e076068636ed7314cd2922c | Solidity | RaceToken | contract RaceToken is ERC721, AccessAdmin {
/// @dev The equipment info
struct Fashion {
uint16 equipmentId; // 0 Equipment ID
uint16 quality; // 1 Rarity: 1 Coarse/2 Good/3 Rare/4 Epic/5 Legendary If car /1 T1 /2 T2 /3 T3 /4 T4 /5 T5 /6 T6 /7 free
uint16 pos; // 2 Slots: 1 Engine/2 Turbine/3 BodySystem/4 Pipe/5 Suspension/6 NO2/7 Tyre/8 Transmission/9 Car
uint16 production; // 3 Race bonus productivity
uint16 attack; // 4 Attack
uint16 defense; // 5 Defense
uint16 plunder; // 6 Plunder
uint16 productionMultiplier; // 7 Percent value
uint16 attackMultiplier; // 8 Percent value
uint16 defenseMultiplier; // 9 Percent value
uint16 plunderMultiplier; // 10 Percent value
uint16 level; // 11 level
uint16 isPercent; // 12 Percent value
}
/// @dev All equipments tokenArray (not exceeding 2^32-1)
Fashion[] public fashionArray;
/// @dev Amount of tokens destroyed
uint256 destroyFashionCount;
/// @dev Equipment token ID belong to owner address
mapping (uint256 => address) fashionIdToOwner;
/// @dev Equipments owner by the owner (array)
mapping (address => uint256[]) ownerToFashionArray;
/// @dev Equipment token ID search in owner array
mapping (uint256 => uint256) fashionIdToOwnerIndex;
/// @dev The authorized address for each Race
mapping (uint256 => address) fashionIdToApprovals;
/// @dev The authorized operators for each address
mapping (address => mapping (address => bool)) operatorToApprovals;
/// @dev Trust contract
mapping (address => bool) actionContracts;
function setActionContract(address _actionAddr, bool _useful) external onlyAdmin {
actionContracts[_actionAddr] = _useful;
}
function getActionContract(address _actionAddr) external view onlyAdmin returns(bool) {
return actionContracts[_actionAddr];
}
/// @dev This emits when the approved address for an Race is changed or reaffirmed.
event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
/// @dev This emits when an operator is enabled or disabled for an owner.
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/// @dev This emits when the equipment ownership changed
event Transfer(address indexed from, address indexed to, uint256 tokenId);
/// @dev This emits when the equipment created
event CreateFashion(address indexed owner, uint256 tokenId, uint16 equipmentId, uint16 quality, uint16 pos, uint16 level, uint16 createType);
/// @dev This emits when the equipment's attributes changed
event ChangeFashion(address indexed owner, uint256 tokenId, uint16 changeType);
/// @dev This emits when the equipment destroyed
event DeleteFashion(address indexed owner, uint256 tokenId, uint16 deleteType);
function RaceToken() public {
addrAdmin = msg.sender;
fashionArray.length += 1;
}
// modifier
/// @dev Check if token ID is valid
modifier isValidToken(uint256 _tokenId) {
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
require(fashionIdToOwner[_tokenId] != address(0));
_;
}
modifier canTransfer(uint256 _tokenId) {
address owner = fashionIdToOwner[_tokenId];
require(msg.sender == owner || msg.sender == fashionIdToApprovals[_tokenId] || operatorToApprovals[owner][msg.sender]);
_;
}
// ERC721
function supportsInterface(bytes4 _interfaceId) external view returns(bool) {
// ERC165 || ERC721 || ERC165^ERC721
return (_interfaceId == 0x01ffc9a7 || _interfaceId == 0x80ac58cd || _interfaceId == 0x8153916a) && (_interfaceId != 0xffffffff);
}
function name() public pure returns(string) {
return "Race Token";
}
function symbol() public pure returns(string) {
return "Race";
}
/// @dev Search for token quantity address
/// @param _owner Address that needs to be searched
/// @return Returns token quantity
function balanceOf(address _owner) external view returns(uint256) {
require(_owner != address(0));
return ownerToFashionArray[_owner].length;
}
/// @dev Find the owner of an Race
/// @param _tokenId The tokenId of Race
/// @return Give The address of the owner of this Race
function ownerOf(uint256 _tokenId) external view /*isValidToken(_tokenId)*/ returns (address owner) {
return fashionIdToOwner[_tokenId];
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
/// @param data Additional data with no specified format, sent in call to `_to`
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, data);
}
/// @dev Transfers the ownership of an Race from one address to another address
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function safeTransferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
{
_safeTransferFrom(_from, _to, _tokenId, "");
}
/// @dev Transfer ownership of an Race, '_to' must be a vaild address, or the Race will lost
/// @param _from The current owner of the Race
/// @param _to The new owner
/// @param _tokenId The Race to transfer
function transferFrom(address _from, address _to, uint256 _tokenId)
external
whenNotPaused
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
}
/// @dev Set or reaffirm the approved address for an Race
/// @param _approved The new approved Race controller
/// @param _tokenId The Race to approve
function approve(address _approved, uint256 _tokenId)
external
whenNotPaused
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(msg.sender == owner || operatorToApprovals[owner][msg.sender]);
fashionIdToApprovals[_tokenId] = _approved;
Approval(owner, _approved, _tokenId);
}
/// @dev Enable or disable approval for a third party ("operator") to manage all your asset.
/// @param _operator Address to add to the set of authorized operators.
/// @param _approved True if the operators is approved, false to revoke approval
function setApprovalForAll(address _operator, bool _approved)
external
whenNotPaused
{
operatorToApprovals[msg.sender][_operator] = _approved;
ApprovalForAll(msg.sender, _operator, _approved);
}
/// @dev Get the approved address for a single Race
/// @param _tokenId The Race to find the approved address for
/// @return The approved address for this Race, or the zero address if there is none
function getApproved(uint256 _tokenId) external view isValidToken(_tokenId) returns (address) {
return fashionIdToApprovals[_tokenId];
}
/// @dev Query if an address is an authorized operator for another address
/// @param _owner The address that owns the Races
/// @param _operator The address that acts on behalf of the owner
/// @return True if `_operator` is an approved operator for `_owner`, false otherwise
function isApprovedForAll(address _owner, address _operator) external view returns (bool) {
return operatorToApprovals[_owner][_operator];
}
/// @dev Count Races tracked by this contract
/// @return A count of valid Races tracked by this contract, where each one of
/// them has an assigned and queryable owner not equal to the zero address
function totalSupply() external view returns (uint256) {
return fashionArray.length - destroyFashionCount - 1;
}
/// @dev Do the real transfer with out any condition checking
/// @param _from The old owner of this Race(If created: 0x0)
/// @param _to The new owner of this Race
/// @param _tokenId The tokenId of the Race
function _transfer(address _from, address _to, uint256 _tokenId) internal {
if (_from != address(0)) {
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
// If the Race is not the element of array, change it to with the last
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
if (fashionIdToApprovals[_tokenId] != address(0)) {
delete fashionIdToApprovals[_tokenId];
}
}
// Give the Race to '_to'
fashionIdToOwner[_tokenId] = _to;
ownerToFashionArray[_to].push(_tokenId);
fashionIdToOwnerIndex[_tokenId] = ownerToFashionArray[_to].length - 1;
Transfer(_from != address(0) ? _from : this, _to, _tokenId);
}
/// @dev Actually perform the safeTransferFrom
function _safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)
internal
isValidToken(_tokenId)
canTransfer(_tokenId)
{
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner == _from);
_transfer(_from, _to, _tokenId);
// Do the callback after everything is done to avoid reentrancy attack
uint256 codeSize;
assembly { codeSize := extcodesize(_to) }
if (codeSize == 0) {
return;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(_from, _tokenId, data);
// bytes4(keccak256("onERC721Received(address,uint256,bytes)")) = 0xf0b9e5ba;
require(retval == 0xf0b9e5ba);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Equipment creation
/// @param _owner Owner of the equipment created
/// @param _attrs Attributes of the equipment created
/// @return Token ID of the equipment created
function createFashion(address _owner, uint16[13] _attrs, uint16 _createType)
external
whenNotPaused
returns(uint256)
{
require(actionContracts[msg.sender]);
require(_owner != address(0));
uint256 newFashionId = fashionArray.length;
require(newFashionId < 4294967296);
fashionArray.length += 1;
Fashion storage fs = fashionArray[newFashionId];
fs.equipmentId = _attrs[0];
fs.quality = _attrs[1];
fs.pos = _attrs[2];
if (_attrs[3] != 0) {
fs.production = _attrs[3];
}
if (_attrs[4] != 0) {
fs.attack = _attrs[4];
}
if (_attrs[5] != 0) {
fs.defense = _attrs[5];
}
if (_attrs[6] != 0) {
fs.plunder = _attrs[6];
}
if (_attrs[7] != 0) {
fs.productionMultiplier = _attrs[7];
}
if (_attrs[8] != 0) {
fs.attackMultiplier = _attrs[8];
}
if (_attrs[9] != 0) {
fs.defenseMultiplier = _attrs[9];
}
if (_attrs[10] != 0) {
fs.plunderMultiplier = _attrs[10];
}
if (_attrs[11] != 0) {
fs.level = _attrs[11];
}
if (_attrs[12] != 0) {
fs.isPercent = _attrs[12];
}
_transfer(0, _owner, newFashionId);
CreateFashion(_owner, newFashionId, _attrs[0], _attrs[1], _attrs[2], _attrs[11], _createType);
return newFashionId;
}
/// @dev One specific attribute of the equipment modified
function _changeAttrByIndex(Fashion storage _fs, uint16 _index, uint16 _val) internal {
if (_index == 3) {
_fs.production = _val;
} else if(_index == 4) {
_fs.attack = _val;
} else if(_index == 5) {
_fs.defense = _val;
} else if(_index == 6) {
_fs.plunder = _val;
}else if(_index == 7) {
_fs.productionMultiplier = _val;
}else if(_index == 8) {
_fs.attackMultiplier = _val;
}else if(_index == 9) {
_fs.defenseMultiplier = _val;
}else if(_index == 10) {
_fs.plunderMultiplier = _val;
} else if(_index == 11) {
_fs.level = _val;
}
}
/// @dev Equiment attributes modified (max 4 stats modified)
/// @param _tokenId Equipment Token ID
/// @param _idxArray Stats order that must be modified
/// @param _params Stat value that must be modified
/// @param _changeType Modification type such as enhance, socket, etc.
function changeFashionAttr(uint256 _tokenId, uint16[4] _idxArray, uint16[4] _params, uint16 _changeType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
Fashion storage fs = fashionArray[_tokenId];
if (_idxArray[0] > 0) {
_changeAttrByIndex(fs, _idxArray[0], _params[0]);
}
if (_idxArray[1] > 0) {
_changeAttrByIndex(fs, _idxArray[1], _params[1]);
}
if (_idxArray[2] > 0) {
_changeAttrByIndex(fs, _idxArray[2], _params[2]);
}
if (_idxArray[3] > 0) {
_changeAttrByIndex(fs, _idxArray[3], _params[3]);
}
ChangeFashion(fashionIdToOwner[_tokenId], _tokenId, _changeType);
}
/// @dev Equipment destruction
/// @param _tokenId Equipment Token ID
/// @param _deleteType Destruction type, such as craft
function destroyFashion(uint256 _tokenId, uint16 _deleteType)
external
whenNotPaused
isValidToken(_tokenId)
{
require(actionContracts[msg.sender]);
address _from = fashionIdToOwner[_tokenId];
uint256 indexFrom = fashionIdToOwnerIndex[_tokenId];
uint256[] storage fsArray = ownerToFashionArray[_from];
require(fsArray[indexFrom] == _tokenId);
if (indexFrom != fsArray.length - 1) {
uint256 lastTokenId = fsArray[fsArray.length - 1];
fsArray[indexFrom] = lastTokenId;
fashionIdToOwnerIndex[lastTokenId] = indexFrom;
}
fsArray.length -= 1;
fashionIdToOwner[_tokenId] = address(0);
delete fashionIdToOwnerIndex[_tokenId];
destroyFashionCount += 1;
Transfer(_from, 0, _tokenId);
DeleteFashion(_from, _tokenId, _deleteType);
}
/// @dev Safe transfer by trust contracts
function safeTransferByContract(uint256 _tokenId, address _to)
external
whenNotPaused
{
require(actionContracts[msg.sender]);
require(_tokenId >= 1 && _tokenId <= fashionArray.length);
address owner = fashionIdToOwner[_tokenId];
require(owner != address(0));
require(_to != address(0));
require(owner != _to);
_transfer(owner, _to, _tokenId);
}
//----------------------------------------------------------------------------------------------------------
/// @dev Get fashion attrs by tokenId
function getFashion(uint256 _tokenId) external view isValidToken(_tokenId) returns (uint16[13] datas) {
Fashion storage fs = fashionArray[_tokenId];
datas[0] = fs.equipmentId;
datas[1] = fs.quality;
datas[2] = fs.pos;
datas[3] = fs.production;
datas[4] = fs.attack;
datas[5] = fs.defense;
datas[6] = fs.plunder;
datas[7] = fs.productionMultiplier;
datas[8] = fs.attackMultiplier;
datas[9] = fs.defenseMultiplier;
datas[10] = fs.plunderMultiplier;
datas[11] = fs.level;
datas[12] = fs.isPercent;
}
/// @dev Get tokenIds and flags by owner
function getOwnFashions(address _owner) external view returns(uint256[] tokens, uint32[] flags) {
require(_owner != address(0));
uint256[] storage fsArray = ownerToFashionArray[_owner];
uint256 length = fsArray.length;
tokens = new uint256[](length);
flags = new uint32[](length);
for (uint256 i = 0; i < length; ++i) {
tokens[i] = fsArray[i];
Fashion storage fs = fashionArray[fsArray[i]];
flags[i] = uint32(uint32(fs.equipmentId) * 10000 + uint32(fs.quality) * 100 + fs.pos);
}
}
/// @dev Race token info returned based on Token ID transfered (64 at most)
function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
} | /* equipmentId
/* 10001 T1
/* 10002 T2
/* 10003 T3
/* 10004 T4
/* 10005 T5
/* 10006 T6
/* 10007 freeCar
/* ==================================================================== */ | Comment | getFashionsAttrs | function getFashionsAttrs(uint256[] _tokens) external view returns(uint16[] attrs) {
uint256 length = _tokens.length;
require(length <= 64);
attrs = new uint16[](length * 13);
uint256 tokenId;
uint256 index;
for (uint256 i = 0; i < length; ++i) {
tokenId = _tokens[i];
if (fashionIdToOwner[tokenId] != address(0)) {
index = i * 13;
Fashion storage fs = fashionArray[tokenId];
attrs[index] = fs.equipmentId;
attrs[index + 1] = fs.quality;
attrs[index + 2] = fs.pos;
attrs[index + 3] = fs.production;
attrs[index + 4] = fs.attack;
attrs[index + 5] = fs.defense;
attrs[index + 6] = fs.plunder;
attrs[index + 7] = fs.productionMultiplier;
attrs[index + 8] = fs.attackMultiplier;
attrs[index + 9] = fs.defenseMultiplier;
attrs[index + 10] = fs.plunderMultiplier;
attrs[index + 11] = fs.level;
attrs[index + 12] = fs.isPercent;
}
}
}
| /// @dev Race token info returned based on Token ID transfered (64 at most) | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://f7b34676bca76b0201237770d21e20b4e00a74dd0fef65b0819874bf70a7e701 | {
"func_code_index": [
17917,
19108
]
} | 848 |
|
StakingPool | StakingPool.sol | 0x47cd7e91c3cbaaf266369fe8518345fc4fc12935 | Solidity | StakingPool | contract StakingPool {
// ERC20 stuff
// Constants
string public constant name = "Ambire Wallet Staking Token";
uint8 public constant decimals = 18;
string public constant symbol = "xWALLET";
// Mutable variables
uint public totalSupply;
mapping(address => uint) private balances;
mapping(address => mapping(address => uint)) private allowed;
// EIP 2612
bytes32 public DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint) public nonces;
// ERC20 events
event Approval(address indexed owner, address indexed spender, uint amount);
event Transfer(address indexed from, address indexed to, uint amount);
// ERC20 methods
function balanceOf(address owner) external view returns (uint balance) {
return balances[owner];
}
function transfer(address to, uint amount) external returns (bool success) {
require(to != address(this), "BAD_ADDRESS");
balances[msg.sender] = balances[msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint amount) external returns (bool success) {
balances[from] = balances[from] - amount;
allowed[from][msg.sender] = allowed[from][msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(from, to, amount);
return true;
}
function approve(address spender, uint amount) external returns (bool success) {
allowed[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function allowance(address owner, address spender) external view returns (uint remaining) {
return allowed[owner][spender];
}
// EIP 2612
function permit(address owner, address spender, uint amount, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, "DEADLINE_EXPIRED");
bytes32 digest = keccak256(abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, amount, nonces[owner]++, deadline))
));
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNATURE");
allowed[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
// Inner
function innerMint(address owner, uint amount) internal {
totalSupply = totalSupply + amount;
balances[owner] = balances[owner] + amount;
// Because of https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transfer-1
emit Transfer(address(0), owner, amount);
}
function innerBurn(address owner, uint amount) internal {
totalSupply = totalSupply - amount;
balances[owner] = balances[owner] - amount;
emit Transfer(owner, address(0), amount);
}
// Pool functionality
uint public timeToUnbond = 20 days;
uint public rageReceivedPromilles = 700;
// Vesting parameters
// we call .mintVesting to get the additional incentive tokens for this pool
uint public vestingEnd = 1675576800;
uint public vestingAmountPerSec = 1268391679350580000;
IWALLETToken public immutable WALLET;
address public governance;
// Commitment ID against the max amount of tokens it will pay out
mapping (bytes32 => uint) public commitments;
// How many of a user's shares are locked
mapping (address => uint) public lockedShares;
// Unbonding commitment from a staker
struct UnbondCommitment {
address owner;
uint shares;
uint unlocksAt;
}
// Staking pool events
// LogLeave/LogWithdraw must begin with the UnbondCommitment struct
event LogLeave(address indexed owner, uint shares, uint unlocksAt, uint maxTokens);
event LogWithdraw(address indexed owner, uint shares, uint unlocksAt, uint maxTokens, uint receivedTokens);
event LogRageLeave(address indexed owner, uint shares, uint maxTokens, uint receivedTokens);
constructor(IWALLETToken token, address governanceAddr) {
WALLET = token;
governance = governanceAddr;
// EIP 2612
uint chainId;
assembly {
chainId := chainid()
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes("1")),
chainId,
address(this)
)
);
}
// Governance functions
function setGovernance(address addr) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
governance = addr;
}
function setRageReceived(uint rageReceived) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
// AUDIT: should there be a minimum here?
require(rageReceived <= 1000, "TOO_LARGE");
rageReceivedPromilles = rageReceived;
}
function setTimeToUnbond(uint time) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
require(time >= 1 days && time <= 30 days, "BOUNDS");
timeToUnbond = time;
}
function setVestingParams(uint end, uint amountPerSecond) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
vestingEnd = end;
vestingAmountPerSec = amountPerSecond;
}
// Pool stuff
function shareValue() external view returns (uint) {
if (totalSupply == 0) return 0;
return ((WALLET.balanceOf(address(this)) + WALLET.supplyController().mintableVesting(address(this), vestingEnd, vestingAmountPerSec))
* 1e18)
/ totalSupply;
}
function innerEnter(address recipient, uint amount) internal {
// Please note that minting has to be in the beginning so that we take it into account
// when using IWALLETToken.balanceOf()
// Minting makes an external call but it"s to a trusted contract (IIWALLETToken)
WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
uint totalWALLET = WALLET.balanceOf(address(this));
// The totalWALLET == 0 check here should be redudnant; the only way to get totalSupply to a nonzero val is by adding WALLET
if (totalSupply == 0 || totalWALLET == 0) {
innerMint(recipient, amount);
} else {
uint256 newShares = (amount * totalSupply) / totalWALLET;
innerMint(recipient, newShares);
}
// AUDIT: no need to check return value cause WALLET throws
WALLET.transferFrom(msg.sender, address(this), amount);
// no events, as innerMint already emits enough to know the shares amount and price
}
function enter(uint amount) external {
innerEnter(msg.sender, amount);
}
function enterTo(address recipient, uint amount) external {
innerEnter(recipient, amount);
}
function unbondingCommitmentWorth(address owner, uint shares, uint unlocksAt) external view returns (uint) {
if (totalSupply == 0) return 0;
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: owner, shares: shares, unlocksAt: unlocksAt })));
uint maxTokens = commitments[commitmentId];
uint totalWALLET = WALLET.balanceOf(address(this));
uint currentTokens = (shares * totalWALLET) / totalSupply;
return currentTokens > maxTokens ? maxTokens : currentTokens;
}
function leave(uint shares, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
require(shares <= balances[msg.sender] - lockedShares[msg.sender], "INSUFFICIENT_SHARES");
uint totalWALLET = WALLET.balanceOf(address(this));
uint maxTokens = (shares * totalWALLET) / totalSupply;
uint unlocksAt = block.timestamp + timeToUnbond;
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: msg.sender, shares: shares, unlocksAt: unlocksAt })));
require(commitments[commitmentId] == 0, "COMMITMENT_EXISTS");
commitments[commitmentId] = maxTokens;
lockedShares[msg.sender] += shares;
emit LogLeave(msg.sender, shares, unlocksAt, maxTokens);
}
function withdraw(uint shares, uint unlocksAt, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
require(block.timestamp > unlocksAt, "UNLOCK_TOO_EARLY");
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: msg.sender, shares: shares, unlocksAt: unlocksAt })));
uint maxTokens = commitments[commitmentId];
require(maxTokens > 0, "NO_COMMITMENT");
uint totalWALLET = WALLET.balanceOf(address(this));
uint currentTokens = (shares * totalWALLET) / totalSupply;
uint receivedTokens = currentTokens > maxTokens ? maxTokens : currentTokens;
commitments[commitmentId] = 0;
lockedShares[msg.sender] -= shares;
innerBurn(msg.sender, shares);
// AUDIT: no need to check return value cause WALLET throws
WALLET.transfer(msg.sender, receivedTokens);
emit LogWithdraw(msg.sender, shares, unlocksAt, maxTokens, receivedTokens);
}
function rageLeave(uint shares, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
uint totalWALLET = WALLET.balanceOf(address(this));
uint walletAmount = (shares * totalWALLET) / totalSupply;
uint receivedTokens = (walletAmount * rageReceivedPromilles) / 1000;
innerBurn(msg.sender, shares);
// AUDIT: no need to check return value cause WALLET throws
WALLET.transfer(msg.sender, receivedTokens);
emit LogRageLeave(msg.sender, shares, walletAmount, receivedTokens);
}
} | balanceOf | function balanceOf(address owner) external view returns (uint balance) {
return balances[owner];
}
| // ERC20 methods | LineComment | v0.8.7+commit.e28d00a7 | None | ipfs://192b614c5e30cea5d75dfac12ba14851b6bd18631decd0a117c18f1520a9b22f | {
"func_code_index": [
864,
969
]
} | 849 |
||
StakingPool | StakingPool.sol | 0x47cd7e91c3cbaaf266369fe8518345fc4fc12935 | Solidity | StakingPool | contract StakingPool {
// ERC20 stuff
// Constants
string public constant name = "Ambire Wallet Staking Token";
uint8 public constant decimals = 18;
string public constant symbol = "xWALLET";
// Mutable variables
uint public totalSupply;
mapping(address => uint) private balances;
mapping(address => mapping(address => uint)) private allowed;
// EIP 2612
bytes32 public DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint) public nonces;
// ERC20 events
event Approval(address indexed owner, address indexed spender, uint amount);
event Transfer(address indexed from, address indexed to, uint amount);
// ERC20 methods
function balanceOf(address owner) external view returns (uint balance) {
return balances[owner];
}
function transfer(address to, uint amount) external returns (bool success) {
require(to != address(this), "BAD_ADDRESS");
balances[msg.sender] = balances[msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint amount) external returns (bool success) {
balances[from] = balances[from] - amount;
allowed[from][msg.sender] = allowed[from][msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(from, to, amount);
return true;
}
function approve(address spender, uint amount) external returns (bool success) {
allowed[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function allowance(address owner, address spender) external view returns (uint remaining) {
return allowed[owner][spender];
}
// EIP 2612
function permit(address owner, address spender, uint amount, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, "DEADLINE_EXPIRED");
bytes32 digest = keccak256(abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, amount, nonces[owner]++, deadline))
));
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNATURE");
allowed[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
// Inner
function innerMint(address owner, uint amount) internal {
totalSupply = totalSupply + amount;
balances[owner] = balances[owner] + amount;
// Because of https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transfer-1
emit Transfer(address(0), owner, amount);
}
function innerBurn(address owner, uint amount) internal {
totalSupply = totalSupply - amount;
balances[owner] = balances[owner] - amount;
emit Transfer(owner, address(0), amount);
}
// Pool functionality
uint public timeToUnbond = 20 days;
uint public rageReceivedPromilles = 700;
// Vesting parameters
// we call .mintVesting to get the additional incentive tokens for this pool
uint public vestingEnd = 1675576800;
uint public vestingAmountPerSec = 1268391679350580000;
IWALLETToken public immutable WALLET;
address public governance;
// Commitment ID against the max amount of tokens it will pay out
mapping (bytes32 => uint) public commitments;
// How many of a user's shares are locked
mapping (address => uint) public lockedShares;
// Unbonding commitment from a staker
struct UnbondCommitment {
address owner;
uint shares;
uint unlocksAt;
}
// Staking pool events
// LogLeave/LogWithdraw must begin with the UnbondCommitment struct
event LogLeave(address indexed owner, uint shares, uint unlocksAt, uint maxTokens);
event LogWithdraw(address indexed owner, uint shares, uint unlocksAt, uint maxTokens, uint receivedTokens);
event LogRageLeave(address indexed owner, uint shares, uint maxTokens, uint receivedTokens);
constructor(IWALLETToken token, address governanceAddr) {
WALLET = token;
governance = governanceAddr;
// EIP 2612
uint chainId;
assembly {
chainId := chainid()
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes("1")),
chainId,
address(this)
)
);
}
// Governance functions
function setGovernance(address addr) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
governance = addr;
}
function setRageReceived(uint rageReceived) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
// AUDIT: should there be a minimum here?
require(rageReceived <= 1000, "TOO_LARGE");
rageReceivedPromilles = rageReceived;
}
function setTimeToUnbond(uint time) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
require(time >= 1 days && time <= 30 days, "BOUNDS");
timeToUnbond = time;
}
function setVestingParams(uint end, uint amountPerSecond) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
vestingEnd = end;
vestingAmountPerSec = amountPerSecond;
}
// Pool stuff
function shareValue() external view returns (uint) {
if (totalSupply == 0) return 0;
return ((WALLET.balanceOf(address(this)) + WALLET.supplyController().mintableVesting(address(this), vestingEnd, vestingAmountPerSec))
* 1e18)
/ totalSupply;
}
function innerEnter(address recipient, uint amount) internal {
// Please note that minting has to be in the beginning so that we take it into account
// when using IWALLETToken.balanceOf()
// Minting makes an external call but it"s to a trusted contract (IIWALLETToken)
WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
uint totalWALLET = WALLET.balanceOf(address(this));
// The totalWALLET == 0 check here should be redudnant; the only way to get totalSupply to a nonzero val is by adding WALLET
if (totalSupply == 0 || totalWALLET == 0) {
innerMint(recipient, amount);
} else {
uint256 newShares = (amount * totalSupply) / totalWALLET;
innerMint(recipient, newShares);
}
// AUDIT: no need to check return value cause WALLET throws
WALLET.transferFrom(msg.sender, address(this), amount);
// no events, as innerMint already emits enough to know the shares amount and price
}
function enter(uint amount) external {
innerEnter(msg.sender, amount);
}
function enterTo(address recipient, uint amount) external {
innerEnter(recipient, amount);
}
function unbondingCommitmentWorth(address owner, uint shares, uint unlocksAt) external view returns (uint) {
if (totalSupply == 0) return 0;
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: owner, shares: shares, unlocksAt: unlocksAt })));
uint maxTokens = commitments[commitmentId];
uint totalWALLET = WALLET.balanceOf(address(this));
uint currentTokens = (shares * totalWALLET) / totalSupply;
return currentTokens > maxTokens ? maxTokens : currentTokens;
}
function leave(uint shares, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
require(shares <= balances[msg.sender] - lockedShares[msg.sender], "INSUFFICIENT_SHARES");
uint totalWALLET = WALLET.balanceOf(address(this));
uint maxTokens = (shares * totalWALLET) / totalSupply;
uint unlocksAt = block.timestamp + timeToUnbond;
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: msg.sender, shares: shares, unlocksAt: unlocksAt })));
require(commitments[commitmentId] == 0, "COMMITMENT_EXISTS");
commitments[commitmentId] = maxTokens;
lockedShares[msg.sender] += shares;
emit LogLeave(msg.sender, shares, unlocksAt, maxTokens);
}
function withdraw(uint shares, uint unlocksAt, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
require(block.timestamp > unlocksAt, "UNLOCK_TOO_EARLY");
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: msg.sender, shares: shares, unlocksAt: unlocksAt })));
uint maxTokens = commitments[commitmentId];
require(maxTokens > 0, "NO_COMMITMENT");
uint totalWALLET = WALLET.balanceOf(address(this));
uint currentTokens = (shares * totalWALLET) / totalSupply;
uint receivedTokens = currentTokens > maxTokens ? maxTokens : currentTokens;
commitments[commitmentId] = 0;
lockedShares[msg.sender] -= shares;
innerBurn(msg.sender, shares);
// AUDIT: no need to check return value cause WALLET throws
WALLET.transfer(msg.sender, receivedTokens);
emit LogWithdraw(msg.sender, shares, unlocksAt, maxTokens, receivedTokens);
}
function rageLeave(uint shares, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
uint totalWALLET = WALLET.balanceOf(address(this));
uint walletAmount = (shares * totalWALLET) / totalSupply;
uint receivedTokens = (walletAmount * rageReceivedPromilles) / 1000;
innerBurn(msg.sender, shares);
// AUDIT: no need to check return value cause WALLET throws
WALLET.transfer(msg.sender, receivedTokens);
emit LogRageLeave(msg.sender, shares, walletAmount, receivedTokens);
}
} | permit | function permit(address owner, address spender, uint amount, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, "DEADLINE_EXPIRED");
bytes32 digest = keccak256(abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, amount, nonces[owner]++, deadline))
));
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNATURE");
allowed[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
| // EIP 2612 | LineComment | v0.8.7+commit.e28d00a7 | None | ipfs://192b614c5e30cea5d75dfac12ba14851b6bd18631decd0a117c18f1520a9b22f | {
"func_code_index": [
1912,
2514
]
} | 850 |
||
StakingPool | StakingPool.sol | 0x47cd7e91c3cbaaf266369fe8518345fc4fc12935 | Solidity | StakingPool | contract StakingPool {
// ERC20 stuff
// Constants
string public constant name = "Ambire Wallet Staking Token";
uint8 public constant decimals = 18;
string public constant symbol = "xWALLET";
// Mutable variables
uint public totalSupply;
mapping(address => uint) private balances;
mapping(address => mapping(address => uint)) private allowed;
// EIP 2612
bytes32 public DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint) public nonces;
// ERC20 events
event Approval(address indexed owner, address indexed spender, uint amount);
event Transfer(address indexed from, address indexed to, uint amount);
// ERC20 methods
function balanceOf(address owner) external view returns (uint balance) {
return balances[owner];
}
function transfer(address to, uint amount) external returns (bool success) {
require(to != address(this), "BAD_ADDRESS");
balances[msg.sender] = balances[msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint amount) external returns (bool success) {
balances[from] = balances[from] - amount;
allowed[from][msg.sender] = allowed[from][msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(from, to, amount);
return true;
}
function approve(address spender, uint amount) external returns (bool success) {
allowed[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function allowance(address owner, address spender) external view returns (uint remaining) {
return allowed[owner][spender];
}
// EIP 2612
function permit(address owner, address spender, uint amount, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, "DEADLINE_EXPIRED");
bytes32 digest = keccak256(abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, amount, nonces[owner]++, deadline))
));
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNATURE");
allowed[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
// Inner
function innerMint(address owner, uint amount) internal {
totalSupply = totalSupply + amount;
balances[owner] = balances[owner] + amount;
// Because of https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transfer-1
emit Transfer(address(0), owner, amount);
}
function innerBurn(address owner, uint amount) internal {
totalSupply = totalSupply - amount;
balances[owner] = balances[owner] - amount;
emit Transfer(owner, address(0), amount);
}
// Pool functionality
uint public timeToUnbond = 20 days;
uint public rageReceivedPromilles = 700;
// Vesting parameters
// we call .mintVesting to get the additional incentive tokens for this pool
uint public vestingEnd = 1675576800;
uint public vestingAmountPerSec = 1268391679350580000;
IWALLETToken public immutable WALLET;
address public governance;
// Commitment ID against the max amount of tokens it will pay out
mapping (bytes32 => uint) public commitments;
// How many of a user's shares are locked
mapping (address => uint) public lockedShares;
// Unbonding commitment from a staker
struct UnbondCommitment {
address owner;
uint shares;
uint unlocksAt;
}
// Staking pool events
// LogLeave/LogWithdraw must begin with the UnbondCommitment struct
event LogLeave(address indexed owner, uint shares, uint unlocksAt, uint maxTokens);
event LogWithdraw(address indexed owner, uint shares, uint unlocksAt, uint maxTokens, uint receivedTokens);
event LogRageLeave(address indexed owner, uint shares, uint maxTokens, uint receivedTokens);
constructor(IWALLETToken token, address governanceAddr) {
WALLET = token;
governance = governanceAddr;
// EIP 2612
uint chainId;
assembly {
chainId := chainid()
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes("1")),
chainId,
address(this)
)
);
}
// Governance functions
function setGovernance(address addr) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
governance = addr;
}
function setRageReceived(uint rageReceived) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
// AUDIT: should there be a minimum here?
require(rageReceived <= 1000, "TOO_LARGE");
rageReceivedPromilles = rageReceived;
}
function setTimeToUnbond(uint time) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
require(time >= 1 days && time <= 30 days, "BOUNDS");
timeToUnbond = time;
}
function setVestingParams(uint end, uint amountPerSecond) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
vestingEnd = end;
vestingAmountPerSec = amountPerSecond;
}
// Pool stuff
function shareValue() external view returns (uint) {
if (totalSupply == 0) return 0;
return ((WALLET.balanceOf(address(this)) + WALLET.supplyController().mintableVesting(address(this), vestingEnd, vestingAmountPerSec))
* 1e18)
/ totalSupply;
}
function innerEnter(address recipient, uint amount) internal {
// Please note that minting has to be in the beginning so that we take it into account
// when using IWALLETToken.balanceOf()
// Minting makes an external call but it"s to a trusted contract (IIWALLETToken)
WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
uint totalWALLET = WALLET.balanceOf(address(this));
// The totalWALLET == 0 check here should be redudnant; the only way to get totalSupply to a nonzero val is by adding WALLET
if (totalSupply == 0 || totalWALLET == 0) {
innerMint(recipient, amount);
} else {
uint256 newShares = (amount * totalSupply) / totalWALLET;
innerMint(recipient, newShares);
}
// AUDIT: no need to check return value cause WALLET throws
WALLET.transferFrom(msg.sender, address(this), amount);
// no events, as innerMint already emits enough to know the shares amount and price
}
function enter(uint amount) external {
innerEnter(msg.sender, amount);
}
function enterTo(address recipient, uint amount) external {
innerEnter(recipient, amount);
}
function unbondingCommitmentWorth(address owner, uint shares, uint unlocksAt) external view returns (uint) {
if (totalSupply == 0) return 0;
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: owner, shares: shares, unlocksAt: unlocksAt })));
uint maxTokens = commitments[commitmentId];
uint totalWALLET = WALLET.balanceOf(address(this));
uint currentTokens = (shares * totalWALLET) / totalSupply;
return currentTokens > maxTokens ? maxTokens : currentTokens;
}
function leave(uint shares, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
require(shares <= balances[msg.sender] - lockedShares[msg.sender], "INSUFFICIENT_SHARES");
uint totalWALLET = WALLET.balanceOf(address(this));
uint maxTokens = (shares * totalWALLET) / totalSupply;
uint unlocksAt = block.timestamp + timeToUnbond;
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: msg.sender, shares: shares, unlocksAt: unlocksAt })));
require(commitments[commitmentId] == 0, "COMMITMENT_EXISTS");
commitments[commitmentId] = maxTokens;
lockedShares[msg.sender] += shares;
emit LogLeave(msg.sender, shares, unlocksAt, maxTokens);
}
function withdraw(uint shares, uint unlocksAt, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
require(block.timestamp > unlocksAt, "UNLOCK_TOO_EARLY");
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: msg.sender, shares: shares, unlocksAt: unlocksAt })));
uint maxTokens = commitments[commitmentId];
require(maxTokens > 0, "NO_COMMITMENT");
uint totalWALLET = WALLET.balanceOf(address(this));
uint currentTokens = (shares * totalWALLET) / totalSupply;
uint receivedTokens = currentTokens > maxTokens ? maxTokens : currentTokens;
commitments[commitmentId] = 0;
lockedShares[msg.sender] -= shares;
innerBurn(msg.sender, shares);
// AUDIT: no need to check return value cause WALLET throws
WALLET.transfer(msg.sender, receivedTokens);
emit LogWithdraw(msg.sender, shares, unlocksAt, maxTokens, receivedTokens);
}
function rageLeave(uint shares, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
uint totalWALLET = WALLET.balanceOf(address(this));
uint walletAmount = (shares * totalWALLET) / totalSupply;
uint receivedTokens = (walletAmount * rageReceivedPromilles) / 1000;
innerBurn(msg.sender, shares);
// AUDIT: no need to check return value cause WALLET throws
WALLET.transfer(msg.sender, receivedTokens);
emit LogRageLeave(msg.sender, shares, walletAmount, receivedTokens);
}
} | innerMint | function innerMint(address owner, uint amount) internal {
totalSupply = totalSupply + amount;
balances[owner] = balances[owner] + amount;
// Because of https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transfer-1
emit Transfer(address(0), owner, amount);
}
| // Inner | LineComment | v0.8.7+commit.e28d00a7 | None | ipfs://192b614c5e30cea5d75dfac12ba14851b6bd18631decd0a117c18f1520a9b22f | {
"func_code_index": [
2528,
2810
]
} | 851 |
||
StakingPool | StakingPool.sol | 0x47cd7e91c3cbaaf266369fe8518345fc4fc12935 | Solidity | StakingPool | contract StakingPool {
// ERC20 stuff
// Constants
string public constant name = "Ambire Wallet Staking Token";
uint8 public constant decimals = 18;
string public constant symbol = "xWALLET";
// Mutable variables
uint public totalSupply;
mapping(address => uint) private balances;
mapping(address => mapping(address => uint)) private allowed;
// EIP 2612
bytes32 public DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint) public nonces;
// ERC20 events
event Approval(address indexed owner, address indexed spender, uint amount);
event Transfer(address indexed from, address indexed to, uint amount);
// ERC20 methods
function balanceOf(address owner) external view returns (uint balance) {
return balances[owner];
}
function transfer(address to, uint amount) external returns (bool success) {
require(to != address(this), "BAD_ADDRESS");
balances[msg.sender] = balances[msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint amount) external returns (bool success) {
balances[from] = balances[from] - amount;
allowed[from][msg.sender] = allowed[from][msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(from, to, amount);
return true;
}
function approve(address spender, uint amount) external returns (bool success) {
allowed[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function allowance(address owner, address spender) external view returns (uint remaining) {
return allowed[owner][spender];
}
// EIP 2612
function permit(address owner, address spender, uint amount, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, "DEADLINE_EXPIRED");
bytes32 digest = keccak256(abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, amount, nonces[owner]++, deadline))
));
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNATURE");
allowed[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
// Inner
function innerMint(address owner, uint amount) internal {
totalSupply = totalSupply + amount;
balances[owner] = balances[owner] + amount;
// Because of https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transfer-1
emit Transfer(address(0), owner, amount);
}
function innerBurn(address owner, uint amount) internal {
totalSupply = totalSupply - amount;
balances[owner] = balances[owner] - amount;
emit Transfer(owner, address(0), amount);
}
// Pool functionality
uint public timeToUnbond = 20 days;
uint public rageReceivedPromilles = 700;
// Vesting parameters
// we call .mintVesting to get the additional incentive tokens for this pool
uint public vestingEnd = 1675576800;
uint public vestingAmountPerSec = 1268391679350580000;
IWALLETToken public immutable WALLET;
address public governance;
// Commitment ID against the max amount of tokens it will pay out
mapping (bytes32 => uint) public commitments;
// How many of a user's shares are locked
mapping (address => uint) public lockedShares;
// Unbonding commitment from a staker
struct UnbondCommitment {
address owner;
uint shares;
uint unlocksAt;
}
// Staking pool events
// LogLeave/LogWithdraw must begin with the UnbondCommitment struct
event LogLeave(address indexed owner, uint shares, uint unlocksAt, uint maxTokens);
event LogWithdraw(address indexed owner, uint shares, uint unlocksAt, uint maxTokens, uint receivedTokens);
event LogRageLeave(address indexed owner, uint shares, uint maxTokens, uint receivedTokens);
constructor(IWALLETToken token, address governanceAddr) {
WALLET = token;
governance = governanceAddr;
// EIP 2612
uint chainId;
assembly {
chainId := chainid()
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes("1")),
chainId,
address(this)
)
);
}
// Governance functions
function setGovernance(address addr) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
governance = addr;
}
function setRageReceived(uint rageReceived) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
// AUDIT: should there be a minimum here?
require(rageReceived <= 1000, "TOO_LARGE");
rageReceivedPromilles = rageReceived;
}
function setTimeToUnbond(uint time) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
require(time >= 1 days && time <= 30 days, "BOUNDS");
timeToUnbond = time;
}
function setVestingParams(uint end, uint amountPerSecond) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
vestingEnd = end;
vestingAmountPerSec = amountPerSecond;
}
// Pool stuff
function shareValue() external view returns (uint) {
if (totalSupply == 0) return 0;
return ((WALLET.balanceOf(address(this)) + WALLET.supplyController().mintableVesting(address(this), vestingEnd, vestingAmountPerSec))
* 1e18)
/ totalSupply;
}
function innerEnter(address recipient, uint amount) internal {
// Please note that minting has to be in the beginning so that we take it into account
// when using IWALLETToken.balanceOf()
// Minting makes an external call but it"s to a trusted contract (IIWALLETToken)
WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
uint totalWALLET = WALLET.balanceOf(address(this));
// The totalWALLET == 0 check here should be redudnant; the only way to get totalSupply to a nonzero val is by adding WALLET
if (totalSupply == 0 || totalWALLET == 0) {
innerMint(recipient, amount);
} else {
uint256 newShares = (amount * totalSupply) / totalWALLET;
innerMint(recipient, newShares);
}
// AUDIT: no need to check return value cause WALLET throws
WALLET.transferFrom(msg.sender, address(this), amount);
// no events, as innerMint already emits enough to know the shares amount and price
}
function enter(uint amount) external {
innerEnter(msg.sender, amount);
}
function enterTo(address recipient, uint amount) external {
innerEnter(recipient, amount);
}
function unbondingCommitmentWorth(address owner, uint shares, uint unlocksAt) external view returns (uint) {
if (totalSupply == 0) return 0;
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: owner, shares: shares, unlocksAt: unlocksAt })));
uint maxTokens = commitments[commitmentId];
uint totalWALLET = WALLET.balanceOf(address(this));
uint currentTokens = (shares * totalWALLET) / totalSupply;
return currentTokens > maxTokens ? maxTokens : currentTokens;
}
function leave(uint shares, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
require(shares <= balances[msg.sender] - lockedShares[msg.sender], "INSUFFICIENT_SHARES");
uint totalWALLET = WALLET.balanceOf(address(this));
uint maxTokens = (shares * totalWALLET) / totalSupply;
uint unlocksAt = block.timestamp + timeToUnbond;
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: msg.sender, shares: shares, unlocksAt: unlocksAt })));
require(commitments[commitmentId] == 0, "COMMITMENT_EXISTS");
commitments[commitmentId] = maxTokens;
lockedShares[msg.sender] += shares;
emit LogLeave(msg.sender, shares, unlocksAt, maxTokens);
}
function withdraw(uint shares, uint unlocksAt, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
require(block.timestamp > unlocksAt, "UNLOCK_TOO_EARLY");
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: msg.sender, shares: shares, unlocksAt: unlocksAt })));
uint maxTokens = commitments[commitmentId];
require(maxTokens > 0, "NO_COMMITMENT");
uint totalWALLET = WALLET.balanceOf(address(this));
uint currentTokens = (shares * totalWALLET) / totalSupply;
uint receivedTokens = currentTokens > maxTokens ? maxTokens : currentTokens;
commitments[commitmentId] = 0;
lockedShares[msg.sender] -= shares;
innerBurn(msg.sender, shares);
// AUDIT: no need to check return value cause WALLET throws
WALLET.transfer(msg.sender, receivedTokens);
emit LogWithdraw(msg.sender, shares, unlocksAt, maxTokens, receivedTokens);
}
function rageLeave(uint shares, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
uint totalWALLET = WALLET.balanceOf(address(this));
uint walletAmount = (shares * totalWALLET) / totalSupply;
uint receivedTokens = (walletAmount * rageReceivedPromilles) / 1000;
innerBurn(msg.sender, shares);
// AUDIT: no need to check return value cause WALLET throws
WALLET.transfer(msg.sender, receivedTokens);
emit LogRageLeave(msg.sender, shares, walletAmount, receivedTokens);
}
} | setGovernance | function setGovernance(address addr) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
governance = addr;
}
| // Governance functions | LineComment | v0.8.7+commit.e28d00a7 | None | ipfs://192b614c5e30cea5d75dfac12ba14851b6bd18631decd0a117c18f1520a9b22f | {
"func_code_index": [
4583,
4714
]
} | 852 |
||
StakingPool | StakingPool.sol | 0x47cd7e91c3cbaaf266369fe8518345fc4fc12935 | Solidity | StakingPool | contract StakingPool {
// ERC20 stuff
// Constants
string public constant name = "Ambire Wallet Staking Token";
uint8 public constant decimals = 18;
string public constant symbol = "xWALLET";
// Mutable variables
uint public totalSupply;
mapping(address => uint) private balances;
mapping(address => mapping(address => uint)) private allowed;
// EIP 2612
bytes32 public DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint) public nonces;
// ERC20 events
event Approval(address indexed owner, address indexed spender, uint amount);
event Transfer(address indexed from, address indexed to, uint amount);
// ERC20 methods
function balanceOf(address owner) external view returns (uint balance) {
return balances[owner];
}
function transfer(address to, uint amount) external returns (bool success) {
require(to != address(this), "BAD_ADDRESS");
balances[msg.sender] = balances[msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint amount) external returns (bool success) {
balances[from] = balances[from] - amount;
allowed[from][msg.sender] = allowed[from][msg.sender] - amount;
balances[to] = balances[to] + amount;
emit Transfer(from, to, amount);
return true;
}
function approve(address spender, uint amount) external returns (bool success) {
allowed[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function allowance(address owner, address spender) external view returns (uint remaining) {
return allowed[owner][spender];
}
// EIP 2612
function permit(address owner, address spender, uint amount, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, "DEADLINE_EXPIRED");
bytes32 digest = keccak256(abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, amount, nonces[owner]++, deadline))
));
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNATURE");
allowed[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
// Inner
function innerMint(address owner, uint amount) internal {
totalSupply = totalSupply + amount;
balances[owner] = balances[owner] + amount;
// Because of https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transfer-1
emit Transfer(address(0), owner, amount);
}
function innerBurn(address owner, uint amount) internal {
totalSupply = totalSupply - amount;
balances[owner] = balances[owner] - amount;
emit Transfer(owner, address(0), amount);
}
// Pool functionality
uint public timeToUnbond = 20 days;
uint public rageReceivedPromilles = 700;
// Vesting parameters
// we call .mintVesting to get the additional incentive tokens for this pool
uint public vestingEnd = 1675576800;
uint public vestingAmountPerSec = 1268391679350580000;
IWALLETToken public immutable WALLET;
address public governance;
// Commitment ID against the max amount of tokens it will pay out
mapping (bytes32 => uint) public commitments;
// How many of a user's shares are locked
mapping (address => uint) public lockedShares;
// Unbonding commitment from a staker
struct UnbondCommitment {
address owner;
uint shares;
uint unlocksAt;
}
// Staking pool events
// LogLeave/LogWithdraw must begin with the UnbondCommitment struct
event LogLeave(address indexed owner, uint shares, uint unlocksAt, uint maxTokens);
event LogWithdraw(address indexed owner, uint shares, uint unlocksAt, uint maxTokens, uint receivedTokens);
event LogRageLeave(address indexed owner, uint shares, uint maxTokens, uint receivedTokens);
constructor(IWALLETToken token, address governanceAddr) {
WALLET = token;
governance = governanceAddr;
// EIP 2612
uint chainId;
assembly {
chainId := chainid()
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes("1")),
chainId,
address(this)
)
);
}
// Governance functions
function setGovernance(address addr) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
governance = addr;
}
function setRageReceived(uint rageReceived) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
// AUDIT: should there be a minimum here?
require(rageReceived <= 1000, "TOO_LARGE");
rageReceivedPromilles = rageReceived;
}
function setTimeToUnbond(uint time) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
require(time >= 1 days && time <= 30 days, "BOUNDS");
timeToUnbond = time;
}
function setVestingParams(uint end, uint amountPerSecond) external {
require(governance == msg.sender, "NOT_GOVERNANCE");
vestingEnd = end;
vestingAmountPerSec = amountPerSecond;
}
// Pool stuff
function shareValue() external view returns (uint) {
if (totalSupply == 0) return 0;
return ((WALLET.balanceOf(address(this)) + WALLET.supplyController().mintableVesting(address(this), vestingEnd, vestingAmountPerSec))
* 1e18)
/ totalSupply;
}
function innerEnter(address recipient, uint amount) internal {
// Please note that minting has to be in the beginning so that we take it into account
// when using IWALLETToken.balanceOf()
// Minting makes an external call but it"s to a trusted contract (IIWALLETToken)
WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
uint totalWALLET = WALLET.balanceOf(address(this));
// The totalWALLET == 0 check here should be redudnant; the only way to get totalSupply to a nonzero val is by adding WALLET
if (totalSupply == 0 || totalWALLET == 0) {
innerMint(recipient, amount);
} else {
uint256 newShares = (amount * totalSupply) / totalWALLET;
innerMint(recipient, newShares);
}
// AUDIT: no need to check return value cause WALLET throws
WALLET.transferFrom(msg.sender, address(this), amount);
// no events, as innerMint already emits enough to know the shares amount and price
}
function enter(uint amount) external {
innerEnter(msg.sender, amount);
}
function enterTo(address recipient, uint amount) external {
innerEnter(recipient, amount);
}
function unbondingCommitmentWorth(address owner, uint shares, uint unlocksAt) external view returns (uint) {
if (totalSupply == 0) return 0;
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: owner, shares: shares, unlocksAt: unlocksAt })));
uint maxTokens = commitments[commitmentId];
uint totalWALLET = WALLET.balanceOf(address(this));
uint currentTokens = (shares * totalWALLET) / totalSupply;
return currentTokens > maxTokens ? maxTokens : currentTokens;
}
function leave(uint shares, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
require(shares <= balances[msg.sender] - lockedShares[msg.sender], "INSUFFICIENT_SHARES");
uint totalWALLET = WALLET.balanceOf(address(this));
uint maxTokens = (shares * totalWALLET) / totalSupply;
uint unlocksAt = block.timestamp + timeToUnbond;
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: msg.sender, shares: shares, unlocksAt: unlocksAt })));
require(commitments[commitmentId] == 0, "COMMITMENT_EXISTS");
commitments[commitmentId] = maxTokens;
lockedShares[msg.sender] += shares;
emit LogLeave(msg.sender, shares, unlocksAt, maxTokens);
}
function withdraw(uint shares, uint unlocksAt, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
require(block.timestamp > unlocksAt, "UNLOCK_TOO_EARLY");
bytes32 commitmentId = keccak256(abi.encode(UnbondCommitment({ owner: msg.sender, shares: shares, unlocksAt: unlocksAt })));
uint maxTokens = commitments[commitmentId];
require(maxTokens > 0, "NO_COMMITMENT");
uint totalWALLET = WALLET.balanceOf(address(this));
uint currentTokens = (shares * totalWALLET) / totalSupply;
uint receivedTokens = currentTokens > maxTokens ? maxTokens : currentTokens;
commitments[commitmentId] = 0;
lockedShares[msg.sender] -= shares;
innerBurn(msg.sender, shares);
// AUDIT: no need to check return value cause WALLET throws
WALLET.transfer(msg.sender, receivedTokens);
emit LogWithdraw(msg.sender, shares, unlocksAt, maxTokens, receivedTokens);
}
function rageLeave(uint shares, bool skipMint) external {
if (!skipMint) WALLET.supplyController().mintVesting(address(this), vestingEnd, vestingAmountPerSec);
uint totalWALLET = WALLET.balanceOf(address(this));
uint walletAmount = (shares * totalWALLET) / totalSupply;
uint receivedTokens = (walletAmount * rageReceivedPromilles) / 1000;
innerBurn(msg.sender, shares);
// AUDIT: no need to check return value cause WALLET throws
WALLET.transfer(msg.sender, receivedTokens);
emit LogRageLeave(msg.sender, shares, walletAmount, receivedTokens);
}
} | shareValue | function shareValue() external view returns (uint) {
if (totalSupply == 0) return 0;
return ((WALLET.balanceOf(address(this)) + WALLET.supplyController().mintableVesting(address(this), vestingEnd, vestingAmountPerSec))
* 1e18)
/ totalSupply;
}
| // Pool stuff | LineComment | v0.8.7+commit.e28d00a7 | None | ipfs://192b614c5e30cea5d75dfac12ba14851b6bd18631decd0a117c18f1520a9b22f | {
"func_code_index": [
5367,
5628
]
} | 853 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | Ownable | contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == msg.sender, "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | owner | function owner() public view returns (address) {
return _owner;
}
| /**
* @dev Returns the address of the current owner.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
445,
529
]
} | 854 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | Ownable | contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == msg.sender, "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | renounceOwnership | function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
| /**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
1085,
1230
]
} | 855 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | Ownable | contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == msg.sender, "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | transferOwnership | function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
| /**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
1380,
1621
]
} | 856 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: 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
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | totalSupply | function totalSupply() external view returns (uint256);
| /**
* @dev Returns the amount of tokens in existence.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
94,
154
]
} | 857 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: 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
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | balanceOf | function balanceOf(address account) external view returns (uint256);
| /**
* @dev Returns the amount of tokens owned by `account`.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
237,
310
]
} | 858 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: 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
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | transfer | function transfer(address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
534,
616
]
} | 859 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: 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
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | allowance | function allowance(address owner, address spender) external view returns (uint256);
| /**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
895,
983
]
} | 860 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: 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
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | approve | function approve(address spender, uint256 amount) external returns (bool);
| /**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: 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
*
* Emits an {Approval} event.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
1647,
1726
]
} | 861 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: 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
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | transferFrom | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
2039,
2141
]
} | 862 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20Detailed | contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for `name`, `symbol`, and `decimals`. All three of
* these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
} | name | function name() public view returns (string memory) {
return _name;
}
| /**
* @dev Returns the name of the token.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
550,
638
]
} | 863 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20Detailed | contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for `name`, `symbol`, and `decimals`. All three of
* these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
} | symbol | function symbol() public view returns (string memory) {
return _symbol;
}
| /**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
752,
844
]
} | 864 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20Detailed | contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for `name`, `symbol`, and `decimals`. All three of
* these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
} | decimals | function decimals() public view returns (uint8) {
return _decimals;
}
| /**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
1402,
1490
]
} | 865 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | totalSupply | function totalSupply() public view returns (uint256) {
return _totalSupply;
}
| /**
* @dev See {IERC20-totalSupply}.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
291,
387
]
} | 866 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | balanceOf | function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
| /**
* @dev See {IERC20-balanceOf}.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
445,
560
]
} | 867 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | transfer | function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
| /**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
768,
929
]
} | 868 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | allowance | function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
| /**
* @dev See {IERC20-allowance}.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
987,
1126
]
} | 869 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | approve | function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
| /**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
1268,
1421
]
} | 870 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | transferFrom | function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
| /**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
1887,
2148
]
} | 871 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | increaseAllowance | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
| /**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
2552,
2763
]
} | 872 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | decreaseAllowance | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
| /**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
3261,
3482
]
} | 873 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | _transfer | function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
| /**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
3967,
4401
]
} | 874 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | _mint | function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
| /** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
4677,
4990
]
} | 875 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | _burn | function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
| /**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
5318,
5629
]
} | 876 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | _approve | function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
| /**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
6064,
6404
]
} | 877 |
||
Token8848 | Token8848.sol | 0x38d4cdc85656467e46337793a0dd53376f8b58e5 | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 internal _totalSupply;
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
} | _burnFrom | function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
| /**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | MIT | bzzr://a4063894cf2d9850c904fd6b7970ba14389dcef975278759fcb7d1b37dcc5374 | {
"func_code_index": [
6584,
6777
]
} | 878 |
||
DOSXToken | DOSXToken.sol | 0x6a807ae567fd14d7bb7b9559416321cac07edd70 | Solidity | DOSXToken | contract DOSXToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function DOSXToken() public {
symbol = "DOSX";
name = "DOSXToken";
decimals = 18;
_totalSupply = 12000000000000000000000000;
balances[0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43] = _totalSupply;
Transfer(address(0), 0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | DOSXToken | function DOSXToken() public {
symbol = "DOSX";
name = "DOSXToken";
decimals = 18;
_totalSupply = 12000000000000000000000000;
balances[0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43] = _totalSupply;
Transfer(address(0), 0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43, _totalSupply);
}
| // ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://e9598a9ef5a2c085656cfd07e6b2485d41937dd9348143fd5d4af0cf0637b9fa | {
"func_code_index": [
456,
795
]
} | 879 |
|
DOSXToken | DOSXToken.sol | 0x6a807ae567fd14d7bb7b9559416321cac07edd70 | Solidity | DOSXToken | contract DOSXToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function DOSXToken() public {
symbol = "DOSX";
name = "DOSXToken";
decimals = 18;
_totalSupply = 12000000000000000000000000;
balances[0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43] = _totalSupply;
Transfer(address(0), 0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | totalSupply | function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
| // ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://e9598a9ef5a2c085656cfd07e6b2485d41937dd9348143fd5d4af0cf0637b9fa | {
"func_code_index": [
983,
1104
]
} | 880 |
|
DOSXToken | DOSXToken.sol | 0x6a807ae567fd14d7bb7b9559416321cac07edd70 | Solidity | DOSXToken | contract DOSXToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function DOSXToken() public {
symbol = "DOSX";
name = "DOSXToken";
decimals = 18;
_totalSupply = 12000000000000000000000000;
balances[0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43] = _totalSupply;
Transfer(address(0), 0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | balanceOf | function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
| // ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://e9598a9ef5a2c085656cfd07e6b2485d41937dd9348143fd5d4af0cf0637b9fa | {
"func_code_index": [
1324,
1453
]
} | 881 |
|
DOSXToken | DOSXToken.sol | 0x6a807ae567fd14d7bb7b9559416321cac07edd70 | Solidity | DOSXToken | contract DOSXToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function DOSXToken() public {
symbol = "DOSX";
name = "DOSXToken";
decimals = 18;
_totalSupply = 12000000000000000000000000;
balances[0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43] = _totalSupply;
Transfer(address(0), 0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | transfer | function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://e9598a9ef5a2c085656cfd07e6b2485d41937dd9348143fd5d4af0cf0637b9fa | {
"func_code_index": [
1797,
2074
]
} | 882 |
|
DOSXToken | DOSXToken.sol | 0x6a807ae567fd14d7bb7b9559416321cac07edd70 | Solidity | DOSXToken | contract DOSXToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function DOSXToken() public {
symbol = "DOSX";
name = "DOSXToken";
decimals = 18;
_totalSupply = 12000000000000000000000000;
balances[0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43] = _totalSupply;
Transfer(address(0), 0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | approve | function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://e9598a9ef5a2c085656cfd07e6b2485d41937dd9348143fd5d4af0cf0637b9fa | {
"func_code_index": [
2582,
2790
]
} | 883 |
|
DOSXToken | DOSXToken.sol | 0x6a807ae567fd14d7bb7b9559416321cac07edd70 | Solidity | DOSXToken | contract DOSXToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function DOSXToken() public {
symbol = "DOSX";
name = "DOSXToken";
decimals = 18;
_totalSupply = 12000000000000000000000000;
balances[0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43] = _totalSupply;
Transfer(address(0), 0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | transferFrom | function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://e9598a9ef5a2c085656cfd07e6b2485d41937dd9348143fd5d4af0cf0637b9fa | {
"func_code_index": [
3321,
3679
]
} | 884 |
|
DOSXToken | DOSXToken.sol | 0x6a807ae567fd14d7bb7b9559416321cac07edd70 | Solidity | DOSXToken | contract DOSXToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function DOSXToken() public {
symbol = "DOSX";
name = "DOSXToken";
decimals = 18;
_totalSupply = 12000000000000000000000000;
balances[0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43] = _totalSupply;
Transfer(address(0), 0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | allowance | function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
| // ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://e9598a9ef5a2c085656cfd07e6b2485d41937dd9348143fd5d4af0cf0637b9fa | {
"func_code_index": [
3962,
4118
]
} | 885 |
|
DOSXToken | DOSXToken.sol | 0x6a807ae567fd14d7bb7b9559416321cac07edd70 | Solidity | DOSXToken | contract DOSXToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function DOSXToken() public {
symbol = "DOSX";
name = "DOSXToken";
decimals = 18;
_totalSupply = 12000000000000000000000000;
balances[0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43] = _totalSupply;
Transfer(address(0), 0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | approveAndCall | function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://e9598a9ef5a2c085656cfd07e6b2485d41937dd9348143fd5d4af0cf0637b9fa | {
"func_code_index": [
4473,
4790
]
} | 886 |
|
DOSXToken | DOSXToken.sol | 0x6a807ae567fd14d7bb7b9559416321cac07edd70 | Solidity | DOSXToken | contract DOSXToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function DOSXToken() public {
symbol = "DOSX";
name = "DOSXToken";
decimals = 18;
_totalSupply = 12000000000000000000000000;
balances[0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43] = _totalSupply;
Transfer(address(0), 0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | function () public payable {
revert();
}
| // ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://e9598a9ef5a2c085656cfd07e6b2485d41937dd9348143fd5d4af0cf0637b9fa | {
"func_code_index": [
4982,
5041
]
} | 887 |
||
DOSXToken | DOSXToken.sol | 0x6a807ae567fd14d7bb7b9559416321cac07edd70 | Solidity | DOSXToken | contract DOSXToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function DOSXToken() public {
symbol = "DOSX";
name = "DOSXToken";
decimals = 18;
_totalSupply = 12000000000000000000000000;
balances[0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43] = _totalSupply;
Transfer(address(0), 0xF58a749AB4929b462F33b8A07f1e3b568ed8eC43, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | transferAnyERC20Token | function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
| // ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://e9598a9ef5a2c085656cfd07e6b2485d41937dd9348143fd5d4af0cf0637b9fa | {
"func_code_index": [
5274,
5463
]
} | 888 |
|
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | IERC165 | interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
} | /**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/ | NatSpecMultiLine | supportsInterface | function supportsInterface(bytes4 interfaceId) external view returns (bool);
| /**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
374,
455
]
} | 889 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | ERC165 | abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
} | /**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/ | NatSpecMultiLine | supportsInterface | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
| /**
* @dev See {IERC165-supportsInterface}.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
103,
265
]
} | 890 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | IERC1155Receiver | interface IERC1155Receiver is IERC165 {
/**
@dev Handles the receipt of a single ERC1155 token type. This function is
called at the end of a `safeTransferFrom` after the balance has been updated.
To accept the transfer, this must return
`bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
(i.e. 0xf23a6e61, or its own function selector).
@param operator The address which initiated the transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param id The ID of the token being transferred
@param value The amount of tokens being transferred
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
@dev Handles the receipt of a multiple ERC1155 token types. This function
is called at the end of a `safeBatchTransferFrom` after the balances have
been updated. To accept the transfer(s), this must return
`bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
(i.e. 0xbc197c81, or its own function selector).
@param operator The address which initiated the batch transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param ids An array containing ids of each token being transferred (order and length must match values array)
@param values An array containing amounts of each token being transferred (order and length must match ids array)
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
} | /**
* @dev _Available since v3.1._
*/ | NatSpecMultiLine | onERC1155Received | function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
| /**
@dev Handles the receipt of a single ERC1155 token type. This function is
called at the end of a `safeTransferFrom` after the balance has been updated.
To accept the transfer, this must return
`bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
(i.e. 0xf23a6e61, or its own function selector).
@param operator The address which initiated the transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param id The ID of the token being transferred
@param value The amount of tokens being transferred
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
875,
1065
]
} | 891 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | IERC1155Receiver | interface IERC1155Receiver is IERC165 {
/**
@dev Handles the receipt of a single ERC1155 token type. This function is
called at the end of a `safeTransferFrom` after the balance has been updated.
To accept the transfer, this must return
`bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
(i.e. 0xf23a6e61, or its own function selector).
@param operator The address which initiated the transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param id The ID of the token being transferred
@param value The amount of tokens being transferred
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
@dev Handles the receipt of a multiple ERC1155 token types. This function
is called at the end of a `safeBatchTransferFrom` after the balances have
been updated. To accept the transfer(s), this must return
`bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
(i.e. 0xbc197c81, or its own function selector).
@param operator The address which initiated the batch transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param ids An array containing ids of each token being transferred (order and length must match values array)
@param values An array containing amounts of each token being transferred (order and length must match ids array)
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
} | /**
* @dev _Available since v3.1._
*/ | NatSpecMultiLine | onERC1155BatchReceived | function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
| /**
@dev Handles the receipt of a multiple ERC1155 token types. This function
is called at the end of a `safeBatchTransferFrom` after the balances have
been updated. To accept the transfer(s), this must return
`bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
(i.e. 0xbc197c81, or its own function selector).
@param operator The address which initiated the batch transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param ids An array containing ids of each token being transferred (order and length must match values array)
@param values An array containing amounts of each token being transferred (order and length must match ids array)
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
2063,
2282
]
} | 892 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | ERC1155Receiver | abstract contract ERC1155Receiver is ERC165, IERC1155Receiver {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
}
} | /**
* @dev _Available since v3.1._
*/ | NatSpecMultiLine | supportsInterface | function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
}
| /**
* @dev See {IERC165-supportsInterface}.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
129,
357
]
} | 893 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | tryAdd | function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
| /**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
161,
388
]
} | 894 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | trySub | function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
| /**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
536,
735
]
} | 895 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | tryMul | function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
| /**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
885,
1393
]
} | 896 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | tryDiv | function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
| /**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
1544,
1744
]
} | 897 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | tryMod | function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
| /**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
1905,
2105
]
} | 898 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
| /**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
2347,
2450
]
} | 899 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
2728,
2831
]
} | 900 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
3085,
3188
]
} | 901 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
| /**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
3484,
3587
]
} | 902 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
4049,
4152
]
} | 903 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | sub | function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
4626,
4871
]
} | 904 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | div | function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
| /**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
5364,
5608
]
} | 905 |
DutchAuction | DutchAuction.sol | 0x0ead3984384ba026feb5d2e1022b28abe2f11cb3 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/ | NatSpecMultiLine | mod | function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://0a6fd78671f82266286c87785c5f9c329dc6715c7ea1d5ebb50323b92528d1fa | {
"func_code_index": [
6266,
6510
]
} | 906 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.