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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
GBTToken | GBTToken.sol | 0xf9d7c212cb020501fd0991b68d094f80e8b4bdad | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
| /**
* @dev Integer division of two numbers, truncating the quotient.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | None | bzzr://11bb640bb38b0495160c97061006fffb4c8ec934b77cf8e75c748f3c8903b93d | {
"func_code_index": [
350,
630
]
} | 57,261 |
GBTToken | GBTToken.sol | 0xf9d7c212cb020501fd0991b68d094f80e8b4bdad | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
| /**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | None | bzzr://11bb640bb38b0495160c97061006fffb4c8ec934b77cf8e75c748f3c8903b93d | {
"func_code_index": [
744,
860
]
} | 57,262 |
GBTToken | GBTToken.sol | 0xf9d7c212cb020501fd0991b68d094f80e8b4bdad | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
| /**
* @dev Adds two numbers, throws on overflow.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | None | bzzr://11bb640bb38b0495160c97061006fffb4c8ec934b77cf8e75c748f3c8903b93d | {
"func_code_index": [
924,
1054
]
} | 57,263 |
GBTToken | GBTToken.sol | 0xf9d7c212cb020501fd0991b68d094f80e8b4bdad | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view returns (uint256) {
return totalSupply_;
}
| /**
* @dev total number of tokens in existence
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | None | bzzr://11bb640bb38b0495160c97061006fffb4c8ec934b77cf8e75c748f3c8903b93d | {
"func_code_index": [
199,
287
]
} | 57,264 |
GBTToken | GBTToken.sol | 0xf9d7c212cb020501fd0991b68d094f80e8b4bdad | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | 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);
emit Transfer(msg.sender, _to, _value);
return true;
}
| /**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | None | bzzr://11bb640bb38b0495160c97061006fffb4c8ec934b77cf8e75c748f3c8903b93d | {
"func_code_index": [
445,
777
]
} | 57,265 |
GBTToken | GBTToken.sol | 0xf9d7c212cb020501fd0991b68d094f80e8b4bdad | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
| /**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | None | bzzr://11bb640bb38b0495160c97061006fffb4c8ec934b77cf8e75c748f3c8903b93d | {
"func_code_index": [
983,
1087
]
} | 57,266 |
GBTToken | GBTToken.sol | 0xf9d7c212cb020501fd0991b68d094f80e8b4bdad | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
| /**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | None | bzzr://11bb640bb38b0495160c97061006fffb4c8ec934b77cf8e75c748f3c8903b93d | {
"func_code_index": [
401,
858
]
} | 57,267 |
GBTToken | GBTToken.sol | 0xf9d7c212cb020501fd0991b68d094f80e8b4bdad | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | approve | function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
| /**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | None | bzzr://11bb640bb38b0495160c97061006fffb4c8ec934b77cf8e75c748f3c8903b93d | {
"func_code_index": [
1490,
1685
]
} | 57,268 |
GBTToken | GBTToken.sol | 0xf9d7c212cb020501fd0991b68d094f80e8b4bdad | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | allowance | function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
| /**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | None | bzzr://11bb640bb38b0495160c97061006fffb4c8ec934b77cf8e75c748f3c8903b93d | {
"func_code_index": [
2009,
2140
]
} | 57,269 |
GBTToken | GBTToken.sol | 0xf9d7c212cb020501fd0991b68d094f80e8b4bdad | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | increaseApproval | function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | None | bzzr://11bb640bb38b0495160c97061006fffb4c8ec934b77cf8e75c748f3c8903b93d | {
"func_code_index": [
2606,
2875
]
} | 57,270 |
GBTToken | GBTToken.sol | 0xf9d7c212cb020501fd0991b68d094f80e8b4bdad | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | decreaseApproval | function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | None | bzzr://11bb640bb38b0495160c97061006fffb4c8ec934b77cf8e75c748f3c8903b93d | {
"func_code_index": [
3346,
3761
]
} | 57,271 |
Vicion | Vicion.sol | 0x77c8a119173f0c0656f55954e4ebc1517b32afed | Solidity | Vicion | contract Vicion is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "VIC";
name = "Vicion";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) public returns (bool success){
if(msg.sender != owner)revert();
msg.sender.transfer(amount);
return true;
}
// ------------------------------------------------------------------------
// Accept ETH
// ------------------------------------------------------------------------
function () external payable {
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ---------------------------------------------------------------------------- | LineComment | totalSupply | function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
| // ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------ | LineComment | v0.5.4+commit.9549d8ff | bzzr://e2c06dd14b32f6edc44a6bc70367907571ddf8f0139c0ff73700d053cf9f29a3 | {
"func_code_index": [
920,
1039
]
} | 57,272 |
|
Vicion | Vicion.sol | 0x77c8a119173f0c0656f55954e4ebc1517b32afed | Solidity | Vicion | contract Vicion is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "VIC";
name = "Vicion";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) public returns (bool success){
if(msg.sender != owner)revert();
msg.sender.transfer(amount);
return true;
}
// ------------------------------------------------------------------------
// Accept ETH
// ------------------------------------------------------------------------
function () external payable {
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ---------------------------------------------------------------------------- | LineComment | balanceOf | function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
| // ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------ | LineComment | v0.5.4+commit.9549d8ff | bzzr://e2c06dd14b32f6edc44a6bc70367907571ddf8f0139c0ff73700d053cf9f29a3 | {
"func_code_index": [
1261,
1386
]
} | 57,273 |
|
Vicion | Vicion.sol | 0x77c8a119173f0c0656f55954e4ebc1517b32afed | Solidity | Vicion | contract Vicion is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "VIC";
name = "Vicion";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) public returns (bool success){
if(msg.sender != owner)revert();
msg.sender.transfer(amount);
return true;
}
// ------------------------------------------------------------------------
// Accept ETH
// ------------------------------------------------------------------------
function () external payable {
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ---------------------------------------------------------------------------- | LineComment | transfer | function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.5.4+commit.9549d8ff | bzzr://e2c06dd14b32f6edc44a6bc70367907571ddf8f0139c0ff73700d053cf9f29a3 | {
"func_code_index": [
1732,
2004
]
} | 57,274 |
|
Vicion | Vicion.sol | 0x77c8a119173f0c0656f55954e4ebc1517b32afed | Solidity | Vicion | contract Vicion is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "VIC";
name = "Vicion";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) public returns (bool success){
if(msg.sender != owner)revert();
msg.sender.transfer(amount);
return true;
}
// ------------------------------------------------------------------------
// Accept ETH
// ------------------------------------------------------------------------
function () external payable {
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ---------------------------------------------------------------------------- | LineComment | approve | function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------ | LineComment | v0.5.4+commit.9549d8ff | bzzr://e2c06dd14b32f6edc44a6bc70367907571ddf8f0139c0ff73700d053cf9f29a3 | {
"func_code_index": [
2515,
2728
]
} | 57,275 |
|
Vicion | Vicion.sol | 0x77c8a119173f0c0656f55954e4ebc1517b32afed | Solidity | Vicion | contract Vicion is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "VIC";
name = "Vicion";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) public returns (bool success){
if(msg.sender != owner)revert();
msg.sender.transfer(amount);
return true;
}
// ------------------------------------------------------------------------
// Accept ETH
// ------------------------------------------------------------------------
function () external payable {
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ---------------------------------------------------------------------------- | LineComment | transferFrom | function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.5.4+commit.9549d8ff | bzzr://e2c06dd14b32f6edc44a6bc70367907571ddf8f0139c0ff73700d053cf9f29a3 | {
"func_code_index": [
3266,
3614
]
} | 57,276 |
|
Vicion | Vicion.sol | 0x77c8a119173f0c0656f55954e4ebc1517b32afed | Solidity | Vicion | contract Vicion is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "VIC";
name = "Vicion";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) public returns (bool success){
if(msg.sender != owner)revert();
msg.sender.transfer(amount);
return true;
}
// ------------------------------------------------------------------------
// Accept ETH
// ------------------------------------------------------------------------
function () external payable {
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ---------------------------------------------------------------------------- | LineComment | allowance | function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
| // ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------ | LineComment | v0.5.4+commit.9549d8ff | bzzr://e2c06dd14b32f6edc44a6bc70367907571ddf8f0139c0ff73700d053cf9f29a3 | {
"func_code_index": [
3897,
4049
]
} | 57,277 |
|
Vicion | Vicion.sol | 0x77c8a119173f0c0656f55954e4ebc1517b32afed | Solidity | Vicion | contract Vicion is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "VIC";
name = "Vicion";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) public returns (bool success){
if(msg.sender != owner)revert();
msg.sender.transfer(amount);
return true;
}
// ------------------------------------------------------------------------
// Accept ETH
// ------------------------------------------------------------------------
function () external payable {
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ---------------------------------------------------------------------------- | LineComment | approveAndCall | function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------ | LineComment | v0.5.4+commit.9549d8ff | bzzr://e2c06dd14b32f6edc44a6bc70367907571ddf8f0139c0ff73700d053cf9f29a3 | {
"func_code_index": [
4412,
4750
]
} | 57,278 |
|
Vicion | Vicion.sol | 0x77c8a119173f0c0656f55954e4ebc1517b32afed | Solidity | Vicion | contract Vicion is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "VIC";
name = "Vicion";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) public returns (bool success){
if(msg.sender != owner)revert();
msg.sender.transfer(amount);
return true;
}
// ------------------------------------------------------------------------
// Accept ETH
// ------------------------------------------------------------------------
function () external payable {
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ---------------------------------------------------------------------------- | LineComment | withdrawEther | function withdrawEther(uint256 amount) public returns (bool success){
if(msg.sender != owner)revert();
msg.sender.transfer(amount);
return true;
}
| // transfer balance to owner | LineComment | v0.5.4+commit.9549d8ff | bzzr://e2c06dd14b32f6edc44a6bc70367907571ddf8f0139c0ff73700d053cf9f29a3 | {
"func_code_index": [
4791,
4956
]
} | 57,279 |
|
Vicion | Vicion.sol | 0x77c8a119173f0c0656f55954e4ebc1517b32afed | Solidity | Vicion | contract Vicion is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "VIC";
name = "Vicion";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) public returns (bool success){
if(msg.sender != owner)revert();
msg.sender.transfer(amount);
return true;
}
// ------------------------------------------------------------------------
// Accept ETH
// ------------------------------------------------------------------------
function () external payable {
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ---------------------------------------------------------------------------- | LineComment | function () external payable {
}
| // ------------------------------------------------------------------------
// Accept ETH
// ------------------------------------------------------------------------ | LineComment | v0.5.4+commit.9549d8ff | bzzr://e2c06dd14b32f6edc44a6bc70367907571ddf8f0139c0ff73700d053cf9f29a3 | {
"func_code_index": [
5143,
5194
]
} | 57,280 |
||
Vicion | Vicion.sol | 0x77c8a119173f0c0656f55954e4ebc1517b32afed | Solidity | Vicion | contract Vicion is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "VIC";
name = "Vicion";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes memory data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) public returns (bool success){
if(msg.sender != owner)revert();
msg.sender.transfer(amount);
return true;
}
// ------------------------------------------------------------------------
// Accept ETH
// ------------------------------------------------------------------------
function () external payable {
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ---------------------------------------------------------------------------- | LineComment | transferAnyERC20Token | function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
| // ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------ | LineComment | v0.5.4+commit.9549d8ff | bzzr://e2c06dd14b32f6edc44a6bc70367907571ddf8f0139c0ff73700d053cf9f29a3 | {
"func_code_index": [
5427,
5616
]
} | 57,281 |
|
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | setTrustedSigner | function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
| /**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
3816,
4069
]
} | 57,282 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | getSatoshiTokenContract | function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
| /**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
4207,
4325
]
} | 57,283 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | getAllotmentPlans | function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
| /**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
4605,
5668
]
} | 57,284 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | isAllotmentPlanValid | function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
| /**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
5821,
5947
]
} | 57,285 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | getAllotmentPlanById | function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
| /**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
6117,
6251
]
} | 57,286 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | _releasableAmount | function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
| /**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
6491,
6665
]
} | 57,287 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | _allottedAmount | function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
| /**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
6857,
7385
]
} | 57,288 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | getAllotmentsByAccount | function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
| /**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
7744,
9515
]
} | 57,289 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | getAllotmentById | function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
| /**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
9734,
10318
]
} | 57,290 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | changeSatoshiTokenContract | function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
| /**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
10515,
10902
]
} | 57,291 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | grantAlloterRole | function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
| /**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
11095,
11337
]
} | 57,292 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | addAllotmentPlan | function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
| /**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
11637,
12337
]
} | 57,293 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | removeAllotmentPlan | function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
| /**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
12543,
12905
]
} | 57,294 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | grantAllotment | function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
| /**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
13477,
14678
]
} | 57,295 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | topUp | function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
| /**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
15115,
16330
]
} | 57,296 |
SatoshiAllotment | contracts/SatoshiAllotment.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SatoshiAllotment | contract SatoshiAllotment is AccessControl, GSNRecipientSignature {
using SafeERC20 for ISatoshiToken;
using SafeMath for uint256;
using SafeMath64 for uint64;
// Alloter role who has permission to allot satoshi tokens
bytes32 public constant ALLOTER_ROLE = keccak256("ALLOTER_ROLE");
// Allotment request details
struct AllotmentRequest {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
}
// Allotment response for get functions
struct AllotmentResponse {
// Id of the allotment
uint64 id;
uint64 start;
uint64 cliff;
uint64 duration;
// Total amount of alloted tokens to be released
uint256 amount;
// Amount Released
uint256 amountReleased;
// Amount available
uint256 amountAvailable;
}
// Allotment plan details
struct AllotmentPlan {
uint64 id;
bool isValid;
uint64 cliffDuration;
uint64 duration;
}
struct TopUpData {
address account;
uint64 id;
uint256 amount;
}
// Satoshi token Contract
ISatoshiToken private _satoshiToken;
// Allotment plans array
AllotmentPlan[] private _allotmentPlans;
// Allotment Requests mapping
mapping(address => AllotmentRequest[]) private _allotmentRequests;
// Event definitions
event TokenContractChanged(address indexed newAddress);
event GrantedAllotment(address indexed account, uint256 id, uint256 amount, uint256 indexed timestamp);
event TopUpAdded(address indexed account, uint256 indexed id, uint256 amount, uint256 indexed timestamp);
event PlanAdded(uint256 indexed id, uint64 cliffDuration, uint64 duration);
event PlanRemoved(uint256 indexed id);
event ReleasedAmount(address indexed account, uint64[] ids, uint256[] amounts, uint256 indexed timestamp);
/**
* @dev Initialize the contract with Satoshi token address,
* cliff and duration for default plan.
*
* @param satoshiToken - Satoshi Token address
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
* @param trustedSigner - Trusted signer for GSN
*/
constructor(
address satoshiToken,
uint64 cliffDuration,
uint64 duration,
address trustedSigner
) public GSNRecipientSignature(trustedSigner) {
require(satoshiToken != address(0), "SatoshiAllotment: token is zero address");
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(ALLOTER_ROLE, _msgSender());
// Set Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(satoshiToken);
// Add allotment plan
_allotmentPlans.push(AllotmentPlan({
id: 0,
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(_allotmentPlans.length.sub(1), cliffDuration, duration);
}
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*
* @param trustedSigner - Address of the trusted signer for GSN
*
* Requirements:
*
* - the caller must have the `DEFAULT_ADMIN_ROLE`
*/
function setTrustedSigner(address trustedSigner) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiToken: must have admin role to change trustedSigner");
super.setTrustedSigner(trustedSigner);
}
/**
* @dev Get Satoshi token contract address.
*
* @return account - Address of Satoshi Token contract
*/
function getSatoshiTokenContract() public view returns (address) {
return address(_satoshiToken);
}
/**
* @dev Get allotment plans
*
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentPlan[] - Allotment plan array
* uint256 - Count of responses
*/
function getAllotmentPlans(
uint256 cursor,
uint256 maxLength) public view returns (AllotmentPlan[] memory, uint256){
uint256 length = maxLength;
if (length > _allotmentPlans.length)
length = _allotmentPlans.length;
AllotmentPlan[] memory responses = new AllotmentPlan[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < _allotmentPlans.length; i++) {
AllotmentPlan memory plan = _allotmentPlans[i];
if (true == plan.isValid) {
// Fill response
responses[idCounter].id = plan.id;
responses[idCounter].isValid = plan.isValid;
responses[idCounter].cliffDuration = plan.cliffDuration;
responses[idCounter].duration = plan.duration;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Is allotment plan valid
*
* @param id - Allotment plan ID
*
* @return bool - Plan valid or not
*/
function isAllotmentPlanValid(uint64 id) public view returns (bool) {
return _allotmentPlans[id].isValid;
}
/**
* @dev Get allotment plan details for an ID
*
* @param id - Allotment plan ID
*
* @return AllotmentPlan - Plan details
*/
function getAllotmentPlanById(uint64 id) public view returns (AllotmentPlan memory) {
return _allotmentPlans[id];
}
/**
* @dev Calculates the releasable amount that has already vested but
* hasn't been released yet.
*
* @param request - Allotment request details
*
* @return uint256 - releasable amount
*/
function _releasableAmount(AllotmentRequest memory request) private view returns (uint256) {
return _allottedAmount(request).sub(request.amountReleased);
}
/**
* @dev Calculates the amount that has already allotted.
*
* @param request - Allotment request details
*
* @return uint256 - allotted amount
*/
function _allottedAmount(AllotmentRequest memory request) private view returns (uint256) {
uint256 totalBalance = request.amount;
if (block.timestamp < request.cliff) {
return 0;
} else if (block.timestamp >= (request.start.add(request.duration))) {
return totalBalance;
} else {
uint256 timeDiff = block.timestamp.sub((uint256)(request.start));
return totalBalance.mul(timeDiff).div((uint256)(request.duration));
}
}
/**
* @dev Get allotment details per account
*
* @param account - Address of the user
* @param cursor - Cursor index to start
* @param maxLength - Max length of allotments to retrieve
*
* @return AllotmentResponse[] - Allotment details array of the user
* uint256 - Count of allotments
*/
function getAllotmentsByAccount(
address account,
uint256 cursor,
uint256 maxLength,
bool includeUpcoming,
bool includeAll) public view returns (AllotmentResponse[] memory, uint256){
AllotmentRequest[] memory requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 length = maxLength;
if (length > allotmentLen)
length = allotmentLen;
AllotmentResponse[] memory responses = new AllotmentResponse[](length);
uint256 idCounter = 0;
for (uint256 i = cursor; i < allotmentLen; i++) {
uint256 releasableAmount;
AllotmentRequest memory request = requests[i];
if (block.timestamp >= request.cliff) {
releasableAmount = _releasableAmount(request);
}
if ((releasableAmount > 0) ||
((true == includeUpcoming) && (block.timestamp < request.cliff)) ||
(true == includeAll)) {
// Fill response
responses[idCounter].id = request.id;
responses[idCounter].amount = request.amount;
responses[idCounter].start = request.start;
responses[idCounter].cliff = request.cliff;
responses[idCounter].duration = request.duration;
responses[idCounter].amountReleased = request.amountReleased;
responses[idCounter].amountAvailable = releasableAmount;
idCounter++;
// Check for requested length
if (idCounter >= length)
break;
}
}
return (responses, idCounter);
}
/**
* @dev Get allotment details by ID
*
* @param account - Address of the user
* @param id - Allotment ID
*
* @return AllotmentResponse - Details of an allotment ID
*/
function getAllotmentById(address account, uint64 id) public view returns (AllotmentResponse memory) {
AllotmentRequest memory request = _allotmentRequests[account][id];
uint256 releasableAmount = _releasableAmount(request);
return (AllotmentResponse({
id: request.id,
amount: request.amount,
start: request.start,
cliff: request.cliff,
duration: request.duration,
amountReleased: request.amountReleased,
amountAvailable: releasableAmount
}));
}
/**
* @dev Change the Satoshi Token contract
*
* @param newAddress New Address of the token
* Requirements:
*
* - the caller must have the admin role.
*/
function changeSatoshiTokenContract(address newAddress) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to change satoshi token contract"
);
// Change Satoshi ERC20 token Contract
_satoshiToken = ISatoshiToken(newAddress);
emit TokenContractChanged(newAddress);
}
/**
* @dev Grant alloter role.
* @param account - Address of the alloter to be granted
* Requirements:
*
* - the caller must have the admin role.
*/
function grantAlloterRole(address account) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: sender must be an admin to grant");
super.grantRole(ALLOTER_ROLE, account);
}
/**
* @dev Add an allotment plan.
*
* @param cliffDuration - Additional cliff after the allotment start date
* @param duration - Duration of the allotment, i.e. say 100 days
*
* Requirements:
*
* - the caller must have the admin role.
*/
function addAllotmentPlan(uint64 cliffDuration, uint64 duration) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to add plan"
);
require(cliffDuration <= duration, "SatoshiAllotment: cliff is longer than duration");
require(duration > 0, "SatoshiAllotment: duration is 0");
uint256 length = _allotmentPlans.length;
_allotmentPlans.push(AllotmentPlan({
id: (uint64)(length),
isValid: true,
cliffDuration: cliffDuration,
duration: duration
}));
emit PlanAdded(length, cliffDuration, duration);
}
/**
* @dev Remove an existing allotment plan.
*
* @param id - Pland ID to be removed.
*
* Requirements:
*
* - the caller must have the admin role.
*/
function removeAllotmentPlan(uint256 id) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"SatoshiAllotment: must have admin role to remove plan"
);
require(_allotmentPlans[id].isValid == true, "SatoshiAllotment: deleted plan");
delete(_allotmentPlans[id]);
emit PlanRemoved(id);
}
/**
* @dev Grant an allotment to user.
*
* @param account - Address of user to be allotted
* @param start - Start timestamp of the allotment
* @param planId - Allotment plan ID.
*
* @return (uint64) - ID of the allotment
*
* Requirements:
*
* - the caller must have the alloter role.
* - account cannot be zero address
* - start time should be greater than or equal to block timestamp
* - plan id should be a valid plan
* - max id limit shouldn't have been reached
*/
function grantAllotment(address account,
uint256 amount,
uint64 start,
uint256 planId) external returns (uint64) {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to allot tokens"
);
require(account != address(0), "SatoshiAllotment: account is zero address");
require(start >= block.timestamp, "SatoshiAllotment: start < now");
// Get allotment plan details, verify the same
AllotmentPlan memory plan = _allotmentPlans[planId];
require(plan.isValid == true, "SatoshiAllotment: deleted plan");
uint256 id = _allotmentRequests[account].length;
require(id < (uint256)(~uint64(0)), "SatoshiAllotment: Max allotment IDs reached");
_allotmentRequests[account].push(AllotmentRequest({
id: (uint64)(id),
start: start,
cliff: start.add(plan.cliffDuration),
duration: plan.duration,
amount: amount,
amountReleased: 0
}));
emit GrantedAllotment(account, (uint64)(id), amount, block.timestamp);
return (uint64)(id);
}
/**
* @dev Topup existing allotments.
*
* @param accounts[] - Address of user to be allotted
* @param ids[] - Allotment ID
* @param amounts[] - Amount to be topped-up
*
* Requirements:
*
* - the caller must have the alloter role
* - length of accounts, ids, amounts should be same
* - accounts cannot be zero address
* - allotments should be valid
*/
function topUp(address[] calldata accounts, uint64[] calldata ids, uint256[] calldata amounts) external {
require(hasRole(ALLOTER_ROLE, _msgSender()),
"SatoshiAllotment: must have alloter role to topup allotment tokens"
);
require(accounts.length == ids.length, "SatoshiAllotment: accounts length doesn't match with ids length");
require(ids.length == amounts.length, "SatoshiAllotment: ids length doesn't match with amounts length");
for (uint256 i = 0; i < accounts.length; i++) {
require(accounts[i] != address(0), "SatoshiAllotment: account is zero address");
require(amounts[i] > 0, "SatoshiAllotment: amount is zero");
AllotmentRequest storage requestPointer = _allotmentRequests[accounts[i]][ids[i]];
// Check for validity of the allotment
require(requestPointer.start.add(requestPointer.duration) > block.timestamp, "SatoshiAllotment: allotment has expired");
// Add the topup amount to the existing amount
requestPointer.amount += amounts[i];
emit TopUpAdded(accounts[i], ids[i], amounts[i], block.timestamp);
}
}
/**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/
function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
} | /**
* @dev This contract handles allotment of Satoshi Token either thru direct buying
* or approved grants from platform
*/ | NatSpecMultiLine | release | function release(address account, uint64[] calldata ids) external {
require(account != address(0), "SatoshiAllotment: account is zero address");
require(ids.length > 0, "SatoshiAllotment: Ids are empty");
uint256 amountToBeReleased = 0;
uint256 totalAmountToBeReleased = 0;
// Access the allotments of an account
AllotmentRequest[] storage requests = _allotmentRequests[account];
uint256 allotmentLen = requests.length;
uint256 maxLength = ids.length;
// Amounts released as part of Response
uint256[] memory amountsReleased = new uint256[](maxLength);
if (maxLength > allotmentLen)
maxLength = allotmentLen;
for (uint256 i = 0; i < maxLength; i++) {
// Verify whether id is within max allotments
require (ids[i] < allotmentLen, "SatoshiAllotment: invalid allotment id");
// Get request storage pointer to update the amount released
AllotmentRequest storage requestPointer = requests[ids[i]];
// Copy the content of allotment request into memory to save gas
AllotmentRequest memory request = requests[ids[i]];
if (block.timestamp >= request.cliff) {
amountToBeReleased = _releasableAmount(request);
totalAmountToBeReleased = totalAmountToBeReleased.add(amountToBeReleased);
amountsReleased[i] = amountToBeReleased;
// Delete when allotment is completed
if ((request.amountReleased.add(amountToBeReleased)) >= request.amount)
delete(requests[ids[i]]);
else // Update released amount
requestPointer.amountReleased = request.amountReleased.add(amountToBeReleased);
}
}
// Mint Satoshi for the account address
if (totalAmountToBeReleased > 0)
_satoshiToken.mint(account, totalAmountToBeReleased);
emit ReleasedAmount(account, ids, amountsReleased, block.timestamp);
}
| /**
* @dev Release available tokens from requested allotment ids
*
* @param account - Address of the allottee
* @param ids - Array of allotment ids
*
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
16527,
18644
]
} | 57,297 |
RoyalStables | ..\openzeppelin-solidity\contracts\AddressUtils.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | AddressUtils | library AddressUtils {
/**
* Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
* @param _account address of the account to check
* @return whether the target address is a contract
*/
function isContract(address _account) internal view returns (bool) {
uint256 size;
// XXX Currently there is no better way to check if there is a contract in an address
// than to check the size of the code at that address.
// See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be
// contracts then.
// solium-disable-next-line security/no-inline-assembly
assembly { size := extcodesize(_account) }
return size > 0;
}
} | /**
* Utility library of inline functions on addresses
*/ | NatSpecMultiLine | isContract | function isContract(address _account) internal view returns (bool) {
uint256 size;
// XXX Currently there is no better way to check if there is a contract in an address
// than to check the size of the code at that address.
// See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be
// contracts then.
// solium-disable-next-line security/no-inline-assembly
assembly { size := extcodesize(_account) }
return size > 0;
}
| /**
* Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
* @param _account address of the account to check
* @return whether the target address is a contract
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
376,
974
]
} | 57,298 |
|
LeapCoin | LeapCoin.sol | 0x8b392bec1eb2df9daea83110a1397a0d86c736f6 | Solidity | LeapCoin | contract LeapCoin is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function LeapCoin() public {
symbol = "LEAC";
name = "LEAC";
decimals = 18;
_totalSupply = 5000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function increaseApproval (address _spender, uint _addedValue) public
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | LeapCoin | function LeapCoin() public {
symbol = "LEAC";
name = "LEAC";
decimals = 18;
_totalSupply = 5000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
| // ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------ | LineComment | v0.4.21+commit.dfe3193c | bzzr://b3170cb35311884e73e279868e68ede4c8bde44032421b911823989293a1532a | {
"func_code_index": [
477,
746
]
} | 57,299 |
|
LeapCoin | LeapCoin.sol | 0x8b392bec1eb2df9daea83110a1397a0d86c736f6 | Solidity | LeapCoin | contract LeapCoin is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function LeapCoin() public {
symbol = "LEAC";
name = "LEAC";
decimals = 18;
_totalSupply = 5000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function increaseApproval (address _spender, uint _addedValue) public
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | totalSupply | function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
| // ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------ | LineComment | v0.4.21+commit.dfe3193c | bzzr://b3170cb35311884e73e279868e68ede4c8bde44032421b911823989293a1532a | {
"func_code_index": [
934,
1055
]
} | 57,300 |
|
LeapCoin | LeapCoin.sol | 0x8b392bec1eb2df9daea83110a1397a0d86c736f6 | Solidity | LeapCoin | contract LeapCoin is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function LeapCoin() public {
symbol = "LEAC";
name = "LEAC";
decimals = 18;
_totalSupply = 5000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function increaseApproval (address _spender, uint _addedValue) public
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | balanceOf | function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
| // ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------ | LineComment | v0.4.21+commit.dfe3193c | bzzr://b3170cb35311884e73e279868e68ede4c8bde44032421b911823989293a1532a | {
"func_code_index": [
1275,
1404
]
} | 57,301 |
|
LeapCoin | LeapCoin.sol | 0x8b392bec1eb2df9daea83110a1397a0d86c736f6 | Solidity | LeapCoin | contract LeapCoin is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function LeapCoin() public {
symbol = "LEAC";
name = "LEAC";
decimals = 18;
_totalSupply = 5000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function increaseApproval (address _spender, uint _addedValue) public
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | transfer | function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.4.21+commit.dfe3193c | bzzr://b3170cb35311884e73e279868e68ede4c8bde44032421b911823989293a1532a | {
"func_code_index": [
1750,
2022
]
} | 57,302 |
|
LeapCoin | LeapCoin.sol | 0x8b392bec1eb2df9daea83110a1397a0d86c736f6 | Solidity | LeapCoin | contract LeapCoin is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function LeapCoin() public {
symbol = "LEAC";
name = "LEAC";
decimals = 18;
_totalSupply = 5000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function increaseApproval (address _spender, uint _addedValue) public
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | approve | function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------ | LineComment | v0.4.21+commit.dfe3193c | bzzr://b3170cb35311884e73e279868e68ede4c8bde44032421b911823989293a1532a | {
"func_code_index": [
2534,
2747
]
} | 57,303 |
|
LeapCoin | LeapCoin.sol | 0x8b392bec1eb2df9daea83110a1397a0d86c736f6 | Solidity | LeapCoin | contract LeapCoin is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function LeapCoin() public {
symbol = "LEAC";
name = "LEAC";
decimals = 18;
_totalSupply = 5000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function increaseApproval (address _spender, uint _addedValue) public
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | transferFrom | function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.4.21+commit.dfe3193c | bzzr://b3170cb35311884e73e279868e68ede4c8bde44032421b911823989293a1532a | {
"func_code_index": [
3286,
3634
]
} | 57,304 |
|
LeapCoin | LeapCoin.sol | 0x8b392bec1eb2df9daea83110a1397a0d86c736f6 | Solidity | LeapCoin | contract LeapCoin is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function LeapCoin() public {
symbol = "LEAC";
name = "LEAC";
decimals = 18;
_totalSupply = 5000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function increaseApproval (address _spender, uint _addedValue) public
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | allowance | function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
| // ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------ | LineComment | v0.4.21+commit.dfe3193c | bzzr://b3170cb35311884e73e279868e68ede4c8bde44032421b911823989293a1532a | {
"func_code_index": [
3917,
4073
]
} | 57,305 |
|
LeapCoin | LeapCoin.sol | 0x8b392bec1eb2df9daea83110a1397a0d86c736f6 | Solidity | LeapCoin | contract LeapCoin is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function LeapCoin() public {
symbol = "LEAC";
name = "LEAC";
decimals = 18;
_totalSupply = 5000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function increaseApproval (address _spender, uint _addedValue) public
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | approveAndCall | function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------ | LineComment | v0.4.21+commit.dfe3193c | bzzr://b3170cb35311884e73e279868e68ede4c8bde44032421b911823989293a1532a | {
"func_code_index": [
5168,
5490
]
} | 57,306 |
|
LeapCoin | LeapCoin.sol | 0x8b392bec1eb2df9daea83110a1397a0d86c736f6 | Solidity | LeapCoin | contract LeapCoin is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function LeapCoin() public {
symbol = "LEAC";
name = "LEAC";
decimals = 18;
_totalSupply = 5000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function increaseApproval (address _spender, uint _addedValue) public
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | function () public payable {
revert();
}
| // ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------ | LineComment | v0.4.21+commit.dfe3193c | bzzr://b3170cb35311884e73e279868e68ede4c8bde44032421b911823989293a1532a | {
"func_code_index": [
5682,
5741
]
} | 57,307 |
||
LeapCoin | LeapCoin.sol | 0x8b392bec1eb2df9daea83110a1397a0d86c736f6 | Solidity | LeapCoin | contract LeapCoin is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function LeapCoin() public {
symbol = "LEAC";
name = "LEAC";
decimals = 18;
_totalSupply = 5000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
function increaseApproval (address _spender, uint _addedValue) public
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | transferAnyERC20Token | function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
| // ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------ | LineComment | v0.4.21+commit.dfe3193c | bzzr://b3170cb35311884e73e279868e68ede4c8bde44032421b911823989293a1532a | {
"func_code_index": [
5974,
6163
]
} | 57,308 |
|
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
constructor () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) private allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
| /**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
421,
534
]
} | 57,309 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
constructor () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) private allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
| /**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
951,
1370
]
} | 57,310 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
constructor () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) private allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
| /**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
1867,
2436
]
} | 57,311 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
constructor () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) private allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | approve | function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
| /**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
2764,
2974
]
} | 57,312 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
constructor () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) private allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | allowance | function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
| /**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
3422,
3570
]
} | 57,313 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
| /**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
934,
1027
]
} | 57,314 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
f (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
| /**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
1500,
1711
]
} | 57,315 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
equire(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
| /**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
2107,
2348
]
} | 57,316 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | approve | function approve (address _spender, uint256 _value) public
returns (bool success) {
equire(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
| /**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
3034,
3249
]
} | 57,317 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | createTokens | function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
| /**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
3515,
4033
]
} | 57,318 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | mintToken | function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
| /**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
4388,
4861
]
} | 57,319 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | burn | function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
| /**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
5072,
5435
]
} | 57,320 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | setOwner | function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
| /**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
5626,
5741
]
} | 57,321 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | freezeTransfers | function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
| /**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
5842,
5996
]
} | 57,322 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | unfreezeTransfers | function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
| /**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
6099,
6257
]
} | 57,323 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | refundTokens | function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
| /**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
6683,
6982
]
} | 57,324 |
DRCG | DRCG.sol | 0xd140bd1e843f08c254f7eb8c75133bdfa22d3716 | Solidity | DRCG | contract DRCG is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 100000000 * (10**18);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "Democratic Republic of Congo Gold Token";
string constant public symbol = "DRCG";
uint8 constant public decimals = 18;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* For future use only whne we will need more tokens for our main application
* Create mintedAmount new tokens and give new created tokens to target.
* May only be called by smart contract owner.
* @param mintedAmount number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function mintToken(address target, uint256 mintedAmount) public
returns (bool success) {
require (msg.sender == owner);
if (mintedAmount > 0) {
accounts [target] = safeAdd (accounts [target], mintedAmount);
tokenCount = safeAdd (tokenCount, mintedAmount);
// adding transfer event and _from address as null address
emit Transfer(address(0), target, mintedAmount);
return true;
}
return false;
}
/**
* Burn intended tokens.
* Only be called by by burnable addresses.
*
* @param _value number of tokens to burn
* @return true if burnt successfully, false otherwise
*/
function burn(uint256 _value) public returns (bool success) {
require(accounts[msg.sender] >= _value);
require (msg.sender == owner);
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
tokenCount = safeSub (tokenCount, _value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/**
* A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* Logged when a token is burnt.
*/
event Burn(address target,uint256 _value);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* DRCG smart contract.
*/ | NatSpecMultiLine | freezeAccount | function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
| /**
* Freeze specific account
* May only be called by smart contract owner.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | MIT | bzzr://27957e9f5875ebb664cff8d331a5f4b47c134d3f209374f558db54683e9161e0 | {
"func_code_index": [
7081,
7306
]
} | 57,325 |
SushiRoll | contracts/SushiRoll.sol | 0x14b2075e6d5993ae10df843f9979296f4b6100c6 | Solidity | SushiRoll | contract SushiRoll {
using SafeERC20 for IERC20;
IUniswapV2Router01 public oldRouter;
IUniswapV2Router01 public router;
constructor(IUniswapV2Router01 _oldRouter, IUniswapV2Router01 _router) public {
oldRouter = _oldRouter;
router = _router;
}
// msg.sender should have approved 'liquidity' amount of LP token of 'tokenA' and 'tokenB'
function migrate(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external {
require(deadline >= block.timestamp, 'SushiSwap: EXPIRED');
// Remove liquidity from the old router with permit
(uint256 amountA, uint256 amountB) = removeLiquidity(
tokenA,
tokenB,
liquidity,
amountAMin,
amountBMin,
deadline,
v,
r,
s
);
// Add liquidity to the new router
(uint256 pooledAmountA, uint256 pooledAmountB) = addLiquidity(tokenA, tokenB, amountA, amountB);
// Send remaining tokens to msg.sender
if (amountA > pooledAmountA) {
IERC20(tokenA).safeTransfer(msg.sender, amountA - pooledAmountA);
}
if (amountB > pooledAmountB) {
IERC20(tokenB).safeTransfer(msg.sender, amountB - pooledAmountB);
}
}
function removeLiquidity(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal returns (uint256 amountA, uint256 amountB) {
IUniswapV2Pair pair = IUniswapV2Pair(pairForOldRouter(tokenA, tokenB));
pair.permit(msg.sender, address(this), liquidity, deadline, v, r, s);
// Send liquidity to pair
pair.transferFrom(msg.sender, address(pair), liquidity);
(uint256 amount0, uint256 amount1) = pair.burn(address(this));
(address token0,) = UniswapV2Library.sortTokens(tokenA, tokenB);
(amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0);
require(amountA >= amountAMin, 'SushiRoll: INSUFFICIENT_A_AMOUNT');
require(amountB >= amountBMin, 'SushiRoll: INSUFFICIENT_B_AMOUNT');
}
// calculates the CREATE2 address for a pair without making any external calls
function pairForOldRouter(address tokenA, address tokenB) internal view returns (address pair) {
(address token0, address token1) = UniswapV2Library.sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
oldRouter.factory(),
keccak256(abi.encodePacked(token0, token1)),
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
))));
}
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired
) internal returns (uint amountA, uint amountB) {
(amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired);
address pair = UniswapV2Library.pairFor(router.factory(), tokenA, tokenB);
IERC20(tokenA).safeTransfer(pair, amountA);
IERC20(tokenB).safeTransfer(pair, amountB);
IUniswapV2Pair(pair).mint(msg.sender);
}
function _addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired
) internal returns (uint256 amountA, uint256 amountB) {
// create the pair if it doesn't exist yet
IUniswapV2Factory factory = IUniswapV2Factory(router.factory());
if (factory.getPair(tokenA, tokenB) == address(0)) {
factory.createPair(tokenA, tokenB);
}
(uint256 reserveA, uint256 reserveB) = UniswapV2Library.getReserves(address(factory), tokenA, tokenB);
if (reserveA == 0 && reserveB == 0) {
(amountA, amountB) = (amountADesired, amountBDesired);
} else {
uint256 amountBOptimal = UniswapV2Library.quote(amountADesired, reserveA, reserveB);
if (amountBOptimal <= amountBDesired) {
(amountA, amountB) = (amountADesired, amountBOptimal);
} else {
uint256 amountAOptimal = UniswapV2Library.quote(amountBDesired, reserveB, reserveA);
assert(amountAOptimal <= amountADesired);
(amountA, amountB) = (amountAOptimal, amountBDesired);
}
}
}
} | migrate | function migrate(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external {
require(deadline >= block.timestamp, 'SushiSwap: EXPIRED');
// Remove liquidity from the old router with permit
(uint256 amountA, uint256 amountB) = removeLiquidity(
tokenA,
tokenB,
liquidity,
amountAMin,
amountBMin,
deadline,
v,
r,
s
);
// Add liquidity to the new router
(uint256 pooledAmountA, uint256 pooledAmountB) = addLiquidity(tokenA, tokenB, amountA, amountB);
// Send remaining tokens to msg.sender
if (amountA > pooledAmountA) {
IERC20(tokenA).safeTransfer(msg.sender, amountA - pooledAmountA);
}
if (amountB > pooledAmountB) {
IERC20(tokenB).safeTransfer(msg.sender, amountB - pooledAmountB);
}
}
| // msg.sender should have approved 'liquidity' amount of LP token of 'tokenA' and 'tokenB' | LineComment | v0.6.12+commit.27d51765 | MIT | ipfs://8242fcdb6c4aa9f9014a3bcb08a5b2ee5e65007494746fdaf0012eeb38fe44af | {
"func_code_index": [
390,
1512
]
} | 57,326 |
||
SushiRoll | contracts/SushiRoll.sol | 0x14b2075e6d5993ae10df843f9979296f4b6100c6 | Solidity | SushiRoll | contract SushiRoll {
using SafeERC20 for IERC20;
IUniswapV2Router01 public oldRouter;
IUniswapV2Router01 public router;
constructor(IUniswapV2Router01 _oldRouter, IUniswapV2Router01 _router) public {
oldRouter = _oldRouter;
router = _router;
}
// msg.sender should have approved 'liquidity' amount of LP token of 'tokenA' and 'tokenB'
function migrate(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external {
require(deadline >= block.timestamp, 'SushiSwap: EXPIRED');
// Remove liquidity from the old router with permit
(uint256 amountA, uint256 amountB) = removeLiquidity(
tokenA,
tokenB,
liquidity,
amountAMin,
amountBMin,
deadline,
v,
r,
s
);
// Add liquidity to the new router
(uint256 pooledAmountA, uint256 pooledAmountB) = addLiquidity(tokenA, tokenB, amountA, amountB);
// Send remaining tokens to msg.sender
if (amountA > pooledAmountA) {
IERC20(tokenA).safeTransfer(msg.sender, amountA - pooledAmountA);
}
if (amountB > pooledAmountB) {
IERC20(tokenB).safeTransfer(msg.sender, amountB - pooledAmountB);
}
}
function removeLiquidity(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal returns (uint256 amountA, uint256 amountB) {
IUniswapV2Pair pair = IUniswapV2Pair(pairForOldRouter(tokenA, tokenB));
pair.permit(msg.sender, address(this), liquidity, deadline, v, r, s);
// Send liquidity to pair
pair.transferFrom(msg.sender, address(pair), liquidity);
(uint256 amount0, uint256 amount1) = pair.burn(address(this));
(address token0,) = UniswapV2Library.sortTokens(tokenA, tokenB);
(amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0);
require(amountA >= amountAMin, 'SushiRoll: INSUFFICIENT_A_AMOUNT');
require(amountB >= amountBMin, 'SushiRoll: INSUFFICIENT_B_AMOUNT');
}
// calculates the CREATE2 address for a pair without making any external calls
function pairForOldRouter(address tokenA, address tokenB) internal view returns (address pair) {
(address token0, address token1) = UniswapV2Library.sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
oldRouter.factory(),
keccak256(abi.encodePacked(token0, token1)),
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
))));
}
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired
) internal returns (uint amountA, uint amountB) {
(amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired);
address pair = UniswapV2Library.pairFor(router.factory(), tokenA, tokenB);
IERC20(tokenA).safeTransfer(pair, amountA);
IERC20(tokenB).safeTransfer(pair, amountB);
IUniswapV2Pair(pair).mint(msg.sender);
}
function _addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired
) internal returns (uint256 amountA, uint256 amountB) {
// create the pair if it doesn't exist yet
IUniswapV2Factory factory = IUniswapV2Factory(router.factory());
if (factory.getPair(tokenA, tokenB) == address(0)) {
factory.createPair(tokenA, tokenB);
}
(uint256 reserveA, uint256 reserveB) = UniswapV2Library.getReserves(address(factory), tokenA, tokenB);
if (reserveA == 0 && reserveB == 0) {
(amountA, amountB) = (amountADesired, amountBDesired);
} else {
uint256 amountBOptimal = UniswapV2Library.quote(amountADesired, reserveA, reserveB);
if (amountBOptimal <= amountBDesired) {
(amountA, amountB) = (amountADesired, amountBOptimal);
} else {
uint256 amountAOptimal = UniswapV2Library.quote(amountBDesired, reserveB, reserveA);
assert(amountAOptimal <= amountADesired);
(amountA, amountB) = (amountAOptimal, amountBDesired);
}
}
}
} | pairForOldRouter | function pairForOldRouter(address tokenA, address tokenB) internal view returns (address pair) {
(address token0, address token1) = UniswapV2Library.sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
oldRouter.factory(),
keccak256(abi.encodePacked(token0, token1)),
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
))));
}
| // calculates the CREATE2 address for a pair without making any external calls | LineComment | v0.6.12+commit.27d51765 | MIT | ipfs://8242fcdb6c4aa9f9014a3bcb08a5b2ee5e65007494746fdaf0012eeb38fe44af | {
"func_code_index": [
2571,
3075
]
} | 57,327 |
||
WhatsAroundToken | WhatsAroundToken.sol | 0x7496c9c70125db7070ade91f2e118e8dd1d058cb | Solidity | WhatsAroundToken | contract WhatsAroundToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "WAT";
name = "WhatsAround Token";
decimals = 8;
_totalSupply = 5000000000000000;
balances[0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772] = _totalSupply;
emit Transfer(address(0), 0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | totalSupply | function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
| // ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------ | LineComment | v0.4.25+commit.59dbf8f1 | None | bzzr://79d8d02601bc642449600a5c8ac9e78d267f87ae918b3016b12603985e35cc5f | {
"func_code_index": [
984,
1105
]
} | 57,328 |
WhatsAroundToken | WhatsAroundToken.sol | 0x7496c9c70125db7070ade91f2e118e8dd1d058cb | Solidity | WhatsAroundToken | contract WhatsAroundToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "WAT";
name = "WhatsAround Token";
decimals = 8;
_totalSupply = 5000000000000000;
balances[0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772] = _totalSupply;
emit Transfer(address(0), 0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | balanceOf | function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
| // ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------ | LineComment | v0.4.25+commit.59dbf8f1 | None | bzzr://79d8d02601bc642449600a5c8ac9e78d267f87ae918b3016b12603985e35cc5f | {
"func_code_index": [
1325,
1454
]
} | 57,329 |
WhatsAroundToken | WhatsAroundToken.sol | 0x7496c9c70125db7070ade91f2e118e8dd1d058cb | Solidity | WhatsAroundToken | contract WhatsAroundToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "WAT";
name = "WhatsAround Token";
decimals = 8;
_totalSupply = 5000000000000000;
balances[0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772] = _totalSupply;
emit Transfer(address(0), 0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | transfer | function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.4.25+commit.59dbf8f1 | None | bzzr://79d8d02601bc642449600a5c8ac9e78d267f87ae918b3016b12603985e35cc5f | {
"func_code_index": [
1798,
2080
]
} | 57,330 |
WhatsAroundToken | WhatsAroundToken.sol | 0x7496c9c70125db7070ade91f2e118e8dd1d058cb | Solidity | WhatsAroundToken | contract WhatsAroundToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "WAT";
name = "WhatsAround Token";
decimals = 8;
_totalSupply = 5000000000000000;
balances[0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772] = _totalSupply;
emit Transfer(address(0), 0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | approve | function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------ | LineComment | v0.4.25+commit.59dbf8f1 | None | bzzr://79d8d02601bc642449600a5c8ac9e78d267f87ae918b3016b12603985e35cc5f | {
"func_code_index": [
2588,
2801
]
} | 57,331 |
WhatsAroundToken | WhatsAroundToken.sol | 0x7496c9c70125db7070ade91f2e118e8dd1d058cb | Solidity | WhatsAroundToken | contract WhatsAroundToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "WAT";
name = "WhatsAround Token";
decimals = 8;
_totalSupply = 5000000000000000;
balances[0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772] = _totalSupply;
emit Transfer(address(0), 0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | transferFrom | function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.4.25+commit.59dbf8f1 | None | bzzr://79d8d02601bc642449600a5c8ac9e78d267f87ae918b3016b12603985e35cc5f | {
"func_code_index": [
3332,
3695
]
} | 57,332 |
WhatsAroundToken | WhatsAroundToken.sol | 0x7496c9c70125db7070ade91f2e118e8dd1d058cb | Solidity | WhatsAroundToken | contract WhatsAroundToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "WAT";
name = "WhatsAround Token";
decimals = 8;
_totalSupply = 5000000000000000;
balances[0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772] = _totalSupply;
emit Transfer(address(0), 0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | allowance | function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
| // ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------ | LineComment | v0.4.25+commit.59dbf8f1 | None | bzzr://79d8d02601bc642449600a5c8ac9e78d267f87ae918b3016b12603985e35cc5f | {
"func_code_index": [
3978,
4134
]
} | 57,333 |
WhatsAroundToken | WhatsAroundToken.sol | 0x7496c9c70125db7070ade91f2e118e8dd1d058cb | Solidity | WhatsAroundToken | contract WhatsAroundToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "WAT";
name = "WhatsAround Token";
decimals = 8;
_totalSupply = 5000000000000000;
balances[0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772] = _totalSupply;
emit Transfer(address(0), 0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | approveAndCall | function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------ | LineComment | v0.4.25+commit.59dbf8f1 | None | bzzr://79d8d02601bc642449600a5c8ac9e78d267f87ae918b3016b12603985e35cc5f | {
"func_code_index": [
4489,
4811
]
} | 57,334 |
WhatsAroundToken | WhatsAroundToken.sol | 0x7496c9c70125db7070ade91f2e118e8dd1d058cb | Solidity | WhatsAroundToken | contract WhatsAroundToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "WAT";
name = "WhatsAround Token";
decimals = 8;
_totalSupply = 5000000000000000;
balances[0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772] = _totalSupply;
emit Transfer(address(0), 0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | function () public payable {
revert();
}
| // ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------ | LineComment | v0.4.25+commit.59dbf8f1 | None | bzzr://79d8d02601bc642449600a5c8ac9e78d267f87ae918b3016b12603985e35cc5f | {
"func_code_index": [
5003,
5062
]
} | 57,335 |
|
WhatsAroundToken | WhatsAroundToken.sol | 0x7496c9c70125db7070ade91f2e118e8dd1d058cb | Solidity | WhatsAroundToken | contract WhatsAroundToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "WAT";
name = "WhatsAround Token";
decimals = 8;
_totalSupply = 5000000000000000;
balances[0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772] = _totalSupply;
emit Transfer(address(0), 0xAd1B9D05825b3BA8A26096BA9bfCE09668CF7772, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ---------------------------------------------------------------------------- | LineComment | transferAnyERC20Token | function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
| // ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------ | LineComment | v0.4.25+commit.59dbf8f1 | None | bzzr://79d8d02601bc642449600a5c8ac9e78d267f87ae918b3016b12603985e35cc5f | {
"func_code_index": [
5295,
5484
]
} | 57,336 |
RoyalStables | ..\openzeppelin-solidity\contracts\token\ERC721\ERC721Token.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | ERC721Token | contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
/**
* @dev Constructor function
*/
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return name_;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return symbol_;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
/**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
/**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
} | /**
* @title Full ERC721 Token
* This implementation includes all the required and some optional functionality of the ERC721 standard
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ | NatSpecMultiLine | name | function name() external view returns (string) {
return name_;
}
| /**
* @dev Gets the token name
* @return string representing the token name
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
1136,
1211
]
} | 57,337 |
|
RoyalStables | ..\openzeppelin-solidity\contracts\token\ERC721\ERC721Token.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | ERC721Token | contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
/**
* @dev Constructor function
*/
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return name_;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return symbol_;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
/**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
/**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
} | /**
* @title Full ERC721 Token
* This implementation includes all the required and some optional functionality of the ERC721 standard
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ | NatSpecMultiLine | symbol | function symbol() external view returns (string) {
return symbol_;
}
| /**
* @dev Gets the token symbol
* @return string representing the token symbol
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
1312,
1391
]
} | 57,338 |
|
RoyalStables | ..\openzeppelin-solidity\contracts\token\ERC721\ERC721Token.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | ERC721Token | contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
/**
* @dev Constructor function
*/
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return name_;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return symbol_;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
/**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
/**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
} | /**
* @title Full ERC721 Token
* This implementation includes all the required and some optional functionality of the ERC721 standard
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ | NatSpecMultiLine | tokenURI | function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
| /**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
1583,
1723
]
} | 57,339 |
|
RoyalStables | ..\openzeppelin-solidity\contracts\token\ERC721\ERC721Token.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | ERC721Token | contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
/**
* @dev Constructor function
*/
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return name_;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return symbol_;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
/**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
/**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
} | /**
* @title Full ERC721 Token
* This implementation includes all the required and some optional functionality of the ERC721 standard
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ | NatSpecMultiLine | tokenOfOwnerByIndex | function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
| /**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
2089,
2305
]
} | 57,340 |
|
RoyalStables | ..\openzeppelin-solidity\contracts\token\ERC721\ERC721Token.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | ERC721Token | contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
/**
* @dev Constructor function
*/
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return name_;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return symbol_;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
/**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
/**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
} | /**
* @title Full ERC721 Token
* This implementation includes all the required and some optional functionality of the ERC721 standard
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view returns (uint256) {
return allTokens.length;
}
| /**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
2450,
2542
]
} | 57,341 |
|
RoyalStables | ..\openzeppelin-solidity\contracts\token\ERC721\ERC721Token.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | ERC721Token | contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
/**
* @dev Constructor function
*/
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return name_;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return symbol_;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
/**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
/**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
} | /**
* @title Full ERC721 Token
* This implementation includes all the required and some optional functionality of the ERC721 standard
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ | NatSpecMultiLine | tokenByIndex | function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
| /**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
2871,
3017
]
} | 57,342 |
|
RoyalStables | ..\openzeppelin-solidity\contracts\token\ERC721\ERC721Token.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | ERC721Token | contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
/**
* @dev Constructor function
*/
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return name_;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return symbol_;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
/**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
/**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
} | /**
* @title Full ERC721 Token
* This implementation includes all the required and some optional functionality of the ERC721 standard
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ | NatSpecMultiLine | _setTokenURI | function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
| /**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
3247,
3384
]
} | 57,343 |
|
RoyalStables | ..\openzeppelin-solidity\contracts\token\ERC721\ERC721Token.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | ERC721Token | contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
/**
* @dev Constructor function
*/
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return name_;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return symbol_;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
/**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
/**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
} | /**
* @title Full ERC721 Token
* This implementation includes all the required and some optional functionality of the ERC721 standard
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ | NatSpecMultiLine | addTokenTo | function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
| /**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
3651,
3885
]
} | 57,344 |
|
RoyalStables | ..\openzeppelin-solidity\contracts\token\ERC721\ERC721Token.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | ERC721Token | contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
/**
* @dev Constructor function
*/
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return name_;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return symbol_;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
/**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
/**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
} | /**
* @title Full ERC721 Token
* This implementation includes all the required and some optional functionality of the ERC721 standard
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ | NatSpecMultiLine | removeTokenFrom | function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
| /**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
4168,
5212
]
} | 57,345 |
|
RoyalStables | ..\openzeppelin-solidity\contracts\token\ERC721\ERC721Token.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | ERC721Token | contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
/**
* @dev Constructor function
*/
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return name_;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return symbol_;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
/**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
/**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
} | /**
* @title Full ERC721 Token
* This implementation includes all the required and some optional functionality of the ERC721 standard
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ | NatSpecMultiLine | _mint | function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
| /**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
5478,
5658
]
} | 57,346 |
|
RoyalStables | ..\openzeppelin-solidity\contracts\token\ERC721\ERC721Token.sol | 0xdbbe7e0db7c8819925843f73a03c94b495fbaa9a | Solidity | ERC721Token | contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 {
// Token name
string internal name_;
// Token symbol
string internal symbol_;
// Mapping from owner to list of owned token IDs
mapping(address => uint256[]) internal ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) internal ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] internal allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) internal allTokensIndex;
// Optional mapping for token URIs
mapping(uint256 => string) internal tokenURIs;
/**
* @dev Constructor function
*/
constructor(string _name, string _symbol) public {
name_ = _name;
symbol_ = _symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Enumerable);
_registerInterface(InterfaceId_ERC721Metadata);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return name_;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return symbol_;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId) public view returns (string) {
require(_exists(_tokenId));
return tokenURIs[_tokenId];
}
/**
* @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address
*/
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
public
view
returns (uint256)
{
require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index];
}
/**
* @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens
*/
function totalSupply() public view returns (uint256) {
return allTokens.length;
}
/**
* @dev Gets the token ID at a given index of all the tokens in this contract
* Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list
*/
function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply());
return allTokens[_index];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign
*/
function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(_exists(_tokenId));
tokenURIs[_tokenId] = _uri;
}
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length;
}
/**
* @dev Internal function to remove a token ID from the list of a given address
* @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot.
uint256 tokenIndex = ownedTokensIndex[_tokenId];
uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
uint256 lastToken = ownedTokens[_from][lastTokenIndex];
ownedTokens[_from][tokenIndex] = lastToken;
// This also deletes the contents at the last position of the array
ownedTokens[_from].length--;
// Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
// be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
// the lastToken to the first position, and then dropping the element placed in the last position of the list
ownedTokensIndex[_tokenId] = 0;
ownedTokensIndex[lastToken] = tokenIndex;
}
/**
* @dev Internal function to mint a new token
* Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/
function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId);
allTokensIndex[_tokenId] = allTokens.length;
allTokens.push(_tokenId);
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
} | /**
* @title Full ERC721 Token
* This implementation includes all the required and some optional functionality of the ERC721 standard
* Moreover, it includes approve all functionality using operator terminology
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
*/ | NatSpecMultiLine | _burn | function _burn(address _owner, uint256 _tokenId) internal {
super._burn(_owner, _tokenId);
// Clear metadata (if any)
if (bytes(tokenURIs[_tokenId]).length != 0) {
delete tokenURIs[_tokenId];
}
// Reorg all tokens array
uint256 tokenIndex = allTokensIndex[_tokenId];
uint256 lastTokenIndex = allTokens.length.sub(1);
uint256 lastToken = allTokens[lastTokenIndex];
allTokens[tokenIndex] = lastToken;
allTokens[lastTokenIndex] = 0;
allTokens.length--;
allTokensIndex[_tokenId] = 0;
allTokensIndex[lastToken] = tokenIndex;
}
| /**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param _owner owner of the token to burn
* @param _tokenId uint256 ID of the token being burned by the msg.sender
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4bd5cfc1aad880638638e63394331ab9d58f3b260547b462ac1d058cc52819f2 | {
"func_code_index": [
5895,
6502
]
} | 57,347 |
|
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() external view returns (uint256);
| /**
* @dev Returns the amount of tokens in existence.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
94,
154
]
} | 57,348 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address account) external view returns (uint256);
| /**
* @dev Returns the amount of tokens owned by `account`.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
237,
310
]
} | 57,349 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | transfer | function transfer(address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
534,
616
]
} | 57,350 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | 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.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
895,
983
]
} | 57,351 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | 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.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
1647,
1726
]
} | 57,352 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | 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.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
2039,
2141
]
} | 57,353 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | 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;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | 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.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
259,
445
]
} | 57,354 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | 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;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | 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.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
723,
864
]
} | 57,355 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | 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;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | 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.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
1162,
1359
]
} | 57,356 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | 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;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | 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.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
1613,
2089
]
} | 57,357 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | 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;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | 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.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
2560,
2697
]
} | 57,358 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | 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;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | 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.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
3188,
3471
]
} | 57,359 |
Lender | Lender.sol | 0x55dbe7df69e9385b9be0f4bdcc9f1505cd139791 | 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;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | 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.6.12+commit.27d51765 | MIT | ipfs://cc07295a027ff4b350dad10d12d3f3ca9eb724ea5b3c2240dc1f8ee2bec1603b | {
"func_code_index": [
3931,
4066
]
} | 57,360 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.